package testUnitaire.database.crud.alltest;

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

import java.sql.SQLException;

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

import testUnitaire.database.crud.testCrud;
import database.crud.EmployeCrud;
import database.dataset.Employe;

public class testCrudEmploye extends testCrud<Employe> {

	@Override
	@Before
	public void init() throws SQLException {
		setCrud(new EmployeCrud(getConnection()));
		setDataset(new Employe(magicID, "Robert", "Chiasson", "vraiment payant", magicID));
		setDataset2(new Employe(magicID+1, "Robert", "Chiasson", "vraiment payant", magicID));
	}

	@Test(expected = SQLException.class)  
	public void insertionDuneFKstatusNonValide() throws SQLException {  
		getCrud().create(new Employe(magicID-1, "Robert", "Chiasson", "vraiment payant", magicID+1));
	}

	@Test
	public void testDeReadByFkutilisateur() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Employe a :((EmployeCrud)getCrud()).readByFk_utilisateur(magicID))
			ok |= a.equals(getDataset());
		assertTrue("By Fkutilisateur not work",ok);
	}

	@Test
	public void testDeReadAllLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Employe a : ((EmployeCrud)getCrud()).readAllLike("ROBERT", "", ""))
			ok |= a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllLike2() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Employe a : ((EmployeCrud)getCrud()).readAllLike("", "CHIASSON", ""))
			ok |= a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllLike4() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Employe a : ((EmployeCrud)getCrud()).readAllLike("", "", ""))
			ok |= a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Employe a : ((EmployeCrud)getCrud()).readAllLike("MIKE", "", ""))
			ok |= a.equals(getDataset());
		assertFalse("should fail",ok);
	}
}
