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.GroupeCrud;
import database.dataset.Groupe;

public class testCrudGroupe extends testCrud<Groupe> {

	@Override
	@Before
	public void init() throws SQLException {
		setCrud(new GroupeCrud(getConnection()));
		setDataset(new Groupe(magicID, magicID, "banana split"));
		setDataset2(new Groupe(magicID+1, magicID, "banana split"));
	}
	
	@Test(expected = SQLException.class)  
	public void insertionDuneFKclientNonValide() throws SQLException {  
		getCrud().create(new Groupe(magicID-1, magicID+1, "banana split"));
	}

	@Test
	public void testDeReadByFkclient() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Groupe a :((GroupeCrud)getCrud()).readByFk_client(magicID))
			ok |= a.equals(getDataset());
		assertTrue("By Fkutilisateur not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Groupe a : ((GroupeCrud)getCrud()).readAllLike("","", ""))
			ok |= a.equals(getDataset());
		assertFalse("should fail",ok);
	}

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

	@Test
	public void testDeReadAllLike2() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Groupe a : ((GroupeCrud)getCrud()).readAllLike("", "", "banana"))
			ok |= a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
}
