From 8c7cda026e6b0a8e427893ac7cd6d62fbebe72bf Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Tue, 7 Jun 2022 17:11:54 +0200 Subject: [PATCH] =?UTF-8?q?test=20unitaires=20qui=20se=20basent=20sur=20la?= =?UTF-8?q?=20fen=C3=AAtre=20de=20r=C3=A9sultats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/univ_amu/iut/fResultat/TableEntry.java | 44 +++++++++++++++++ .../java/fr/univ_amu/iut/fp/Controller.java | 3 ++ .../fr/univ_amu/iut/test/DAOUsageTest.java | 13 ++++- src/test/java/fr/univ_amu/iut/AppTest.java | 49 ++++++++++++++++++- 4 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/univ_amu/iut/fResultat/TableEntry.java b/src/main/java/fr/univ_amu/iut/fResultat/TableEntry.java index 41c3c75..aec118e 100644 --- a/src/main/java/fr/univ_amu/iut/fResultat/TableEntry.java +++ b/src/main/java/fr/univ_amu/iut/fResultat/TableEntry.java @@ -8,12 +8,15 @@ public class TableEntry { private String nom; private String discipline; + private String thematique; private String description; private String niveau; public TableEntry(Usage usage) { nom = usage.getNom(); + thematique = usage.getThematique().getNom(); discipline = usage.getDiscipline().getNom(); + System.out.println("DESC="+usage.getDescription()); description = usage.getDescription(); niveau = usage.getNiveau().getNom(); } @@ -34,6 +37,15 @@ public class TableEntry { this.discipline = discipline; } + + public String getThematique() { + return thematique; + } + + public void setThematique(String thematique) { + this.thematique = thematique; + } + public String getDescription() { return description; } @@ -51,4 +63,36 @@ public class TableEntry { } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TableEntry that = (TableEntry) o; + + if (nom != null ? !nom.equals(that.nom) : that.nom != null) return false; + if (discipline != null ? !discipline.equals(that.discipline) : that.discipline != null) return false; + if (description != null ? !description.equals(that.description) : that.description != null) return false; + return niveau != null ? niveau.equals(that.niveau) : that.niveau == null; + } + + @Override + public int hashCode() { + int result = nom != null ? nom.hashCode() : 0; + result = 31 * result + (discipline != null ? discipline.hashCode() : 0); + result = 31 * result + (description != null ? description.hashCode() : 0); + result = 31 * result + (niveau != null ? niveau.hashCode() : 0); + return result; + } + + + @Override + public String toString() { + return "TableEntry{" + + "nom='" + nom + '\'' + + ", discipline='" + discipline + '\'' + + ", description='" + description + '\'' + + ", niveau='" + niveau + '\'' + + '}'; + } } diff --git a/src/main/java/fr/univ_amu/iut/fp/Controller.java b/src/main/java/fr/univ_amu/iut/fp/Controller.java index 4b2882b..c87792f 100644 --- a/src/main/java/fr/univ_amu/iut/fp/Controller.java +++ b/src/main/java/fr/univ_amu/iut/fp/Controller.java @@ -43,6 +43,8 @@ public class Controller implements Initializable { DAOThematique daoThematique; DAOUsage daoUsage; + Stage lastResultSceneOpened; + @FXML private Pane stackPaneFrance; @@ -205,6 +207,7 @@ public class Controller implements Initializable { try { resultats.setScene(new Scene(FXMLLoader.load(getClass().getResource("/fr/univ_amu/iut/fResultat/FResultat.fxml")))); resultats.show(); + lastResultSceneOpened = resultats; } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/fr/univ_amu/iut/test/DAOUsageTest.java b/src/main/java/fr/univ_amu/iut/test/DAOUsageTest.java index f456276..6b77901 100644 --- a/src/main/java/fr/univ_amu/iut/test/DAOUsageTest.java +++ b/src/main/java/fr/univ_amu/iut/test/DAOUsageTest.java @@ -23,13 +23,22 @@ public class DAOUsageTest implements DAOUsage{ List usages = new ArrayList<>(); for( int i = 0; i < 42 ; i++){ Usage tmp = new Usage(); - tmp.setNom(String.valueOf(i)); + tmp.setNom("Usage n°"+ i); tmp.setDiscipline(Discipline.Technologie); tmp.setThematique(Thematique.CreationNumerique); tmp.setNiveau(Niveau.Tous); - tmp.setDescription("je suis un commentaire tres long mais surtout tres utile, je sert a tester l'interface graphique et la mettre au bout de ses limtes"); + tmp.setDescription("je suis un commentaire tres long mais surtout tres utile, je sert a tester l'interface graphique et la mettre au bout de ses limites"); usages.add(tmp); } + + Usage tmp = new Usage(); + tmp.setNom("Usage spécial 1"); + tmp.setDiscipline(Discipline.PhysiqueChimie); + tmp.setThematique(Thematique.ClasseInversee); + tmp.setNiveau(Niveau.PremierDegre); + tmp.setDescription("Un usage très simple, pour un test de recherche"); + usages.add(tmp); + return usages; } diff --git a/src/test/java/fr/univ_amu/iut/AppTest.java b/src/test/java/fr/univ_amu/iut/AppTest.java index 58ae6d3..0cc0b8a 100644 --- a/src/test/java/fr/univ_amu/iut/AppTest.java +++ b/src/test/java/fr/univ_amu/iut/AppTest.java @@ -1,11 +1,16 @@ package fr.univ_amu.iut; +import fr.univ_amu.iut.fResultat.TableEntry; import fr.univ_amu.iut.model.Discipline; +import fr.univ_amu.iut.model.Niveau; import fr.univ_amu.iut.model.Thematique; import javafx.scene.Node; +import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.TableView; import javafx.scene.layout.Pane; import javafx.stage.Stage; +import javafx.stage.Window; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -69,7 +74,39 @@ public class AppTest { } @Test - void test_recherche(FxRobot robot) { + void search_should_open_window(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)); + + + int windowsCount = Stage.getWindows().size(); + robot.clickOn(recherche); + assertThat(Stage.getWindows().size()).isEqualTo(windowsCount+1); + } + @Test + void search_window_should_have_1_result(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)); + + + int windowsCount = Stage.getWindows().size(); + robot.clickOn(recherche); + + Scene resultScene = Stage.getWindows().get(windowsCount).getScene(); + TableView table = (TableView) resultScene.lookup("#table"); + assertThat(table.getItems().size()).isEqualTo(1); + } + + @Test + void search_window_result_should_be_shown(FxRobot robot) { Pane disciplinesPane = (Pane) stage.getScene().lookup("#discipline"); Pane thematiquesPane = (Pane) stage.getScene().lookup("#thematique"); Node recherche = stage.getScene().lookup("#recherche"); @@ -78,6 +115,16 @@ public class AppTest { robot.clickOn(thematiquesPane.getChildren().get(0)); robot.clickOn(recherche); + + Scene resultScene = Stage.getWindows().get(1).getScene(); + TableView table = (TableView) resultScene.lookup("#table"); + TableEntry entry = table.getItems().get(0); + + assertThat(entry.getNom()).isEqualTo("Usage spécial 1"); + assertThat(entry.getDescription()).isEqualTo("Un usage très simple, pour un test de recherche"); + assertThat(entry.getDiscipline()).isEqualTo(Discipline.PhysiqueChimie.getNom()); + assertThat(entry.getThematique()).isEqualTo(Thematique.ClasseInversee.getNom()); + assertThat(entry.getNiveau()).isEqualTo(Niveau.PremierDegre.getNom()); } } \ No newline at end of file