package com.ibtp.kontor.library.dal;

import com.ibtp.kontor.dal.DatabaseManager;
import com.ibtp.kontor.util.LocalTestDatabase;
import com.ibtp.kontor.library.entity.AuthorEntity;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

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

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

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

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

    @Test
    public void testAuthorAddAndDelete() {

    }

    @Test
    public void testAuthorFindAll() {

    }
}
