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.ArticleCrud;
import database.dataset.Article;

public class testCrudArticle extends testCrud<Article> {

	@Override
	@Before
	public void init() throws SQLException {
		setCrud(new ArticleCrud(getConnection()));
		setDataset(new Article(magicID,"EDFR4","un article", false, magicID, true));
		setDataset2(new Article(magicID+1,"EDFR4","un article", false, magicID, true));
	}

	@Test(expected = SQLException.class)  
	public void insertionDuneFKcategorieNonValide() throws SQLException {  
		getCrud().create(new Article(magicID-1,"EDFR4","un article", false, magicID+1, true));
	}
	
	@Test
	public void testDeReadByFkCategorie() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Article a :((ArticleCrud)getCrud()).readByFk_categorie(magicID))
			ok |= a.equals(getDataset());
		assertTrue("ByFkCategorie not work",ok);
	}
	
	@Test
	public void testDeReadAllLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Article a : ((ArticleCrud)getCrud()).readAllLike("EDFR4", "art", "", "", ""))
			ok |= a.equals(getDataset());
		assertTrue("read all like not work",ok);
	}
	
	@Test
	public void testDeReadAllNotLike() throws SQLException{
		getCrud().update(getDataset());
		boolean ok=false;
		for (Article a : ((ArticleCrud)getCrud()).readAllLike("BBBB", "", "", "", ""))
			ok |= a.equals(getDataset());
		assertFalse("read all not like not work",ok);
	}
}
