Début des tests de l'application
This commit is contained in:
parent
f92fb05448
commit
9cb365f8af
@ -9,12 +9,19 @@ import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class Main extends Application {
|
||||
public class AppMain extends Application {
|
||||
private Scene scene = new Scene(new Pane());
|
||||
private ScreenController gestionnaireDePages = new ScreenController(scene);
|
||||
|
||||
public static boolean testMode;
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException{
|
||||
|
||||
String res = getParameters().getNamed().get("testMode");
|
||||
testMode = res!=null&&res.equals("true");
|
||||
|
||||
|
||||
ScreenController.addScreen("Acceuil",FXMLLoader.load(getClass().getResource("/fr/univ_amu/iut/fp/fp.fxml")));
|
||||
|
||||
//TODO Ajouter les pages d'admin pour l'ajout des usages
|
||||
@ -28,7 +35,6 @@ public class Main extends Application {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Thread.sleep(5000);
|
||||
launch(args);
|
||||
}
|
||||
}
|
@ -2,6 +2,6 @@ package fr.univ_amu.iut;
|
||||
|
||||
public class Launcher {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Main.main(args);
|
||||
AppMain.main(args);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ import fr.univ_amu.iut.test.DAOFactoryTest;
|
||||
public class DAOFactoryProducer {
|
||||
public static DAOFactory getFactory(DAOType type) {
|
||||
return switch (type){
|
||||
case JPA -> new DAOFactoryJPA();
|
||||
case JPA -> new DAOFactoryJPA("gestionUsagesPU");
|
||||
case JPA_MEMORY -> new DAOFactoryJPA("gestionUsagesPUMemory");
|
||||
case TEST -> new DAOFactoryTest();
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
|
@ -2,5 +2,6 @@ package fr.univ_amu.iut.dao.factory;
|
||||
|
||||
public enum DAOType {
|
||||
JPA,
|
||||
TEST
|
||||
JPA_MEMORY, // JPA, mais sans persistence (base de données en mémoire) (utilisé pour le test de JPA)
|
||||
TEST // utilisé pour le test de l'interface graphique
|
||||
}
|
||||
|
@ -37,15 +37,11 @@ public class DAOFactoryJPA implements DAOFactory {
|
||||
public DAOFactoryJPA(String unitName){
|
||||
this.unitName = unitName;
|
||||
|
||||
|
||||
insertAllHelper(createDAORegionAcademique(), RegionAcademique.toutes());
|
||||
insertAllHelper(createDAOAcademie(), Academie.toutes());
|
||||
insertAllHelper(createDAOThematique(), Thematique.toutes());
|
||||
insertAllHelper(createDAODiscipline(), Discipline.toutes());
|
||||
}
|
||||
public DAOFactoryJPA(){
|
||||
this("gestionUsagesPU");
|
||||
}
|
||||
|
||||
public EntityManager getEntityManager() {
|
||||
if(entityManager == null){
|
||||
|
@ -1,5 +1,6 @@
|
||||
package fr.univ_amu.iut.fp;
|
||||
|
||||
import fr.univ_amu.iut.AppMain;
|
||||
import fr.univ_amu.iut.Donnees;
|
||||
import fr.univ_amu.iut.dao.DAODiscipline;
|
||||
import fr.univ_amu.iut.dao.DAORessource;
|
||||
@ -163,7 +164,8 @@ public class Controller implements Initializable {
|
||||
stackPaneFrance.getChildren().add(france);
|
||||
|
||||
// init
|
||||
daoFactory = DAOFactoryProducer.getFactory(DAOType.TEST);
|
||||
|
||||
daoFactory = DAOFactoryProducer.getFactory(AppMain.testMode ? DAOType.TEST : DAOType.JPA);
|
||||
daoDiscipline = daoFactory.createDAODiscipline();
|
||||
daoThematique = daoFactory.createDAOThematique();
|
||||
daoUsage = daoFactory.createDAOUsage();
|
||||
|
@ -16,12 +16,7 @@ public class DAOThematiqueTest implements DAOThematique {
|
||||
|
||||
@Override
|
||||
public List<Thematique> findAll() {
|
||||
List<Thematique> liste = new ArrayList<>();
|
||||
for (int i = 0; i < 12; i++){
|
||||
Thematique thematique = new Thematique("Thematique n° "+i);
|
||||
liste.add(thematique);
|
||||
}
|
||||
return liste;
|
||||
return Thematique.toutes();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
<properties>
|
||||
<!-- database connection properties -->
|
||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://localhost/devapp"/>
|
||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://lagrottedeneotaku.hopto.org:6776/devapp"/>
|
||||
<property name="jakarta.persistence.jdbc.user" value="devapp"/>
|
||||
<property name="jakarta.persistence.jdbc.password" value="7kPoWBgoV5ahygxyXYGzaL"/>
|
||||
<!-- Nous ne devrions pas commit le mot de passe dans le dépot, mais... je ne pense pas que le projet ne respecte la moindre règle de sécurité de toute facon (pas d'architecture trois tiers)-->
|
||||
@ -21,7 +21,7 @@
|
||||
<property name="eclipselink.logging.parameters" value="true"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
<persistence-unit name="gestionUsagesPUTest" transaction-type="RESOURCE_LOCAL">
|
||||
<persistence-unit name="gestionUsagesPUMemory" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
|
||||
<exclude-unlisted-classes>false</exclude-unlisted-classes>
|
||||
|
||||
|
@ -1,11 +1,83 @@
|
||||
package fr.univ_amu.iut;
|
||||
|
||||
import fr.univ_amu.iut.model.Discipline;
|
||||
import fr.univ_amu.iut.model.Thematique;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.testfx.api.FxRobot;
|
||||
import org.testfx.framework.junit5.ApplicationExtension;
|
||||
import org.testfx.framework.junit5.ApplicationTest;
|
||||
import org.testfx.framework.junit5.Start;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(ApplicationExtension.class)
|
||||
public class AppTest {
|
||||
|
||||
Stage stage;
|
||||
|
||||
@BeforeEach
|
||||
void setUpClass() throws Exception {
|
||||
ApplicationTest.launch(AppMain.class, "--testMode=true");
|
||||
}
|
||||
|
||||
@Start
|
||||
public void start(Stage stage) throws Exception {
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_should_never_fail() {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_initialize_stage_is_showing() {
|
||||
assertThat(stage.isShowing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void title_is_correct() {
|
||||
assertThat(stage.getTitle()).isEqualTo("Carte des académie");
|
||||
}
|
||||
|
||||
@Test
|
||||
void boutons_ajoutes() {
|
||||
Pane disciplinesPane = (Pane) stage.getScene().lookup("#discipline");
|
||||
Pane thematiquesPane = (Pane) stage.getScene().lookup("#thematique");
|
||||
|
||||
assertThat(disciplinesPane.getChildren().size()).isEqualTo(Discipline.toutes().size());
|
||||
assertThat(thematiquesPane.getChildren().size()).isEqualTo(Thematique.toutes().size());
|
||||
|
||||
for(int i=0;i<disciplinesPane.getChildren().size();i++){
|
||||
String actualtext = ((Button)disciplinesPane.getChildren().get(i)).getText();
|
||||
String expectedText = Discipline.toutes().get(i).getNom();
|
||||
assertThat(actualtext).isEqualTo(expectedText);
|
||||
}
|
||||
for(int i=0;i<thematiquesPane.getChildren().size();i++){
|
||||
String actualtext = ((Button)thematiquesPane.getChildren().get(i)).getText();
|
||||
String expectedText = Thematique.toutes().get(i).getNom();
|
||||
assertThat(actualtext).isEqualTo(expectedText);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_recherche(FxRobot robot) {
|
||||
Pane disciplinesPane = (Pane) stage.getScene().lookup("#discipline");
|
||||
Pane thematiquesPane = (Pane) stage.getScene().lookup("#thematique");
|
||||
Node recherche = stage.getScene().lookup("#recherche");
|
||||
|
||||
robot.clickOn(disciplinesPane.getChildren().get(1));
|
||||
robot.clickOn(thematiquesPane.getChildren().get(0));
|
||||
|
||||
robot.clickOn(recherche);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package fr.univ_amu.iut;
|
||||
|
||||
import fr.univ_amu.iut.dao.factory.DAOFactory;
|
||||
import fr.univ_amu.iut.dao.factory.DAOFactoryProducer;
|
||||
import fr.univ_amu.iut.dao.factory.DAOType;
|
||||
import fr.univ_amu.iut.dao.jpa.DAOFactoryJPA;
|
||||
import fr.univ_amu.iut.model.*;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@ -10,11 +13,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BackendTest {
|
||||
|
||||
private static DAOFactoryJPA daoFactory;
|
||||
private static DAOFactory daoFactory;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
daoFactory = new DAOFactoryJPA("gestionUsagesPUTest");
|
||||
daoFactory = DAOFactoryProducer.getFactory(DAOType.JPA_MEMORY);
|
||||
|
||||
Usage usage = new Usage();
|
||||
usage.setNom("Premier usage");
|
||||
|
Loading…
Reference in New Issue
Block a user