package com.ibtp.kontor.library.dal;

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 com.ibtp.kontor.library.entity.ArticleEntity;

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

import java.util.Collection;
import java.util.List;

/**
 * Created by tpeetz on 23.01.2015.
 */
public class ArticleImplTest {

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

    @AfterAll
    public static void cleanUp() {
        ArticleImpl articleImpl = new ArticleImpl();
        Collection<ArticleEntity> articleList = articleImpl.findAll();
        for (ArticleEntity articleEntity : articleList) {
            articleImpl.delete(articleEntity);
        }
    }

    @Test
    public void testAddArticle() {
        String articleTitle = "testAddArticle";
        ArticleImpl articleImpl = new ArticleImpl();
        ArticleEntity article = articleImpl.addArticle(articleTitle);
        assertNotNull(article);
        List<ArticleEntity> articleList = articleImpl.findByTitle(articleTitle);
        assertEquals(1, articleList.size());
    }

    @Test
    public void testArticleAddAndDelete() {

    }

    @Test
    public void testArticleFindAll() {

    }
}
