From b849b67925f38e21d55d71923203b446d3aaaff0 Mon Sep 17 00:00:00 2001 From: Katja Date: Wed, 17 Mar 2021 10:05:02 +0100 Subject: [PATCH 1/3] Fix Rerun Test --- .../simulators/rerun_adapter/operator.json | 2 +- .../as/mbp/DefaultEntitiesConfiguration.java | 12 ++++++++++++ .../testing/rerun/TestRerunOperatorService.java | 4 ++-- .../service/testing/rerun/TestRerunService.java | 16 ++++++++-------- .../as/mbp/web/rest/RestTestingController.java | 2 +- .../resources/static/js/services/TestService.js | 2 +- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/resources/operators/extraction/simulators/rerun_adapter/operator.json b/resources/operators/extraction/simulators/rerun_adapter/operator.json index 1e7e24a8c..356a4df8c 100644 --- a/resources/operators/extraction/simulators/rerun_adapter/operator.json +++ b/resources/operators/extraction/simulators/rerun_adapter/operator.json @@ -1,7 +1,7 @@ { "name": "RERUN_OPERATOR", "description": "Rerun operator simulating the last generated values of a real sensor in a test.", - "unit": "No Unit", + "unit": "°C", "files": [ "rerun.py", "install.sh", diff --git a/src/main/java/de/ipvs/as/mbp/DefaultEntitiesConfiguration.java b/src/main/java/de/ipvs/as/mbp/DefaultEntitiesConfiguration.java index afc63def2..ce3a8f287 100644 --- a/src/main/java/de/ipvs/as/mbp/DefaultEntitiesConfiguration.java +++ b/src/main/java/de/ipvs/as/mbp/DefaultEntitiesConfiguration.java @@ -42,6 +42,18 @@ public List defaultOperatorWhitelist() { return Collections.unmodifiableList(operatorPaths); } + /** + * Creates a bean representing a whitelist of paths to directories of operators that are supposed + * to be available as default operators for test reruns. + * + * @return The path whitelist bean + */ + @Bean(name = "defaultRerunOperatorWhitelist") + public List defaultRerunOperatorWhitelist() { + List operatorPaths = Arrays.asList("/operators/extraction/simulators/rerun_adapter"); + return Collections.unmodifiableList(operatorPaths); + } + /** * Sets up a list of default users and adds them to the user repository if not already existing. * diff --git a/src/main/java/de/ipvs/as/mbp/service/testing/rerun/TestRerunOperatorService.java b/src/main/java/de/ipvs/as/mbp/service/testing/rerun/TestRerunOperatorService.java index b6163041d..29e4c237d 100644 --- a/src/main/java/de/ipvs/as/mbp/service/testing/rerun/TestRerunOperatorService.java +++ b/src/main/java/de/ipvs/as/mbp/service/testing/rerun/TestRerunOperatorService.java @@ -33,7 +33,7 @@ public class TestRerunOperatorService { private ServletContext servletContext; @Autowired - private List rerunOperatorWhitelist; + private List defaultRerunOperatorWhitelist; @Autowired private OperatorRepository operatorRepository; @@ -49,7 +49,7 @@ public ResponseEntity addRerunOperators() { ResponseEntity responseEntity = null; //Iterate over all default operator paths - for (String operatorPath : rerunOperatorWhitelist) { + for (String operatorPath : defaultRerunOperatorWhitelist) { //Create new operator object to add it later to the repository Operator newOperator = new Operator(); diff --git a/src/main/java/de/ipvs/as/mbp/service/testing/rerun/TestRerunService.java b/src/main/java/de/ipvs/as/mbp/service/testing/rerun/TestRerunService.java index eb9021bbc..c0ae89258 100644 --- a/src/main/java/de/ipvs/as/mbp/service/testing/rerun/TestRerunService.java +++ b/src/main/java/de/ipvs/as/mbp/service/testing/rerun/TestRerunService.java @@ -93,12 +93,12 @@ public TestRerunService() throws IOException { * @param useNewData information if a test should be repeated * @return the updated configuration list */ - public List> editUseNewData(String testId, String useNewData) { + public List> editUseNewData(String testId, boolean useNewData) { TestDetails testDetails = testDetailsRepository.findById(testId).get(); List> configList = testDetails.getConfig(); - if (!Boolean.parseBoolean(useNewData)) { + if (!useNewData) { testDetails.setUseNewData(false); } else { @@ -112,13 +112,13 @@ public List> editUseNewData(String testId, String useNew for (List config : configList) { for (ParameterInstance parameterInstance : config) { if (parameterInstance.getName().equals("useNewData")) { - parameterInstance.setValue(Boolean.valueOf(useNewData)); + parameterInstance.setValue(useNewData); } } } testDetails.setConfig(configList); - testDetails.setUseNewData(Boolean.parseBoolean(useNewData)); + testDetails.setUseNewData(useNewData); // save the changes in the database testDetailsRepository.save(testDetails); @@ -207,7 +207,7 @@ public void addRerunSensors(String realSensorName, TestDetails testDetails) { String newSensorName = RERUN_IDENTIFIER + realSensorName; try { - if (sensorRepository.findByName(newSensorName) == null) { + if (!sensorRepository.findByName(newSensorName).isPresent()) { if (rerunOperator != null && testingDevice != null) { // Set all relevant information newSensor.setName(newSensorName); @@ -260,7 +260,7 @@ public void addRerunRule(TestDetails test) { boolean notRegister = false; for (Rule rule : applicationRules) { - if (ruleRepository.findByName(RERUN_IDENTIFIER + rule.getName()) == null) { + if (!ruleRepository.findByName(RERUN_IDENTIFIER + rule.getName()).isPresent()) { // create new rule Rule rerunRule = new Rule(); rerunRule.setName(RERUN_IDENTIFIER + rule.getName()); @@ -268,7 +268,7 @@ public void addRerunRule(TestDetails test) { rerunRule.setActions(rule.getActions()); // create/adjust trigger querey - if (ruleTriggerRepository.findByName(RERUN_IDENTIFIER + rule.getTrigger().getName()) == null) { + if (!ruleTriggerRepository.findByName(RERUN_IDENTIFIER + rule.getTrigger().getName()).isPresent()) { // create new trigger RuleTrigger newTrigger = new RuleTrigger(); newTrigger.setDescription(rule.getTrigger().getDescription()); @@ -347,7 +347,7 @@ public void deleteRerunRules(TestDetails test) { public ResponseEntity addRerunOperators() { ResponseEntity response; try { - if (operatorRepository.findByName(RERUN_OPERATOR) == null) { + if (!operatorRepository.findByName(RERUN_OPERATOR).isPresent()) { //Call corresponding service function rerunOperatorService.addRerunOperators(); response = new ResponseEntity<>("Adapter successfully created", HttpStatus.OK); diff --git a/src/main/java/de/ipvs/as/mbp/web/rest/RestTestingController.java b/src/main/java/de/ipvs/as/mbp/web/rest/RestTestingController.java index f9914e155..4d71e0bff 100644 --- a/src/main/java/de/ipvs/as/mbp/web/rest/RestTestingController.java +++ b/src/main/java/de/ipvs/as/mbp/web/rest/RestTestingController.java @@ -277,7 +277,7 @@ public ResponseEntity deleteTestReport(@PathVariable(value = "testId") */ @PostMapping(value = "/editConfig/{testId}") public ResponseEntity>> editConfig(@PathVariable(value = "testId") String testId, - @RequestBody String useNewData) { + @RequestBody boolean useNewData) { List> configList = testRerunService.editUseNewData(testId, useNewData); return new ResponseEntity<>(configList, HttpStatus.OK); } diff --git a/src/main/resources/static/js/services/TestService.js b/src/main/resources/static/js/services/TestService.js index c6fd9d636..01b8be0cb 100644 --- a/src/main/resources/static/js/services/TestService.js +++ b/src/main/resources/static/js/services/TestService.js @@ -126,7 +126,7 @@ app.factory('TestService', ['HttpService', '$http', '$resource', '$q', 'ENDPOINT * @returns {*} */ function editConfig(testId, useNewData) { - return HttpService.postRequest(ENDPOINT_URI + '/test-details/editConfig/' + testId, useNewData).success(function success(response) { + return HttpService.postRequest(ENDPOINT_URI + '/test-details/editConfig/' + testId, useNewData).then(function success(response) { NotificationService.notify('Successfully updated.', 'success'); return response.success; }); From 610cb050a1b834ace650b4c23fdc8e52abdacf6e Mon Sep 17 00:00:00 2001 From: Katja Date: Wed, 17 Mar 2021 10:47:27 +0100 Subject: [PATCH 2/3] Fix TestReport bug --- .../service/testing/analyzer/TestReport.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/de/ipvs/as/mbp/service/testing/analyzer/TestReport.java b/src/main/java/de/ipvs/as/mbp/service/testing/analyzer/TestReport.java index ef51974c7..597f78fd3 100644 --- a/src/main/java/de/ipvs/as/mbp/service/testing/analyzer/TestReport.java +++ b/src/main/java/de/ipvs/as/mbp/service/testing/analyzer/TestReport.java @@ -96,13 +96,6 @@ public TestReport() throws IOException { final Color darkBlue = new DeviceRgb(0, 191, 255); final Color darkGrey = new DeviceRgb(182, 182, 182); final Color mbpBlue = new DeviceRgb(0, 191, 255); - PdfFont font = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD); - final Style white = new Style().setFont(font).setFontSize(12).setFontColor(ColorConstants.WHITE); - final Style headerFont = new Style().setFont(font).setFontSize(10).setFontColor(mbpBlue); - final Style tableHeader = new Style().setFont(font).setFontSize(12).setFontColor(ColorConstants.BLACK); - final Style pageFont = new Style().setFont(font).setFontSize(22).setFontColor(ColorConstants.BLACK); - final Style titleFont = new Style().setFont(font).setFontSize(22).setFontColor(ColorConstants.BLACK); - final Style boldUnderlined = new Style().setFont(font).setFontSize(17).setFontColor(ColorConstants.BLACK).setUnderline(); /** * Generates the Test-Report with the Chart of the simulated Values and other important information for the user. @@ -112,6 +105,15 @@ public TestReport() throws IOException { * @return path where the TestReport can be found */ public String generateTestReport(String testId, List rulesBefore) throws Exception { + + PdfFont font = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD); + final Style white = new Style().setFont(font).setFontSize(12).setFontColor(ColorConstants.WHITE); + final Style headerFont = new Style().setFont(font).setFontSize(10).setFontColor(mbpBlue); + final Style tableHeader = new Style().setFont(font).setFontSize(12).setFontColor(ColorConstants.BLACK); + final Style pageFont = new Style().setFont(font).setFontSize(22).setFontColor(ColorConstants.BLACK); + final Style titleFont = new Style().setFont(font).setFontSize(22).setFontColor(ColorConstants.BLACK); + final Style boldUnderlined = new Style().setFont(font).setFontSize(17).setFontColor(ColorConstants.BLACK).setUnderline(); + int counterRules = 0; TestDetails test = testDetailsRepository.findById(testId).get(); // Create a new pdf, which is named with the ID of the specific test @@ -148,14 +150,14 @@ public String generateTestReport(String testId, List rulesBefore) throws E com.itextpdf.layout.element.Paragraph subtitle = new com.itextpdf.layout.element.Paragraph().add("Test-Details: ").addStyle(boldUnderlined).setTextAlignment(TextAlignment.CENTER); // Sensor information - Table simulationSensors = getSimulationConfig(test); - Table realSensors = getRealSensorConfig(test); + Table simulationSensors = getSimulationConfig(test, tableHeader, white); + Table realSensors = getRealSensorConfig(test,tableHeader, white); // Actuator information - Table actuatorInfos = getActuatorInfos(); + Table actuatorInfos = getActuatorInfos(white); // Rule information - Table ruleInfos = getRuleInfos(test); + Table ruleInfos = getRuleInfos(test,white); doc.add(new com.itextpdf.layout.element.Paragraph("\n")); // Rule details @@ -185,11 +187,11 @@ public String generateTestReport(String testId, List rulesBefore) throws E // Add new table to get the details for each rule for (Rule rule : rulesBefore) { if (test.isUseNewData()) { - ruleDetails = getRuleDetails(test, rule, counterRules); + ruleDetails = getRuleDetails(test, rule, counterRules,tableHeader); counterRules += 1; } else { if (rule.getName().contains(RERUN_IDENTIFIER)) { - ruleDetails = getRuleDetails(test, rule, counterRules); + ruleDetails = getRuleDetails(test, rule, counterRules,tableHeader); counterRules += 1; } } @@ -250,7 +252,7 @@ private Table getGeneralInfo(TestDetails test) { * @param test test for which the test report is created * @return table with all sensor simulators and the configurations of them **/ - private Table getSimulationConfig(TestDetails test) { + private Table getSimulationConfig(TestDetails test, Style tableHeader, Style white) { boolean sensorSimulation = false; int counter = 0; String rerunInfo = ""; @@ -264,7 +266,7 @@ private Table getSimulationConfig(TestDetails test) { Table tableSensorSim = new Table(4); tableSensorSim.setWidth(UnitValue.createPercentValue(100)); - tableSensorSim.addCell(headerCell("Simulated Sensor(s)")); + tableSensorSim.addCell(headerCell("Simulated Sensor(s)", white)); for (String type : test.getType()) { @@ -401,7 +403,7 @@ private Map plannedSim(TestDetails test, String sensorType) { * @param test test for which the test report is created * @return table with user configurations of the test */ - private Table getRealSensorConfig(TestDetails test) { + private Table getRealSensorConfig(TestDetails test, Style tableHeader, Style white) { int counter = 0; boolean realSensors = false; String rerunInfo = ""; @@ -415,7 +417,7 @@ private Table getRealSensorConfig(TestDetails test) { Table tableRealSensors = new Table(4); tableRealSensors.setWidth(UnitValue.createPercentValue(100)); - tableRealSensors.addCell(headerCell("Real Sensor(s)")); + tableRealSensors.addCell(headerCell("Real Sensor(s)", white)); for (String type : test.getType()) { // Check if sensor is no sensor simulator @@ -458,14 +460,14 @@ private Table getRealSensorConfig(TestDetails test) { * * @return table with the actuator information */ - private Table getActuatorInfos() { + private Table getActuatorInfos(Style white) { String infoText = "The actuator used for the tests does not trigger any actions if the corresponding rule is triggered. It functions as a dummy."; // Table configurations Table actuatorInfo = new Table(4); actuatorInfo.setWidth(UnitValue.createPercentValue(100)); - actuatorInfo.addCell(headerCell("Simulated actuator")); + actuatorInfo.addCell(headerCell("Simulated actuator", white)); actuatorInfo.addCell(tableCell(new com.itextpdf.layout.element.Paragraph(infoText), null, 4)); return actuatorInfo; @@ -479,7 +481,7 @@ private Table getActuatorInfos() { * @param rule detail information of the selected rules before the test * @return PDFTable with all important information about the rules in the test of a specific application */ - private Table getRuleDetails(TestDetails test, Rule rule, int counterRules) { + private Table getRuleDetails(TestDetails test, Rule rule, int counterRules, Style tableHeader) { int executionsAfter; String lastExecutionBefore = "NEVER"; String lastExecutionAfter = "NEVER"; @@ -572,7 +574,7 @@ private Table getRuleDetails(TestDetails test, Rule rule, int counterRules) { * @param test test for which the test report is created * @return table with detailed rule information */ - public Table getRuleInfos(TestDetails test) { + public Table getRuleInfos(TestDetails test, Style white) { StringBuilder rulesUser = new StringBuilder(); String rulesExecuted; String triggerRules; @@ -584,7 +586,7 @@ public Table getRuleInfos(TestDetails test) { ruleInfos.setWidth(UnitValue.createPercentValue(100)); //Set header - ruleInfos.addCell(headerCell("Rule-Information")); + ruleInfos.addCell(headerCell("Rule-Information", white)); // Creates a text depending on whether the rules chosen by the user should be triggered or not if (test.isTriggerRules()) { @@ -805,7 +807,7 @@ public Cell tableCell(com.itextpdf.layout.element.Paragraph phrase, Color backgr * @param phrase of the header * @return PdfPCell as header */ - public Cell headerCell(String phrase) { + public Cell headerCell(String phrase, Style white) { Cell headerCell = new Cell(1, 4).add(new com.itextpdf.layout.element.Paragraph(phrase)).addStyle(white).setTextAlignment(TextAlignment.CENTER); headerCell.setHorizontalAlignment(HorizontalAlignment.CENTER); headerCell.setBackgroundColor(darkGrey); From 19b307a8048b49b3c7ccd0f2eb213eaf8b848767 Mon Sep 17 00:00:00 2001 From: Katja Date: Wed, 17 Mar 2021 11:58:25 +0100 Subject: [PATCH 3/3] Fix User Feedback add simulators --- .../static/js/controllers/testing/TestingController.js | 2 +- src/main/webapp/WEB-INF/views/templates/testing-tool.html | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/resources/static/js/controllers/testing/TestingController.js b/src/main/resources/static/js/controllers/testing/TestingController.js index 4d2abbf80..6a81efe84 100644 --- a/src/main/resources/static/js/controllers/testing/TestingController.js +++ b/src/main/resources/static/js/controllers/testing/TestingController.js @@ -335,7 +335,7 @@ app.controller('TestingController', * Register the one dimensional Sensor-Simulator for the Test of IoT-Applications. */ function registerOneDimSensor(sensor) { - TestService.registerOneDimSensor(sensor).success(function () { + TestService.registerOneDimSensor(sensor).then(function () { //Notify the user NotificationService.notify('Entity successfully created.', 'success') checkSensorReg(sensor); diff --git a/src/main/webapp/WEB-INF/views/templates/testing-tool.html b/src/main/webapp/WEB-INF/views/templates/testing-tool.html index 77a1edb54..1bd4e9691 100644 --- a/src/main/webapp/WEB-INF/views/templates/testing-tool.html +++ b/src/main/webapp/WEB-INF/views/templates/testing-tool.html @@ -1189,6 +1189,7 @@