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.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Collection;

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

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

    @AfterAll
    public static void cleanup() {
        PublisherImpl publisherImpl = new PublisherImpl();
        Collection<PublisherEntity> publisherEntities = publisherImpl.findAll();
        for (PublisherEntity publisherEntity : publisherEntities) {
            publisherImpl.delete(publisherEntity);
        }
    }

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