<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package testUnitaire.database.crud;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

import testUnitaire.database.crud.alltest.testCrudAdresse;
import testUnitaire.database.crud.alltest.testCrudArticle;
import testUnitaire.database.crud.alltest.testCrudCategorieArticle;
import testUnitaire.database.crud.alltest.testCrudChambre;
import testUnitaire.database.crud.alltest.testCrudClient;
import testUnitaire.database.crud.alltest.testCrudConstante;
import testUnitaire.database.crud.alltest.testCrudDepot;
import testUnitaire.database.crud.alltest.testCrudEmploye;
import testUnitaire.database.crud.alltest.testCrudEncaissement;
import testUnitaire.database.crud.alltest.testCrudFacture;
import testUnitaire.database.crud.alltest.testCrudGroupe;
import testUnitaire.database.crud.alltest.testCrudGroupe_utilisateur;
import testUnitaire.database.crud.alltest.testCrudLocation_Chambre;
import testUnitaire.database.crud.alltest.testCrudModeDePaiement;
import testUnitaire.database.crud.alltest.testCrudReservation;
import testUnitaire.database.crud.alltest.testCrudReservationGeneral;
import testUnitaire.database.crud.alltest.testCrudReservationGroupe;
import testUnitaire.database.crud.alltest.testCrudReservationIndividu;
import testUnitaire.database.crud.alltest.testCrudStatus;
import testUnitaire.database.crud.alltest.testCrudTaxe;
import testUnitaire.database.crud.alltest.testCrudTelephone;
import testUnitaire.database.crud.alltest.testCrudTelephoneType;
import testUnitaire.database.crud.alltest.testCrudUtilisateur;
import testUnitaire.database.crud.alltest.testCrudVente;
import testUnitaire.database.crud.alltest.testCrudVenteGeneral;
import testUnitaire.database.crud.alltest.testCrudVente_Article;
import testUnitaire.database.crud.alltest.testCrudVille;
import database.Crud;
import database.tools.DbConnection;

public abstract class testCrud&lt;DATASET&gt; {
	public static final int magicID = 1000000;
	public static String[] allInit = new String[]{
		"INSERT INTO `taxe` (`taxe_p_id`, `taxe_tps`, `taxe_tvq`, `taxe_hebergement`, `taxe_changement`) VALUES(1000000, NULL, NULL, NULL, '1900-01-01');",
		"INSERT INTO `chambre` (`chambre_p_id`, `chambre_nombredelits`, `chambre_devantlhotel`, `chambre_nombreEtage`, `chambre_numero`, `chambre_description`) VALUES(1000000, NULL, '', NULL, NULL, NULL);",
		"INSERT INTO `categorie_article` (`categorie_article_p_id`, `categorie_article_description`) VALUES(1000000, NULL);",
		"INSERT INTO `article` (`article_p_id`, `article_code`, `article_description`, `article_taxable`, `article_actif`, `categorie_fk_id`) VALUES(1000000, 'EDFR4', 'art', 'V', 'V', 1000000);",
		"INSERT INTO `ville` (`ville_p_id`, `ville_nom`, `ville_province`, `ville_pays`) VALUES(1000000, 'simcity', NULL, NULL);",
		"INSERT INTO `adresse` (`adresse_p_id`, `adresse_no_rue_app`, `adresse_codepostal`, `ville_fk_id`) VALUES(1000000, NULL, NULL, 1000000);",
		"INSERT INTO `client` (`client_p_id`, `client_nom`, `client_prenom`, `adresse_fk_id`, `client_commentaire`) VALUES(1000000, NULL, NULL, 1000000, NULL);",
		"INSERT INTO `groupe` (`groupe_p_id`, `groupe_nom`, `client_fk_id`) VALUES(1000000, NULL, 1000000);",
		"INSERT INTO `groupe_utilisateur` (`groupe_utilisateur_p_id`, `groupe_utilisateur_nom`) VALUES(1000000, NULL);",
		"INSERT INTO `utilisateur` (`utilisateur_p_id`, `utilisateur_nom`, `utilisateur_motdepasse`, `utilisateur_actif`, `groupe_utilisateur_fk_id`) VALUES(1000000, NULL, NULL, '', 1000000);",
		"INSERT INTO `employe` (`employe_p_id`, `employe_prenom`, `employe_nom`, `utilisateur_fk_id`, `employe_commentaire`) VALUES(1000000, NULL, NULL, 1000000, NULL);",
		"INSERT INTO `depot` (`depot_p_id`, `depot_date`, `depot_montant`, `employe_fk_id`) VALUES(1000000, NULL, NULL, 1000000);",
		"INSERT INTO `fermeture` (`fermeture_p_id`, `fermeture_jour`, `employe_fk_id`, `depot_fk_id`, `fermeture_commentaire`) VALUES(1000000, NULL, 1000000, 1000000, NULL);",		
		"INSERT INTO `facture` (`facture_p_id`, `facture_jour`, `facture_heure`, `facture_depense`, `facture_commentaire`, `client_fk_id`, `fermeture_fk_id`, `taxe_fk_id`) VALUES(1000000, NULL, NULL, NULL, NULL, 1000000, 1000000, 1000000);",
		"INSERT INTO `vente` (`vente_p_id`, `vente_jour`, `vente_heure`, `vente_prix`, `facture_fk_id`, `article_fk_id`) VALUES(1000000, NULL, NULL, NULL, 1000000, 1000000);",
		"INSERT INTO `vente_article` (`vente_article_p_fk_id`, `vente_article_quantite`) VALUES(1000000, NULL);",
		"INSERT INTO `telephone_type` (`telephone_type_p_id`, `telephone_type_nom`) VALUES(1000000, NULL);",
		"INSERT INTO `telephone` (`telephone_p_id`, `telephone_numero`, `telephone_type_fk_id`, `client_fk_id`) VALUES(1000000, NULL, 1000000, 1000000);",
		"INSERT INTO `status_chambre` (`status_chambre_p_id`, `status_chambre_description`) VALUES(1000000, NULL);",
		"INSERT INTO `reservation` (`reservation_p_id`, `reservation_debut`, `reservation_fin`, `status_fk_id`, `chambre_fk_id`, `reservation_commentaire`) VALUES(1000000, '2012-05-05', '2012-05-07', 1000000, 1000000, NULL);",
		"INSERT INTO `reservation_individu` (`reservation_individu_p_fk_id`, `client_fk_id`) VALUES(1000000, 1000000);",
		"INSERT INTO `reservation_groupe` (`reservation_groupe_p_fk_id`, `groupe_fk_id`) VALUES(1000000, 1000000);",
		"INSERT INTO `modedepaiement` (`modedepaiement_p_id`, `modedepaiement_nom`) VALUES(1000000, NULL);",
		"INSERT INTO `location_chambre` (`location_chambre_p_fk_id`, `reservation_fk_id`) VALUES(1000000, 1000000);",
		"INSERT INTO `encaissement` (`encaissement_p_id`, `encaissement_montant`, `facture_fk_id`, `modedepaiement_fk_id`) VALUES(1000000, NULL, 1000000, 1000000);",
		"INSERT INTO `constante` (`constante_p_id`, `constante_noTps`, `constante_noTvq`, `constante_neq`, `constante_messagefacture`) VALUES(1000000, NULL, NULL, NULL, NULL);"
	};
	public static String[] allOutit = new String[]{
		"DELETE FROM `location_chambre` WHERE `location_chambre_p_fk_id`=1000000",
		"DELETE FROM `vente_article` WHERE `vente_article_p_fk_id`=1000000",
		"DELETE FROM `vente` WHERE `vente_p_id`=1000000",
		"DELETE FROM `encaissement` WHERE `encaissement_p_id`=1000000",
		"DELETE FROM `facture` WHERE `facture_p_id`=1000000",
		"DELETE FROM `fermeture` WHERE `fermeture_p_id`=1000000",
		"DELETE FROM `depot` WHERE `depot_p_id`=1000000",
		"DELETE FROM `reservation_individu` WHERE `reservation_individu_p_fk_id`=1000000",
		"DELETE FROM `reservation_groupe` WHERE `reservation_groupe_p_fk_id`=1000000",
		"DELETE FROM `reservation` WHERE `reservation_p_id`=1000000",
		"DELETE FROM `telephone` WHERE `telephone_p_id`=1000000",
		"DELETE FROM `telephone_type` WHERE `telephone_type_p_id`=1000000",
		"DELETE FROM `groupe` WHERE `groupe_p_id`=1000000",
		"DELETE FROM `client` WHERE `client_p_id`=1000000",
		"DELETE FROM `adresse` WHERE `adresse_p_id`=1000000",
		"DELETE FROM `ville` WHERE `ville_p_id`=1000000",
		"DELETE FROM `article` WHERE `article_p_id`=1000000",
		"DELETE FROM `categorie_article` WHERE `categorie_article_p_id`=1000000",
		"DELETE FROM `employe` WHERE `employe_p_id`=1000000",
		"DELETE FROM `utilisateur` WHERE `utilisateur_p_id`=1000000",
		"DELETE FROM `groupe_utilisateur` WHERE `groupe_utilisateur_p_id`=1000000",
		"DELETE FROM `taxe` WHERE `taxe_p_id`=1000000",
		"DELETE FROM `status_chambre` WHERE `status_chambre_p_id`=1000000",
		"DELETE FROM `modedepaiement` WHERE `modedepaiement_p_id`=1000000",
		"DELETE FROM `constante` WHERE `constante_p_id`=1000000",
		"DELETE FROM `chambre` WHERE `chambre_p_id`=1000000"
	};

	private static Connection connection;
	
	private DATASET dataset;
	private DATASET dataset2;
	private Crud&lt;DATASET&gt; crud;
	
	public static Connection getConnection() {
		return connection;
	}

	@BeforeClass
	public static void connect() throws FileNotFoundException, IOException, SQLException, ClassNotFoundException{
		connection = DbConnection.createConnection();
		
		Statement stm = connection.createStatement();
		for (String query : allInit){
			//System.out.println(query);
			stm.execute(query);
		}
	}
	
	@AfterClass
	public static void disconnect() throws SQLException{
		Statement stm = connection.createStatement();
		for (String query : allOutit){
			//System.out.println(query);
			stm.execute(query);
		}
		connection.close();
	}
	
	@Test
	public void testReadAll() throws SQLException {
		System.out.println("read all");
		for (DATASET d : getCrud().readAll()){
			//System.out.println(d.toString());
		}
	}
	
	@Test
	public void testReadById() throws SQLException {
		System.out.println("read by id " + getCrud().readById(magicID));
	}
	
	@Test
	public void testUpdate() throws SQLException{
		getCrud().update(getDataset());
	}
	
	@Test
	public void testCreateThenDelete() throws SQLException{
		System.out.println("create " + getDataset2().toString());
		getCrud().create(getDataset2());
		System.out.println("delete " + getDataset2().toString());
		getCrud().destroy(getDataset2());
	}

	@Test(expected = SQLException.class)  
	public void insertionDunePrimaryKeyDejaExistante() throws SQLException {  
		getCrud().create(getDataset());
	}
	
	public DATASET getDataset() {
		return dataset;
	}
	
	public DATASET getDataset2() {
		return dataset2;
	}

	public Crud&lt;DATASET&gt; getCrud() {
		return crud;
	}

	public void setDataset(DATASET dataset) {
		this.dataset = dataset;
	}
	
	public void setDataset2(DATASET dataset2) {
		this.dataset2 = dataset2;
	}

	public void setCrud(Crud&lt;DATASET&gt; crud) {
		this.crud = crud;
	}
	
	@Before
	public abstract void init() throws SQLException;
	
	
	public static void main(String...strings){
		JUnitCore junit = new JUnitCore();
		
		Result result = junit.runClasses(testCrudAdresse.class,
										 testCrudArticle.class,
										 testCrudCategorieArticle.class,
										 testCrudChambre.class,
										 testCrudClient.class,
										 testCrudConstante.class,
										 testCrudDepot.class,
										 testCrudEmploye.class,
										 testCrudEncaissement.class,
										 testCrudFacture.class,
										 testCrudGroupe.class,
										 testCrudGroupe_utilisateur.class,
										 testCrudLocation_Chambre.class,
										 testCrudModeDePaiement.class,
										 testCrudReservation.class,
										 testCrudReservationGeneral.class,
										 testCrudReservationGroupe.class,
										 testCrudReservationIndividu.class,
										 testCrudStatus.class,
										 testCrudTaxe.class,
										 testCrudTelephone.class,
										 testCrudTelephoneType.class,
										 testCrudUtilisateur.class,
										 testCrudVente.class,
										 testCrudVenteGeneral.class,
										 testCrudVente_Article.class,
										 testCrudVille.class
										 );
		List&lt;Failure&gt; fails = result.getFailures();
		if (fails.size()!=0){
			System.out.println("list of failure");
			for (Failure failure : fails){
				System.out.println(failure.getMessage());
				System.out.println(failure.getTestHeader());
				System.out.println("_______________________");
				//System.out.println(failure.getTrace());
			}
		}
		else{
			System.out.println("success, YOURE AWESOME !!!!");
		}
		System.out.println(result.getRunCount() + " tests dones");
		System.out.println(result.getFailureCount() + " failures");
	}
}
</pre></body></html>