package com.ibtp.kontor.tradingcards.dal;

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

import java.util.Collection;

/**
 * Created by tpeetz on 27.01.2015.
 */
public class PositionImplTest {

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

    @Test
    public void testPositionAddAndDelete() {
        String positionName = "testPositionAddAndDelete";
        PositionImpl positionImpl = new PositionImpl();
	    PositionEntity position = positionImpl.addPosition(positionName);
        Collection<PositionEntity> resultList = positionImpl.findByName(positionName);
        Assert.assertNotNull(resultList);
        Assert.assertEquals(1, resultList.size());
        positionImpl.delete(position);
        resultList = positionImpl.findByName(positionName);
        Assert.assertEquals(0, resultList.size());
    }

    @Test
    public void testPositionFindAll() {
        PositionImpl positionImpl = new PositionImpl();
        Collection<PositionEntity> resultList = positionImpl.findAll();
        Assert.assertEquals(0, resultList.size());
    }
}

