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.ChambreCrud;
import database.dataset.Chambre;

public class testCrudChambre extends testCrud<Chambre> {

	@Override
	@Before
	public void init() throws SQLException {
		setCrud(new ChambreCrud(getConnection()));
		setDataset(new Chambre(magicID, 2, false, 1, "suite populaire", 237));
		setDataset2(new Chambre(magicID+1, 2, false, 1, "suite populaire", 237));
	}
	
	@Test
	public void testDeReadByNumero() throws SQLException{
		getCrud().update(getDataset());
		assertTrue("ByNumero not work",((ChambreCrud)getCrud()).readByNumero(237).equals(getDataset()));
	}
	
	@Test
	public void testDeReadAllLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Chambre a : ((ChambreCrud)getCrud()).readAllLike("2", "", "", "", ""))
			ok = a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllLike2() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Chambre a : ((ChambreCrud)getCrud()).readAllLike("", "F", "", "", ""))
			ok = a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllLike3() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Chambre a : ((ChambreCrud)getCrud()).readAllLike("", "", "1", "", ""))
			ok = a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllLike4() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Chambre a : ((ChambreCrud)getCrud()).readAllLike("", "", "", "2012-05-02", "2012-05-04"))
			ok = a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Chambre a : ((ChambreCrud)getCrud()).readAllLike("", "", "", "2012-05-06", "2012-05-08"))
			ok = a.equals(getDataset());
		assertFalse("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike2() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Chambre a : ((ChambreCrud)getCrud()).readAllLike("", "", "", "2012-05-05", "2012-05-07"))
			ok = a.equals(getDataset());
		assertFalse("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike3() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Chambre a : ((ChambreCrud)getCrud()).readAllLike("", "", "", "2012-05-04", "2012-05-08"))
			ok = a.equals(getDataset());
		assertFalse("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike4() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Chambre a : ((ChambreCrud)getCrud()).readAllLike("", "", "", "2012-05-04", "2012-05-06"))
		{
			System.out.println(a.getChambre_numero());
			ok = a.equals(getDataset());
		}
		assertFalse("read all like not work",ok);
	}
}
