package com.ibtp.kontor.comics;

import com.ibtp.kontor.comics.dal.PublisherImpl;
import com.ibtp.kontor.comics.entity.PublisherEntity;
import com.ibtp.kontor.dal.DatabaseManager;
import com.ibtp.kontor.util.LocalTestDatabase;
import org.junit.*;

import java.util.Collection;
import java.util.Iterator;

/**
 * Created by TPEETZ on 27.01.2015.
 */
public class CollectionTest {

    @Before
    public void setUp() {
        DatabaseManager.setDatabase(new LocalTestDatabase());
    }

    @After
    public void cleanup() {
        PublisherImpl publisherImpl = new PublisherImpl();
        Collection<PublisherEntity> publisherEntities = publisherImpl.findAll();
        for (Iterator<PublisherEntity> iterator = publisherEntities.iterator(); iterator.hasNext(); ) {
            PublisherEntity next =  iterator.next();
            publisherImpl.delete(next);
        }
    }

    @Test
    public void testAddPublishers() {
        String publisherName = "Bongo Comics";
        PublisherImpl publisherImpl = new PublisherImpl();
        publisherImpl.addPublisher("Bongo Comics");
        publisherImpl.addPublisher("Marvel");
        Collection<PublisherEntity> publisherList = publisherImpl.findAll();
        Assert.assertEquals(2, publisherList.size());
    }
}
