package testUnitaire.database.crud.alltest;

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

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

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

import testUnitaire.database.crud.testCrud;
import database.crud.EncaissementCrud;
import database.dataset.Encaissement;

public class testCrudEncaissement extends testCrud<Encaissement> {

	@Override
	@Before
	public void init() throws SQLException {
		setCrud(new EncaissementCrud(getConnection()));
		setDataset(new Encaissement(magicID, magicID, magicID, new BigDecimal("12345515.02")));
		setDataset2(new Encaissement(magicID+1, magicID, magicID, new BigDecimal("12345515.02")));
	}

	@Test(expected = SQLException.class)  
	public void insertionDuneFKfactureNonValide() throws SQLException {  
		getCrud().create(new Encaissement(magicID-1, magicID+1, magicID, new BigDecimal("12345515.02")));
	}
	
	@Test(expected = SQLException.class)  
	public void insertionDuneFKmodedepaiementNonValide() throws SQLException {  
		getCrud().create(new Encaissement(magicID-1, magicID, magicID+1, new BigDecimal("12345515.02")));
	}
	

	@Test
	public void testDeReadByFkfacture() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Encaissement a :((EncaissementCrud)getCrud()).readByFk_facture(magicID))
			ok |= a.equals(getDataset());
		assertTrue("By Fkfacturee not work",ok);
	}
	
	@Test
	public void testDeReadByFkmodedepaiement() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Encaissement a :((EncaissementCrud)getCrud()).readByFk_modedepaiement(magicID))
			ok |= a.equals(getDataset());
		assertTrue("By Fkfacturee not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Encaissement a : ((EncaissementCrud)getCrud()).readAllLike("", "", "", ""))
			ok |= a.equals(getDataset());
		assertFalse("should fail",ok);
	}

}
