package testUnitaire.database.crud.alltest;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.SQLException;

import org.junit.Before;
import org.junit.Test;

import testUnitaire.database.crud.testCrud;
import database.crud.DepotCrud;
import database.dataset.Depot;

public class testCrudDepot extends testCrud<Depot> {

	@Override
	@Before
	public void init() throws SQLException {
		setCrud(new DepotCrud(getConnection()));
		setDataset(new Depot(magicID, Date.valueOf("2013-02-02"), magicID, new BigDecimal("1000.51")));
		setDataset2(new Depot(magicID+1, Date.valueOf("2013-02-02"), magicID, new BigDecimal("1000.51")));
	}

	@Test(expected = SQLException.class)  
	public void insertionDuneFKemployeNonValide() throws SQLException {  
		getCrud().create(new Depot(magicID-1, Date.valueOf("2013-02-02"), magicID+1, new BigDecimal("1000.51")));
	}
	
	@Test
	public void testDeReadByFkemploye() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Depot a :((DepotCrud)getCrud()).readByFk_employe(magicID))
			ok |= a.equals(getDataset());
		assertTrue("By Fkemploye not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Depot a : ((DepotCrud)getCrud()).readAllLike("2014", "",""))
			ok |= a.equals(getDataset());
		assertFalse("should fail",ok);
	}

	@Test
	public void testDeReadAllLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Depot a : ((DepotCrud)getCrud()).readAllLike("2013-02", "",""))
			ok |= a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
}
