package com.ibtp.kontor.comics.dal;

import com.ibtp.kontor.comics.entity.StoryArcEntity;
import com.ibtp.kontor.dal.DatabaseManager;
import com.ibtp.kontor.util.LocalTestDatabase;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

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

import java.util.Collection;

/**
 * Created by TPEETZ on 28.01.2015.
 */
public class StoryArcImplTest {

    @BeforeAll
    public static void setUp() {
        DatabaseManager.setDatabase(new LocalTestDatabase());
        StoryArcImpl storyArcImpl = new StoryArcImpl();
        Collection<StoryArcEntity> storyArcEntityCollection = storyArcImpl.findAll();
        for (StoryArcEntity storyArcEntity : storyArcEntityCollection) {
            storyArcImpl.delete(storyArcEntity);
        }
    }

    @Test
    public void testStoryArcAddAndDelete() {
        String storyArcTtitle = "testStoryArcAddAndDelete";
        StoryArcImpl storyArcImpl = new StoryArcImpl();
        StoryArcEntity storyArc = new StoryArcEntity();
        storyArc.setTitle(storyArcTtitle);
        storyArcImpl.store(storyArc);
        Collection<StoryArcEntity> storyArcEntityCollection = storyArcImpl.findByTitle(storyArcTtitle);
        assertNotNull(storyArcEntityCollection);
        assertEquals(1, storyArcEntityCollection.size());
        storyArcImpl.delete(storyArc);
        storyArcEntityCollection = storyArcImpl.findByTitle(storyArcTtitle);
        assertNotNull(storyArcEntityCollection);
        assertEquals(0, storyArcEntityCollection.size());
    }

    @Test
    public void testStoryArcFindAll() {
        StoryArcImpl storyArcImpl = new StoryArcImpl();
        StoryArcEntity storyArc;
        storyArc = new StoryArcEntity();
        storyArc.setTitle("testStoryArcFindAll1");
        storyArcImpl.store(storyArc);
        storyArc = new StoryArcEntity();
        storyArc.setTitle("testStoryArcFindAll2");
        storyArcImpl.store(storyArc);
        storyArc = new StoryArcEntity();
        storyArc.setTitle("testStoryArcFindAll3");
        storyArcImpl.store(storyArc);
        Collection<StoryArcEntity> storyArcEntityCollection = storyArcImpl.findAll();
        assertNotNull(storyArcEntityCollection);
        assertEquals(3, storyArcEntityCollection.size());
    }
}
