package com.ibtp.kontor.library.dal;

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

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

import java.util.List;

/**
 * Created by thomas on 23.01.15.
 */
public class AuthorImplTest {

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

    @Test
    public void testAddAuthor() {
        String authorName = "testAddAuthor";
        AuthorImpl authorImpl = new AuthorImpl();
        AuthorEntity author = authorImpl.addAuthor(authorName);
        assertNotNull(author);
    }

    @Test
    public void testDeleteAuthor() {
        String authorName = "testDeleteAuthor";
        AuthorImpl authorImpl = new AuthorImpl();
        AuthorEntity author = authorImpl.addAuthor(authorName);
        assertNotNull(author);
        List<AuthorEntity> authorList = authorImpl.findByName(authorName);
        assertEquals(1, authorList.size());
        authorImpl.delete(author);
        authorList = authorImpl.findByName(authorName);
        assertEquals(0, authorList.size());
    }

    @Test
    public void testAuthorAddAndDelete() {

    }

    @Test
    public void testAuthorFindAll() {

    }
}
