From 8e3b06918889df0eb60f284d816fa25b0bfe6429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natha=C3=ABl=20NOGU=C3=88S?= Date: Wed, 27 Jul 2016 11:59:43 +0200 Subject: [PATCH] TEST refs #31 : tests for Main --- .../src/main/java/sandbox/SubjectJsonGen.java | 4 +- .../main/java/fr/axonic/avek/gui/Main.java | 28 +- .../gui/components/results/JellyBean.java | 1 + .../results/JellyBeansSelector.java | 20 +- ...Effect.java => ExperimentationResult.java} | 6 +- .../structure/ExperimentationResults.java | 29 --- .../structure/ExperimentationResultsMap.java | 19 ++ .../gui/model/structure/UploadedFile.java | 2 - .../avek/gui/util/ConcurrentTaskManager.java | 2 +- .../java/fr/axonic/avek/gui/util/Util.java | 8 - .../avek/gui/view/EstablishEffectView.java | 4 +- .../avek/gui/view/StrategySelectionView.java | 14 - .../fr/axonic/avek/gui/view/TreatView.java | 4 +- .../main/resources/files/parametersFile.json | 2 +- .../src/main/resources/files/resultEnum1.json | 242 +++++++++--------- .../src/main/resources/files/subjectFile.json | 2 +- .../fxml/views/StrategySelectionView.fxml | 8 +- .../java/fr/axonic/avek/gui/TestMain.java | 54 ++++ .../components/parameters/TestFileList.java | 9 +- .../TestGeneralizedParametersPane.java | 4 +- .../parameters/TestParametersCategory.java | 4 +- .../results/TestJellyBeanSelector.java | 12 +- .../components/results/TestJellyBeans.java | 4 +- .../components/subjects/TestSubjectData.java | 51 ++-- .../{view => }/model/json/TestJsonifier.java | 43 +++- .../model/structure/TestUploadedFile.java | 12 +- .../Utils.java => util/UtilForTests.java} | 12 +- .../avek/gui/view/TestMainController.java | 39 --- 28 files changed, 321 insertions(+), 318 deletions(-) rename avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/{ExpEffect.java => ExperimentationResult.java} (75%) delete mode 100644 avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResults.java create mode 100644 avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResultsMap.java create mode 100644 avek-gui/src/test/java/fr/axonic/avek/gui/TestMain.java rename avek-gui/src/test/java/fr/axonic/avek/gui/{view => }/model/json/TestJsonifier.java (64%) rename avek-gui/src/test/java/fr/axonic/avek/gui/{view => }/model/structure/TestUploadedFile.java (93%) rename avek-gui/src/test/java/fr/axonic/avek/gui/{view/Utils.java => util/UtilForTests.java} (80%) delete mode 100644 avek-gui/src/test/java/fr/axonic/avek/gui/view/TestMainController.java diff --git a/avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java b/avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java index 3599fc0..0ea65da 100644 --- a/avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java +++ b/avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java @@ -3,7 +3,7 @@ import fr.axonic.avek.gui.model.json.Jsonifier; import fr.axonic.avek.gui.model.sample.ExampleState; import fr.axonic.avek.gui.model.sample.ExampleStateBool; -import fr.axonic.avek.gui.model.structure.ExperimentationResults; +import fr.axonic.avek.gui.model.structure.ExperimentationResultsMap; import fr.axonic.avek.model.MonitoredSystem; import fr.axonic.avek.model.base.ADate; import fr.axonic.avek.model.base.ANumber; @@ -62,7 +62,7 @@ private static String generateSubject() { } public static String generateParameters() throws VerificationException { - ExperimentationResults expRes = new ExperimentationResults(); + ExperimentationResultsMap expRes = new ExperimentationResultsMap(); { ARangedEnum aEnum = new ARangedEnum<>(ExampleState.VERY_LOW); aEnum.setRange(Arrays.asList(ExampleState.values())); diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/Main.java b/avek-gui/src/main/java/fr/axonic/avek/gui/Main.java index fcbae4e..d5cf03e 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/Main.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/Main.java @@ -1,8 +1,5 @@ package fr.axonic.avek.gui; -import fr.axonic.avek.gui.util.ConcurrentTaskManager; -import fr.axonic.avek.gui.util.Util; -import fr.axonic.avek.gui.view.GeneralizedView; import fr.axonic.avek.gui.view.MainFrame; import javafx.application.Application; import javafx.scene.Scene; @@ -14,39 +11,28 @@ public class Main extends Application { private final static Logger logger = Logger.getLogger(Main.class); + private MainFrame mainFrame; + public static void main(String[] args) { launch(args); } + @Override public void start(Stage primaryStage) throws IOException { - ConcurrentTaskManager ctm = new ConcurrentTaskManager(); - logger.debug("Loading MainFrame..."); primaryStage.setTitle("#AVEK analyzer"); - MainFrame mainFrame = new MainFrame(); + mainFrame = new MainFrame(); Scene s = new Scene(mainFrame, 800, 600); primaryStage.setScene(s); primaryStage.show(); logger.debug("MainFrame created."); - - - ctm.runLaterOnThread(() -> { - try { - GeneralizedView generalizedView = new GeneralizedView(); - Thread.sleep(2000); - ctm.runLaterOnPlatform(() -> mainFrame.setView(generalizedView)); - Thread.sleep(2000); - ctm.runLaterOnPlatform(() -> generalizedView.setMonitoredSystem(Util.getFileContent("files/subjectFile.json"))); - Thread.sleep(2000); - ctm.runLaterOnPlatform(() -> generalizedView.setExperimentParameters(Util.getFileContent("files/parametersFile.json"))); - } catch (Exception e) { - e.printStackTrace(); - } - }); } + MainFrame getMainFrame() { + return mainFrame; + } } \ No newline at end of file diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBean.java b/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBean.java index 3b90a28..7ef41a3 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBean.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBean.java @@ -31,6 +31,7 @@ public class JellyBean extends HBox { private Object expEffect; private JellyBeansSelector mainController; + // should be public public JellyBean() { FXMLLoader fxmlLoader = new FXMLLoader(FXML); fxmlLoader.setRoot(this); diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBeansSelector.java b/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBeansSelector.java index 9ccd477..0903965 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBeansSelector.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBeansSelector.java @@ -1,8 +1,8 @@ package fr.axonic.avek.gui.components.results; import fr.axonic.avek.gui.model.json.Jsonifier; -import fr.axonic.avek.gui.model.structure.ExpEffect; -import fr.axonic.avek.gui.model.structure.ExperimentationResults; +import fr.axonic.avek.gui.model.structure.ExperimentationResult; +import fr.axonic.avek.gui.model.structure.ExperimentationResultsMap; import fr.axonic.avek.gui.util.Util; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -38,7 +38,7 @@ public class JellyBeansSelector extends VBox { @FXML private FlowPane jellyBeansPane; @FXML - private ComboBox comboBoxJellyBean; + private ComboBox comboBoxJellyBean; private final Set addedEffects; @@ -65,7 +65,7 @@ public JellyBeansSelector() { // Fill experiment sample list String results = Util.getFileContent("files/resultEnum1.json"); - ExperimentationResults expr = new Jsonifier<>(ExperimentationResults.class).fromJson(results); + ExperimentationResultsMap expr = new Jsonifier<>(ExperimentationResultsMap.class).fromJson(results); setJellyBeansChoice(FXCollections.observableArrayList(expr.getList())); } @@ -90,12 +90,12 @@ void onNewExpEffectClicked(ActionEvent event) { */ private void updateJellyBeanChoice() { comboBoxJellyBean.setCellFactory( - new Callback, ListCell>() { + new Callback, ListCell>() { @Override - public ListCell call(ListView param) { - return new ListCell() { + public ListCell call(ListView param) { + return new ListCell() { @Override - public void updateItem(ExpEffect item, boolean empty) { + public void updateItem(ExperimentationResult item, boolean empty) { super.updateItem(item, empty); if (item != null) { setText(item.getName()); @@ -111,7 +111,7 @@ public void updateItem(ExpEffect item, boolean empty) { private void addJellyBean() { // Verify if JellyBean already created (this result is already selected) - ExpEffect choice = comboBoxJellyBean.getValue(); + ExperimentationResult choice = comboBoxJellyBean.getValue(); if (choice == null) { logger.warn("Choice is null"); return; @@ -135,7 +135,7 @@ void removeJellyBean(JellyBean jbc) { updateJellyBeanChoice(); } - public void setJellyBeansChoice(ObservableList items) { + void setJellyBeansChoice(ObservableList items) { this.comboBoxJellyBean.setItems(items); } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExpEffect.java b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResult.java similarity index 75% rename from avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExpEffect.java rename to avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResult.java index 1dce1d0..872edc3 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExpEffect.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResult.java @@ -5,12 +5,12 @@ /** * Created by Nathaël N on 07/07/16. */ -public class ExpEffect { +public class ExperimentationResult { private final ARangedEnum states; private final String name; - public ExpEffect(String name, ARangedEnum aEnum) { - this.states = aEnum; + public ExperimentationResult(String name, ARangedEnum states) { + this.states = states; this.name = name; } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResults.java b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResults.java deleted file mode 100644 index 265db9e..0000000 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResults.java +++ /dev/null @@ -1,29 +0,0 @@ -package fr.axonic.avek.gui.model.structure; - -import fr.axonic.avek.model.base.ARangedEnum; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Created by Nathaël N on 12/07/16. - */ -public class ExperimentationResults { - private final Map results; - - public ExperimentationResults() { - results = new HashMap<>(); - } - - public void put(String ae1, ARangedEnum aEnum) { - results.put(ae1, aEnum); - } - - public List getList() { - return results.keySet().stream() - .map(s -> new ExpEffect(s, results.get(s))) - .collect(Collectors.toList()); - } -} diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResultsMap.java b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResultsMap.java new file mode 100644 index 0000000..86d7f2f --- /dev/null +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResultsMap.java @@ -0,0 +1,19 @@ +package fr.axonic.avek.gui.model.structure; + +import fr.axonic.avek.model.base.ARangedEnum; + +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by Nathaël N on 12/07/16. + */ +public class ExperimentationResultsMap extends HashMap { + + public List getList() { + return keySet().stream() + .map(s -> new ExperimentationResult(s, get(s))) + .collect(Collectors.toList()); + } +} diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/UploadedFile.java b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/UploadedFile.java index d600566..9e17de3 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/UploadedFile.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/UploadedFile.java @@ -162,8 +162,6 @@ public double getPct() { public boolean equals(Object obj) { if (obj instanceof UploadedFile) return origin.equals(((UploadedFile) obj).origin); - if (obj instanceof File) - return origin.equals(obj) || uploaded.equals(obj); return super.equals(obj); } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java b/avek-gui/src/main/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java index c9d9926..d27620d 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java @@ -33,7 +33,7 @@ private void run(Callable c, boolean onPlatform) { try { c.call(); } catch (Exception e) { - e.printStackTrace(); + logger.error("Exception thrown during task call", e); } return; } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/util/Util.java b/avek-gui/src/main/java/fr/axonic/avek/gui/util/Util.java index 396f4f9..50e1caa 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/util/Util.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/util/Util.java @@ -27,12 +27,4 @@ public static String getFileContent(String path) { } return res; } - - public static void disableGraphics() { - System.setProperty("testfx.robot", "glass"); - System.setProperty("prism.order", "sw"); - System.setProperty("testfx.headless", "true"); - System.setProperty("java.awt.headless", "true"); - System.setProperty("prism.text", "t2k"); - } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java index c56eacf..48e6c39 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java @@ -41,11 +41,11 @@ void onClicStrategyButton(ActionEvent event) { * * @param monitoredSystemJson the MonitoredSystem as a Json String */ - void setMonitoredSystem(String monitoredSystemJson) { + public void setMonitoredSystem(String monitoredSystemJson) { monitoredSystemPane.setMonitoredSystem(MonitoredSystem.fromJson(monitoredSystemJson)); } - void setExperimentParameters(String experimentParametersJson) { + public void setExperimentParameters(String experimentParametersJson) { AList list = Jsonifier.toAListofAListAndAVar(experimentParametersJson); for (AEntity ae : list.getEntities()) diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java index f554288..8a823f4 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java @@ -1,26 +1,12 @@ package fr.axonic.avek.gui.view; -import fr.axonic.avek.gui.components.MonitoredSystemPane; -import fr.axonic.avek.gui.components.parameters.GeneralizedParametersPane; -import fr.axonic.avek.gui.components.results.JellyBeansSelector; -import fr.axonic.avek.gui.model.json.Jsonifier; -import fr.axonic.avek.gui.model.structure.ExpEffect; -import fr.axonic.avek.model.MonitoredSystem; -import fr.axonic.avek.model.base.engine.AEntity; -import fr.axonic.avek.model.base.engine.AList; import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; -import javafx.util.Callback; import org.apache.log4j.Logger; -import java.io.IOException; -import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java index dac91f3..62c0752 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java @@ -38,11 +38,11 @@ void onClicStrategyButton(ActionEvent event) { * * @param monitoredSystemJson the MonitoredSystem as a Json String */ - void setMonitoredSystem(String monitoredSystemJson) { + public void setMonitoredSystem(String monitoredSystemJson) { monitoredSystemPane.setMonitoredSystem(MonitoredSystem.fromJson(monitoredSystemJson)); } - void setExperimentParameters(String experimentParametersJson) { + public void setExperimentParameters(String experimentParametersJson) { AList list = Jsonifier.toAListofAListAndAVar(experimentParametersJson); for (AEntity ae : list.getEntities()) diff --git a/avek-gui/src/main/resources/files/parametersFile.json b/avek-gui/src/main/resources/files/parametersFile.json index c06c14c..3c614ac 100644 --- a/avek-gui/src/main/resources/files/parametersFile.json +++ b/avek-gui/src/main/resources/files/parametersFile.json @@ -30,7 +30,7 @@ "label": "SubNumber" }, { - "value": "Jul 25, 2016 9:50:31 AM", + "value": "Jul 27, 2016 11:21:54 AM", "format": { "formatType": "DATE" }, diff --git a/avek-gui/src/main/resources/files/resultEnum1.json b/avek-gui/src/main/resources/files/resultEnum1.json index 316b1ca..4e92d5c 100644 --- a/avek-gui/src/main/resources/files/resultEnum1.json +++ b/avek-gui/src/main/resources/files/resultEnum1.json @@ -1,133 +1,131 @@ { - "results": { - "AE4": { - "range": [ - "VERY_LOW", - "LOW", - "MEDIUM", - "HIGH", - "VERY_HIGH" - ], - "value": "VERY_LOW", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false + "AE4": { + "range": [ + "VERY_LOW", + "LOW", + "MEDIUM", + "HIGH", + "VERY_HIGH" + ], + "value": "VERY_LOW", + "format": { + "formatType": "ENUM" }, - "AE5": { - "range": [ - "VERY_LOW", - "LOW", - "MEDIUM", - "HIGH", - "VERY_HIGH" - ], - "value": "VERY_LOW", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false + "editable": false, + "mandatory": false + }, + "AE5": { + "range": [ + "VERY_LOW", + "LOW", + "MEDIUM", + "HIGH", + "VERY_HIGH" + ], + "value": "VERY_LOW", + "format": { + "formatType": "ENUM" }, - "AE6": { - "range": [ - "VERY_LOW", - "LOW", - "MEDIUM", - "HIGH", - "VERY_HIGH" - ], - "value": "MEDIUM", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false + "editable": false, + "mandatory": false + }, + "AE6": { + "range": [ + "VERY_LOW", + "LOW", + "MEDIUM", + "HIGH", + "VERY_HIGH" + ], + "value": "MEDIUM", + "format": { + "formatType": "ENUM" }, - "AE7": { - "range": [ - "VERY_LOW", - "LOW", - "MEDIUM", - "HIGH", - "VERY_HIGH" - ], - "value": "VERY_LOW", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false + "editable": false, + "mandatory": false + }, + "AE7": { + "range": [ + "VERY_LOW", + "LOW", + "MEDIUM", + "HIGH", + "VERY_HIGH" + ], + "value": "VERY_LOW", + "format": { + "formatType": "ENUM" }, - "AE8": { - "range": [ - "TRUE", - "FALSE" - ], - "value": "TRUE", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false + "editable": false, + "mandatory": false + }, + "AE8": { + "range": [ + "TRUE", + "FALSE" + ], + "value": "TRUE", + "format": { + "formatType": "ENUM" }, - "AE9": { - "range": [ - "VERY_LOW", - "LOW", - "MEDIUM", - "HIGH", - "VERY_HIGH" - ], - "value": "VERY_LOW", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false + "editable": false, + "mandatory": false + }, + "AE9": { + "range": [ + "VERY_LOW", + "LOW", + "MEDIUM", + "HIGH", + "VERY_HIGH" + ], + "value": "VERY_LOW", + "format": { + "formatType": "ENUM" }, - "AE1": { - "range": [ - "VERY_LOW", - "LOW", - "MEDIUM", - "HIGH", - "VERY_HIGH" - ], - "value": "VERY_LOW", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false + "editable": false, + "mandatory": false + }, + "AE1": { + "range": [ + "VERY_LOW", + "LOW", + "MEDIUM", + "HIGH", + "VERY_HIGH" + ], + "value": "VERY_LOW", + "format": { + "formatType": "ENUM" }, - "AE2": { - "range": [ - "VERY_LOW", - "LOW", - "MEDIUM", - "HIGH", - "VERY_HIGH" - ], - "value": "VERY_LOW", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false + "editable": false, + "mandatory": false + }, + "AE2": { + "range": [ + "VERY_LOW", + "LOW", + "MEDIUM", + "HIGH", + "VERY_HIGH" + ], + "value": "VERY_LOW", + "format": { + "formatType": "ENUM" }, - "AE3": { - "range": [ - "TRUE", - "FALSE" - ], - "value": "FALSE", - "format": { - "formatType": "ENUM" - }, - "editable": false, - "mandatory": false - } + "editable": false, + "mandatory": false + }, + "AE3": { + "range": [ + "TRUE", + "FALSE" + ], + "value": "FALSE", + "format": { + "formatType": "ENUM" + }, + "editable": false, + "mandatory": false } } \ No newline at end of file diff --git a/avek-gui/src/main/resources/files/subjectFile.json b/avek-gui/src/main/resources/files/subjectFile.json index 5b9d75d..adb640b 100644 --- a/avek-gui/src/main/resources/files/subjectFile.json +++ b/avek-gui/src/main/resources/files/subjectFile.json @@ -41,7 +41,7 @@ "label": "Pathology" }, { - "value": "Jul 12, 2016 5:03:13 PM", + "value": "Jul 27, 2016 11:22:00 AM", "format": { "formatType": "DATE" }, diff --git a/avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml b/avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml index 6e22803..a0fe4eb 100644 --- a/avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml +++ b/avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml @@ -1,11 +1,11 @@ - - - - + + + +
diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/TestMain.java b/avek-gui/src/test/java/fr/axonic/avek/gui/TestMain.java new file mode 100644 index 0000000..b0d6abd --- /dev/null +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/TestMain.java @@ -0,0 +1,54 @@ +package fr.axonic.avek.gui; + +import fr.axonic.avek.gui.util.ConcurrentTaskManager; +import fr.axonic.avek.gui.util.Util; +import fr.axonic.avek.gui.util.UtilForTests; +import fr.axonic.avek.gui.view.EstablishEffectView; +import fr.axonic.avek.gui.view.GeneralizedView; +import fr.axonic.avek.gui.view.TreatView; +import javafx.stage.Stage; +import org.junit.Test; +import org.testfx.framework.junit.ApplicationTest; + +import static org.junit.Assert.assertTrue; + +/** + * Created by Nathaël N on 27/07/16. + */ +public class TestMain extends ApplicationTest { + static { UtilForTests.disableGraphics(); } + + private Main reference; + + @Override + public void start(Stage stage) throws Exception { + this.reference = new Main(); + reference.start(stage); + } + + @Test + public void mainTest() { + ConcurrentTaskManager ctm = new ConcurrentTaskManager(); + + GeneralizedView gView = new GeneralizedView(); + ctm.runLaterOnPlatform(() -> reference.getMainFrame().setView(gView)); + ctm.runLaterOnPlatform(() -> gView.setMonitoredSystem(Util.getFileContent("files/subjectFile.json"))); + ctm.runLaterOnPlatform(() -> gView.setExperimentParameters(Util.getFileContent("files/parametersFile.json"))); + ctm.waitForTasks(); + assertTrue(true); + + EstablishEffectView eeView = new EstablishEffectView(); + ctm.runLaterOnPlatform(() -> reference.getMainFrame().setView(eeView)); + ctm.runLaterOnPlatform(() -> eeView.setMonitoredSystem(Util.getFileContent("files/subjectFile.json"))); + ctm.runLaterOnPlatform(() -> eeView.setExperimentParameters(Util.getFileContent("files/parametersFile.json"))); + ctm.waitForTasks(); + assertTrue(true); + + TreatView tView = new TreatView(); + ctm.runLaterOnPlatform(() -> reference.getMainFrame().setView(tView)); + ctm.runLaterOnPlatform(() -> tView.setMonitoredSystem(Util.getFileContent("files/subjectFile.json"))); + ctm.runLaterOnPlatform(() -> tView.setExperimentParameters(Util.getFileContent("files/parametersFile.json"))); + ctm.waitForTasks(); + assertTrue(true); + } +} diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestFileList.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestFileList.java index 5e207e9..61c3de3 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestFileList.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestFileList.java @@ -1,8 +1,7 @@ package fr.axonic.avek.gui.components.parameters; import fr.axonic.avek.gui.components.filelist.FileListView; -import fr.axonic.avek.gui.util.Util; -import fr.axonic.avek.gui.view.Utils; +import fr.axonic.avek.gui.util.UtilForTests; import javafx.scene.Scene; import javafx.stage.Stage; import org.apache.log4j.Logger; @@ -25,7 +24,7 @@ public class TestFileList extends ApplicationTest { private final static Logger logger = Logger.getLogger(TestFileList.class); - static { Util.disableGraphics(); } + static { UtilForTests.disableGraphics(); } private FileListView flv; @@ -40,11 +39,11 @@ public void start(Stage stage) throws Exception { @Before public void before() throws IOException { - Utils.createFileArchi(); + UtilForTests.createFileArchi(); } @After public void after() { - Utils.deleteFileArchi(); + UtilForTests.deleteFileArchi(); } @Test diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestGeneralizedParametersPane.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestGeneralizedParametersPane.java index 8bb0fd6..fcd1153 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestGeneralizedParametersPane.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestGeneralizedParametersPane.java @@ -1,7 +1,7 @@ package fr.axonic.avek.gui.components.parameters; import fr.axonic.avek.gui.util.ConcurrentTaskManager; -import fr.axonic.avek.gui.util.Util; +import fr.axonic.avek.gui.util.UtilForTests; import javafx.scene.Scene; import javafx.stage.Stage; import org.junit.Test; @@ -16,7 +16,7 @@ * Created by Nathaël N on 25/07/16. */ public class TestGeneralizedParametersPane extends ApplicationTest { - static { Util.disableGraphics(); } + static { UtilForTests.disableGraphics(); } private GeneralizedParametersPane pp; diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestParametersCategory.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestParametersCategory.java index b5beb8a..43a6a7f 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestParametersCategory.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestParametersCategory.java @@ -3,7 +3,7 @@ import fr.axonic.avek.gui.components.parameters.list.ParametersGroup; import fr.axonic.avek.gui.components.parameters.list.ParametersRoot; import fr.axonic.avek.gui.util.ConcurrentTaskManager; -import fr.axonic.avek.gui.util.Util; +import fr.axonic.avek.gui.util.UtilForTests; import fr.axonic.avek.model.base.ABoolean; import fr.axonic.avek.model.base.ADate; import fr.axonic.avek.model.base.ANumber; @@ -23,7 +23,7 @@ * Created by Nathaël N on 11/07/16. */ public class TestParametersCategory extends ApplicationTest { - static { Util.disableGraphics(); } + static { UtilForTests.disableGraphics(); } private ParametersGroup pp; diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeanSelector.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeanSelector.java index 365d5d2..e6511e3 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeanSelector.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeanSelector.java @@ -2,8 +2,8 @@ import com.google.gson.Gson; import fr.axonic.avek.gui.model.sample.ExampleState; -import fr.axonic.avek.gui.model.structure.ExpEffect; -import fr.axonic.avek.gui.util.Util; +import fr.axonic.avek.gui.model.structure.ExperimentationResult; +import fr.axonic.avek.gui.util.UtilForTests; import fr.axonic.avek.model.base.ARangedEnum; import fr.axonic.avek.model.verification.exception.VerificationException; import javafx.collections.FXCollections; @@ -28,7 +28,7 @@ * Created by Nathaël N on 04/07/16. */ public class TestJellyBeanSelector extends ApplicationTest { - static { Util.disableGraphics(); } + static { UtilForTests.disableGraphics(); } private Pane jellyBeanPane; @@ -40,7 +40,7 @@ public void start(Stage stage) throws VerificationException, IOException { stage.setScene(scene); stage.show(); - List expEffects = new ArrayList<>(); + List experimentationResults = new ArrayList<>(); for (int i = 1; i <= 30; i++) { String s; { @@ -52,11 +52,11 @@ public void start(Stage stage) throws VerificationException, IOException { } ARangedEnum be = new Gson().fromJson(s, ARangedEnum.class); - expEffects.add(new ExpEffect("AE" + i, be)); + experimentationResults.add(new ExperimentationResult("AE" + i, be)); } // Fill experiment sample list - jbs.setJellyBeansChoice(FXCollections.observableArrayList(expEffects)); + jbs.setJellyBeansChoice(FXCollections.observableArrayList(experimentationResults)); jellyBeanPane = (Pane) jbs.getChildren().get(1); } diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeans.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeans.java index ea1a740..4653c1f 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeans.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeans.java @@ -1,7 +1,7 @@ package fr.axonic.avek.gui.components.results; import fr.axonic.avek.gui.model.sample.ExampleState; -import fr.axonic.avek.gui.util.Util; +import fr.axonic.avek.gui.util.UtilForTests; import fr.axonic.avek.model.base.ARangedEnum; import fr.axonic.avek.model.verification.exception.VerificationException; import javafx.scene.Scene; @@ -21,7 +21,7 @@ * Created by Nathaël N on 07/07/16. */ public class TestJellyBeans extends ApplicationTest { - static { Util.disableGraphics(); } + static { UtilForTests.disableGraphics(); } private JellyBean jb; private Button jbText; diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/subjects/TestSubjectData.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/subjects/TestSubjectData.java index f590828..a37b8ff 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/subjects/TestSubjectData.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/subjects/TestSubjectData.java @@ -2,7 +2,7 @@ import fr.axonic.avek.gui.components.MonitoredSystemPane; import fr.axonic.avek.gui.util.ConcurrentTaskManager; -import fr.axonic.avek.gui.util.Util; +import fr.axonic.avek.gui.util.UtilForTests; import fr.axonic.avek.model.MonitoredSystem; import fr.axonic.avek.model.base.ADate; import fr.axonic.avek.model.base.ANumber; @@ -27,7 +27,7 @@ * Created by Nathaël N on 08/07/16. */ public class TestSubjectData extends ApplicationTest { - static { Util.disableGraphics(); } + static { UtilForTests.disableGraphics(); } private MonitoredSystemPane monitoredSystemPane; private Accordion acc; @@ -45,19 +45,18 @@ public void start(Stage stage) throws IOException { @Test public void testMonitoredSystem() throws ExecutionException, InterruptedException { ConcurrentTaskManager ctm = new ConcurrentTaskManager(); - - MonitoredSystem ms = new MonitoredSystem(42); - ms.addCategory("Category 1"); - ms.addAVar("Category 1", new AString("a string", "strval1")); - ms.addAVar("Category 1", new ANumber("an integer", 123456789)); - ms.addAVar("Category 1", new ANumber("a double", 12345.6789)); - ms.addAVar("Category 1", new ADate("a date", Calendar.getInstance().getTime())); - - ms.addCategory("Category 2"); - ms.addAVar("Category 2", new ANumber("an integer", 987654321)); - ms.addAVar("Category 2", new ANumber("a double", 98765.4321)); - - monitoredSystemPane.setMonitoredSystem(ms); + MonitoredSystem ms1 = new MonitoredSystem(42); + ms1.addCategory("Category 1"); + ms1.addAVar("Category 1", new AString("a string", "strval1")); + ms1.addAVar("Category 1", new ANumber("an integer", 123456789)); + ms1.addAVar("Category 1", new ANumber("a double", 12345.6789)); + ms1.addAVar("Category 1", new ADate("a date", Calendar.getInstance().getTime())); + + ms1.addCategory("Category 2"); + ms1.addAVar("Category 2", new ANumber("an integer", 987654321)); + ms1.addAVar("Category 2", new ANumber("a double", 98765.4321)); + + ctm.runNowOnPlatform(() -> monitoredSystemPane.setMonitoredSystem(ms1)); assertEquals(2, acc.getPanes().size()); TitledPane tp = acc.getPanes().get(0); @@ -70,20 +69,20 @@ public void testMonitoredSystem() throws ExecutionException, InterruptedExceptio vb = (VBox) sp.getContent(); assertEquals(2, vb.getChildren().size()); - ms = new MonitoredSystem(21); - ms.addCategory("Category 1"); - ms.addAVar("Category 1", new AString("a string", "strval1")); - ms.addAVar("Category 1", new ANumber("an integer", 123456789)); - ms.addAVar("Category 1", new ADate("a date", Calendar.getInstance().getTime())); + MonitoredSystem ms2 = new MonitoredSystem(21); + ms2.addCategory("Category 1"); + ms2.addAVar("Category 1", new AString("a string", "strval1")); + ms2.addAVar("Category 1", new ANumber("an integer", 123456789)); + ms2.addAVar("Category 1", new ADate("a date", Calendar.getInstance().getTime())); - ms.addCategory("Category 2"); - ms.addAVar("Category 2", new ANumber("an integer", 987654321)); - ms.addAVar("Category 2", new ANumber("a double", 12345.6789)); - ms.addAVar("Category 2", new ANumber("a double", 98765.4321)); + ms2.addCategory("Category 2"); + ms2.addAVar("Category 2", new ANumber("an integer", 987654321)); + ms2.addAVar("Category 2", new ANumber("a double", 12345.6789)); + ms2.addAVar("Category 2", new ANumber("a double", 98765.4321)); - ms.addCategory("Category 3"); + ms2.addCategory("Category 3"); - monitoredSystemPane.setMonitoredSystem(ms); + ctm.runNowOnPlatform(() -> monitoredSystemPane.setMonitoredSystem(ms2)); assertEquals(3, acc.getPanes().size()); tp = acc.getPanes().get(0); diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/view/model/json/TestJsonifier.java b/avek-gui/src/test/java/fr/axonic/avek/gui/model/json/TestJsonifier.java similarity index 64% rename from avek-gui/src/test/java/fr/axonic/avek/gui/view/model/json/TestJsonifier.java rename to avek-gui/src/test/java/fr/axonic/avek/gui/model/json/TestJsonifier.java index 3f8905a..9d9b596 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/view/model/json/TestJsonifier.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/model/json/TestJsonifier.java @@ -1,15 +1,16 @@ -package fr.axonic.avek.gui.view.model.json; +package fr.axonic.avek.gui.model.json; -import fr.axonic.avek.gui.model.json.Jsonifier; import fr.axonic.avek.gui.model.sample.ExampleState; import fr.axonic.avek.gui.model.sample.ExampleStateBool; import fr.axonic.avek.model.MonitoredSystem; -import fr.axonic.avek.model.base.ANumber; -import fr.axonic.avek.model.base.ARangedEnum; -import fr.axonic.avek.model.base.AString; +import fr.axonic.avek.model.base.*; +import fr.axonic.avek.model.base.engine.AEntity; +import fr.axonic.avek.model.base.engine.AList; +import fr.axonic.avek.model.base.engine.AVar; import org.junit.Test; import java.util.ArrayList; +import java.util.Date; import static org.junit.Assert.assertEquals; @@ -61,6 +62,38 @@ public void testObjects() { test2(ms, MonitoredSystem.class); } + @Test + public void testAListOfAEntities() { + AList aList = new AList<>(); + + aList.addEntity(new ANumber("Frequency", 42.0)); + aList.addEntity(new ABoolean("Bool?", true)); + + AList list = new AList<>(); + list.setLabel("List"); + list.addEntity(new ANumber("SubNumber", 12.34)); + list.addEntity(new ADate("SubDate", new Date())); + + AList subList = new AList<>(); + subList.setLabel("SubList"); + subList.addEntity(new ANumber("SubSubInteger", 42.0)); + subList.addEntity(new AString("SubSubString", "TheSubSubStringValue")); + subList.addEntity(new ANumber("SubSubDouble", 49.3)); + + list.addEntity(subList); + list.addEntity(new ABoolean("SubBool", false)); + list.setLabel("SubCategory"); + aList.addEntity(list); + + aList.addEntity(new ANumber("Times redo", 12.0)); + + String json = Jsonifier.toJson(aList); + AList regenerated = Jsonifier.toAListofAListAndAVar(json); + + assertEquals(json, Jsonifier.toJson(regenerated)); + } + + private void test(T o, Class tClass) { T o2 = new Jsonifier<>(tClass).fromJson(Jsonifier.toJson(o)); assertEquals(o, o2); diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/view/model/structure/TestUploadedFile.java b/avek-gui/src/test/java/fr/axonic/avek/gui/model/structure/TestUploadedFile.java similarity index 93% rename from avek-gui/src/test/java/fr/axonic/avek/gui/view/model/structure/TestUploadedFile.java rename to avek-gui/src/test/java/fr/axonic/avek/gui/model/structure/TestUploadedFile.java index c3c40be..c0e5cea 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/view/model/structure/TestUploadedFile.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/model/structure/TestUploadedFile.java @@ -1,9 +1,7 @@ -package fr.axonic.avek.gui.view.model.structure; +package fr.axonic.avek.gui.model.structure; import com.sun.javafx.application.PlatformImpl; -import fr.axonic.avek.gui.model.structure.UploadedFile; -import fr.axonic.avek.gui.util.Util; -import fr.axonic.avek.gui.view.Utils; +import fr.axonic.avek.gui.util.UtilForTests; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -27,12 +25,12 @@ public class TestUploadedFile { static { PlatformImpl.startup(() -> {}); - Util.disableGraphics(); + UtilForTests.disableGraphics(); } @Before public void before() throws IOException { - Utils.createFileArchi(); + UtilForTests.createFileArchi(); } @Test @@ -163,6 +161,6 @@ private boolean waitingForUpload(UploadedFile uf1) throws FileAlreadyExistsExcep @After public void after() { - Utils.deleteFileArchi(); + UtilForTests.deleteFileArchi(); } } diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/view/Utils.java b/avek-gui/src/test/java/fr/axonic/avek/gui/util/UtilForTests.java similarity index 80% rename from avek-gui/src/test/java/fr/axonic/avek/gui/view/Utils.java rename to avek-gui/src/test/java/fr/axonic/avek/gui/util/UtilForTests.java index 4abd515..a3e54e0 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/view/Utils.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/util/UtilForTests.java @@ -1,4 +1,4 @@ -package fr.axonic.avek.gui.view; +package fr.axonic.avek.gui.util; import fr.axonic.avek.gui.model.structure.UploadedFile; @@ -10,7 +10,7 @@ /** * Created by Nathaël N on 25/07/16. */ -public class Utils { +public class UtilForTests { private static void delete(File f) throws FileNotFoundException { if (f.isDirectory()) for (File c : f.listFiles()) @@ -55,4 +55,12 @@ public static void createFileArchi() throws IOException { writer.println("TONTon TONTOn TONTON"); writer.close(); } + + public static void disableGraphics() { + System.setProperty("testfx.robot", "glass"); + System.setProperty("prism.order", "sw"); + System.setProperty("testfx.headless", "true"); + System.setProperty("java.awt.headless", "true"); + System.setProperty("prism.text", "t2k"); + } } diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/view/TestMainController.java b/avek-gui/src/test/java/fr/axonic/avek/gui/view/TestMainController.java deleted file mode 100644 index cbc1cce..0000000 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/view/TestMainController.java +++ /dev/null @@ -1,39 +0,0 @@ -package fr.axonic.avek.gui.view; - -import fr.axonic.avek.gui.components.MonitoredSystemPane; -import fr.axonic.avek.gui.util.Util; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.layout.BorderPane; -import javafx.stage.Stage; -import org.junit.Test; -import org.testfx.framework.junit.ApplicationTest; - -import java.io.IOException; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Nathaël N on 08/07/16. - */ -public class TestMainController extends ApplicationTest { - static { Util.disableGraphics(); } - - private Parent root; - - @Override - public void start(Stage stage) throws IOException { - root = new GeneralizedView(); - Scene scene = new Scene(root, 200, 200); - stage.setScene(scene); - stage.show(); - } - - @Test - public void testChildren() { - assertEquals(2, root.getChildrenUnmodifiable().size()); - - assertEquals(MonitoredSystemPane.class, ((BorderPane) root).getLeft().getClass()); - assertEquals(BorderPane.class, ((BorderPane) root).getCenter().getClass()); - } -}