package tests.dao;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.support.FileSystemXmlApplicationContext;
import java.util.List;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import dao.PersonalInfoDAO;
import domain.Folder;
import domain.PersonalInfo;
public class DaoPersonalInfoTest extends TestCase{
//AbstractTransactionalDataSourceSpringContextTests {
private PersonalInfoDAO pidao;
private ApplicationContext ac;
// private DataSourceTransactionManager dstmanager;
public void setUp() {
ac = new FileSystemXmlApplicationContext("webgi-testconfig.xml");
pidao = (PersonalInfoDAO) ac.getBean("personalinfodao");
//dstmanager = (DataSourceTransactionManager) ac.getBean("txManager");
}
//@Override
//protected String[] getConfigLocations() {
// File f = new File("test");
// try {
// System.out.println("NOM PARENT "+f.getCanonicalPath());
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// return new String[]{"C:/Documents and Settings/MISTA/Mes
// documents/iagl/eclipse/workspace/webgi2007/WEB-INF/webgi-testconfig.xml"};
// File f = new File("webgi-testconfig.xml");
// System.out.println("La longueur du fichier webgi : " + f.length());
// System.out.println("son endroit : " + f.getPath());
// try {
// String path = f.getCanonicalPath();
// System.out.println("Le path : " + path);
// return new String[] { path };
// } catch (IOException ioe) {
// return null;
// }
// }
/** Teste la recuperation de l'id */
public void testID() {
PersonalInfo pi = new PersonalInfo();
pi.setLastname("MAHOP");
pi.setFirstname("Georges");
pi.setNationality("ETRANGER");
pi.setEmail("email@email.com");
pi.setPhone("+329220652");
pi.setSex("M");
pi.setBirthdate("1984-08-25");
pi.setPassword("lililili");
/* insertion de l'objet personalinfo */
pidao.storePersonalInfo(pi);
/* L'id doit etre initialis� */
assertTrue(pi.getId() != null);
// dstmanager.rollback();
}
/**Teste la methode getById*/
public void testGetById(){
PersonalInfo pi = new PersonalInfo();
pi.setLastname("HAUS");
pi.setFirstname("MARIE");
pi.setNationality("ETRANGER");
pi.setEmail("email@email2.com");
pi.setPhone("+3292200798");
pi.setSex("F");
pi.setBirthdate("1984-06-27");
pi.setPassword("LOLOPOPOLO");
/*insertion de l'objet personalinfo*/
pidao.storePersonalInfo(pi);
PersonalInfo pi2 = pidao.getById(pi.getId());
assertTrue(pi.getLastname().equals(pi2.getLastname()) &&
pi.getEmail().equals(pi2.getEmail()));
}
/**Teste la recuperation du mot de passe*/
public void testRetreivePassWord1(){
String pass = "PASSWORDTO";
PersonalInfo pi = new PersonalInfo();
pi.setLastname("SMTIH");
pi.setFirstname("Stephane");
pi.setNationality("FRANCAIS");
pi.setEmail("email@email3.com");
pi.setPhone("+32922008424");
pi.setSex("F");
pi.setBirthdate("1985-06-27");
pi.setPassword(pass);
/*insertion de l'objet personalinfo*/
pidao.storePersonalInfo(pi);
PersonalInfo pi2 = pidao.getPassWordForEmail(pi.getEmail());
/**test sur le mot de passe recupere*/
assertTrue(pi2.getPassword().equals(pass));
}
/**Teste la recuperation du mot de passe*/
public void testRetreivePassWord2(){
String pass = "PASSWORDON";
PersonalInfo pi = new PersonalInfo();
pi.setLastname("YANN");
pi.setFirstname("Francis");
pi.setNationality("FRANCAIS");
pi.setEmail("email@email4.com");
pi.setPhone("+32937287382");
pi.setSex("F");
pi.setBirthdate("1986-09-11");
pi.setPassword(pass);
/*insertion de l'objet personalinfo*/
pidao.storePersonalInfo(pi);
PersonalInfo pi2 = pidao.getPassWordForEmail("wrongemail@mail.com");
/**test sur le mot de passe recupere*/
assertTrue(pi2==null);
}
/**Teste la recuperation d'info perso grace a l'email et au mot de
passe*/
public void testRetreivePiWRTEmailAndPassWord1(){
String pass = "PASEWORDOR";
String email="email@email5.com";
PersonalInfo pi = new PersonalInfo();
pi.setLastname("EVE");
pi.setFirstname("Manu");
pi.setNationality("FRANCAIS");
pi.setEmail(email);
pi.setPhone("+3293728734984");
pi.setSex("M");
pi.setBirthdate("1981-12-30");
pi.setPassword(pass);
/*insertion de l'objet personalinfo*/
pidao.storePersonalInfo(pi);
PersonalInfo pi2 = pidao.findByEmailAndPass(pi.getEmail(),
pi.getPassword());
/**test sur les infos receperees*/
assertTrue(pi2.getEmail().equals(email) &&
pi2.getLastname().equals("EVE")&&
pi2.getBirthdate().equals("30-12-1981"));
}
/**Teste la recuperation d'info perso grace a l'email et au mot de
passe*/
public void testRetreivePiWRTEmailAndPassWord2(){
String pass = "JSLEZIDINF";
String email="email@email6.com";
PersonalInfo pi = new PersonalInfo();
pi.setLastname("EVA");
pi.setFirstname("Molla");
pi.setNationality("ETRANGER");
pi.setEmail(email);
pi.setPhone("+3282308439");
pi.setSex("F");
pi.setBirthdate("1981-12-10");
pi.setPassword(pass);
/*insertion de l'objet personalinfo*/
pidao.storePersonalInfo(pi);
PersonalInfo pi2 = pidao.findByEmailAndPass("EV",pass);
/**test sur le mot de passe recupere*/
assertTrue(pi2==null);
}
/**Teste de getByState*/
public void testGetByState1(){
String pass = "JSLEZIOFNF";
String email="email@email7.com";
PersonalInfo pi = new PersonalInfo();
pi.setLastname("LIL");
pi.setFirstname("Ruth");
pi.setNationality("ETRANGER");
pi.setEmail(email);
pi.setPhone("+328928942");
pi.setSex("F");
pi.setBirthdate("1979-12-01");
pi.setPassword(pass);
pi.setState(Folder.FOLDER_FINALIZED);
String pass2 = "JEKEZIDINF";
String email2="email@email8.com";
PersonalInfo pi2 = new PersonalInfo();
pi2.setLastname("BOBI");
pi2.setFirstname("Morre");
pi2.setNationality("FRANCAIS");
pi2.setEmail(email2);
pi2.setPhone("+328233829038");
pi2.setSex("M");
pi2.setBirthdate("1981-04-19");
pi2.setPassword(pass2);
pi2.setState(Folder.FOLDER_FINALIZED);
/*on store les pis*/
pidao.storePersonalInfo(pi);
pidao.storePersonalInfo(pi2);
List result = pidao.getPersonalInfoByState(Folder.FOLDER_FINALIZED);
assertTrue(result.size()==2);
}
/**Teste de getByState*/
public void testGetByState2(){
String pass = "JSLEZNARNF";
String email="email@email9.com";
PersonalInfo pi = new PersonalInfo();
pi.setLastname("LILO");
pi.setFirstname("Bibo");
pi.setNationality("ETRANGER");
pi.setEmail(email);
pi.setPhone("+3284242942");
pi.setSex("M");
pi.setBirthdate("1979-11-13");
pi.setPassword(pass);
pi.setState(Folder.FOLDER_FINALIZED);
String pass2 = "JEKEZIBDUE";
String email2="email@email10.com";
PersonalInfo pi2 = new PersonalInfo();
pi2.setLastname("BOBU");
pi2.setFirstname("Mire");
pi2.setNationality("FRANCAIS");
pi2.setEmail(email2);
pi2.setPhone("+324393829038");
pi2.setSex("M");
pi2.setBirthdate("1984-02-14");
pi2.setPassword(pass2);
pi2.setState(Folder.FOLDER_FINALIZED);
String pass3 = "JEKEZIBDUE";
String email3="email@email11.com";
PersonalInfo pi3 = new PersonalInfo();
pi3.setLastname("MALLO");
pi3.setFirstname("Kito");
pi3.setNationality("ETRANGER");
pi3.setEmail(email3);
pi3.setPhone("+3243934738943");
pi3.setSex("M");
pi3.setBirthdate("1987-03-15");
pi3.setPassword(pass3);
pi3.setState(Folder.FOLDER_SAVED);
/*on store les pis*/
pidao.storePersonalInfo(pi);
pidao.storePersonalInfo(pi2);
pidao.storePersonalInfo(pi3);
List result = pidao.getPersonalInfoByState(Folder.FOLDER_SAVED);
assertTrue(result.size()==1);
}
/**Teste de getByState*/
public void testGetByState3(){
List result = pidao.getPersonalInfoByState("jdslfqjdk");
assertTrue(result.isEmpty());
}
/**test de update*/
public void testUpdate1(){
String pass = "JSLEZNARNF";
String email="email@email12.com";
PersonalInfo pi = new PersonalInfo();
pi.setLastname("KAKU");
pi.setFirstname("Lion");
pi.setNationality("ETRANGER");
pi.setEmail(email);
pi.setPhone("+328443902232");
pi.setSex("M");
pi.setBirthdate("1979-09-24");
pi.setPassword(pass);
pi.setState(Folder.FOLDER_FINALIZED);
/*on store les pis*/
pidao.storePersonalInfo(pi);
/*on recupere le pi et on change le prenom*/
PersonalInfo pi2 = pidao.getById(pi.getId());
pi2.setFirstname("Mars");
/*on met a jour avec la methode store*/
pidao.storePersonalInfo(pi2);
PersonalInfo pi3 = pidao.getById(pi2.getId());
assertTrue(pi3.getFirstname().equals(pi2.getFirstname()) &&
pi3.getNationality().equals(pi.getNationality()));
}
/**test de update*/
public void testUpdate2(){
String pass = "JSLEBONDNF";
String email="email@email13.com";
PersonalInfo pi = new PersonalInfo();
pi.setLastname("KAKI");
pi.setFirstname("Twix");
pi.setNationality("ETRANGER");
pi.setEmail(email);
pi.setPhone("+3248390432");
pi.setSex("M");
pi.setBirthdate("1979-05-02");
pi.setPassword(pass);
pi.setState(Folder.FOLDER_SAVED);
/*on store les pis*/
pidao.storePersonalInfo(pi);
/*On met a jour l'etat du pi*/
pidao.updateState(pi.getId(), Folder.FOLDER_FINALIZED);
/*on recupere le pi et on change le prenom*/
PersonalInfo pi2 = pidao.getById(pi.getId());
assertFalse(pi2.getState().equals(Folder.FOLDER_SAVED));
}
}