diff --git a/GTDServer/JBoss/src/main/java/fr/alma/gtd/reactor/MyCallBack.java b/GTDServer/JBoss/src/main/java/fr/alma/gtd/reactor/MyCallBack.java new file mode 100644 index 0000000000000000000000000000000000000000..642025ee30e3a9b55b6b48d8d9df8bb866ecc05e --- /dev/null +++ b/GTDServer/JBoss/src/main/java/fr/alma/gtd/reactor/MyCallBack.java @@ -0,0 +1,35 @@ +package fr.alma.gtd.reactor; + +import fr.alma.gtd.interfacedistante.CallBack; + +import java.rmi.RemoteException; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class MyCallBack<T> implements CallBack<T> { + + protected final Lock lock = new ReentrantLock(); + protected boolean test; + protected T t; + + @Override + public void onSucces(T result) throws RemoteException { + System.out.println("Resultat du serveur : " + result); + test = true; + this.t = result; + lock.unlock(); + } + + @Override + public void onFailure(Exception e) throws RemoteException { + System.out.println("Exception : " + e.getMessage()); + test= false; + lock.unlock(); + } + public boolean hasResult() { + lock.lock(); + return true; + } + + public T get(){ return t; } +} diff --git a/GTDServer/JBoss/src/main/java/fr/alma/gtd/reactor/TestReactorRMI.java b/GTDServer/JBoss/src/main/java/fr/alma/gtd/reactor/TestReactorRMI.java new file mode 100644 index 0000000000000000000000000000000000000000..7403ec1985366b9764e21423bddaa41d668fb623 --- /dev/null +++ b/GTDServer/JBoss/src/main/java/fr/alma/gtd/reactor/TestReactorRMI.java @@ -0,0 +1,152 @@ +package fr.alma.gtd.reactor; + +import fr.alma.gtd.donneespartagees.*; +import fr.alma.gtd.donneesserveur.Contexte; +import fr.alma.gtd.donneesserveur.Projet; +import fr.alma.gtd.isessions.IContexteServiceRemote; +import org.hibernate.ConnectionReleaseMode; +import org.hibernate.validator.AssertTrue; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import javax.naming.NamingException; +import java.lang.reflect.Field; +import java.rmi.RemoteException; +import java.util.Map; + + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + + +public final class TestReactorRMI { + + private ReactorRMI reacRMI; + + + private String authentif; + private Contexte contexte; + + private MyCallBack<String> callBack ; + private MyCallBack<IContexte> cbContexte; + private MyCallBack<ITag> cbTag ; + private MyCallBack<ITache> cbTache; + private MyCallBack<IProjet> cbProjet; + private MyCallBack<IIdee> cbIdee; + + @Before + public void setup(){ + callBack = new MyCallBack<String>(); + cbContexte = new MyCallBack<IContexte>(); + } + + public TestReactorRMI() {super();} + + + @Test + public void testCreerCompte(){ + + try { + + this.reacRMI.creerCompte("test","test","pseudo",callBack); + callBack.hasResult(); + assertTrue("La création du compte a reussi",callBack.test == true); + assertFalse("La création du compte a échoué",callBack.test == false); + } catch (RemoteException e) { + e.printStackTrace(); + } + try { + + this.reacRMI.creerCompte("test","test","pseudo",callBack); + callBack.hasResult(); + assertTrue("Identification invalide",callBack.test == false); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + + @Test + public void testSupprimerCompte(){ + try { + + this.reacRMI.creerCompte("suppr","suppr","suppression",callBack); + callBack.hasResult(); + + authentif = callBack.get(); + + this.reacRMI.supprimerCompte("test","test",authentif,callBack); + callBack.hasResult(); + assertTrue("Compte supprimé",callBack.test==false); + assertFalse("Erreur : Compte supprimé",callBack.test==true); + + this.reacRMI.supprimerCompte("suppr","suppr",authentif,callBack); + callBack.hasResult(); + assertTrue("Compte supprimé :",callBack.test == true); + + + } catch (RemoteException e) { + e.printStackTrace(); + } + + } + + @Test + public void testCreerContexte(){ + try{ + this.reacRMI.creerCompte("contexte","contexte","cont",callBack); + callBack.hasResult(); + authentif = callBack.get(); + + + contexte = new Contexte(); + contexte.setIdentifiantServeur(""); + this.reacRMI.creerContexte(contexte,authentif,cbContexte); + cbContexte.hasResult(); + assertTrue("Contexte crée",(cbContexte.test == true) && cbContexte.get().getIdentifiantServeur().equals("")); + + Contexte test = new Contexte(); + contexte.setIdentifiantServeur("notnul"); + this.reacRMI.creerContexte(test,authentif,cbContexte); + cbContexte.hasResult(); + assertTrue("Contexte non crée",cbContexte.test==false&& !cbContexte.get().getIdentifiantServeur().equals("")); + + } + catch (RemoteException e){ + e.printStackTrace(); + } + + } + + + @Test + public void testSupprimerContexte(){ + try{ + this.reacRMI.supprimerContexte(contexte,authentif,callBack); + callBack.hasResult(); + assertTrue("Contexte supprimé",callBack.test==true); + + Contexte test = new Contexte(); + test.setIdentifiantServeur(""); + this.reacRMI.creerContexte(test,authentif,cbContexte); + cbContexte.hasResult(); + cbContexte.get().setIdentifiantServeur(""); + this.reacRMI.supprimerContexte(test,authentif,callBack); + callBack.hasResult(); + assertTrue("Suppresion échoué : Id vide", callBack.test == false); + + + test = new Contexte(); + this.reacRMI.supprimerContexte(test,authentif,callBack); + callBack.hasResult(); + assertTrue("Suppresion échoué : Le contexte n'appartient pas à l'utilisateur", callBack.test==false); + } + catch (RemoteException e){ + e.printStackTrace(); + } + + } + +} + +