Skip to content

Commit

Permalink
Merge pull request #562 from IPVS-AS/TestTool_BugFixes
Browse files Browse the repository at this point in the history
Test tool bug fixes
  • Loading branch information
hirmerpl authored Mar 18, 2021
2 parents 53760cc + d497887 commit 4e84579
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/ipvs/as/mbp/DefaultEntitiesConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ public List<String> 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<String> defaultRerunOperatorWhitelist() {
List<String> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -112,6 +105,15 @@ public TestReport() throws IOException {
* @return path where the TestReport can be found
*/
public String generateTestReport(String testId, List<Rule> 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
Expand Down Expand Up @@ -148,14 +150,14 @@ public String generateTestReport(String testId, List<Rule> 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
Expand Down Expand Up @@ -185,11 +187,11 @@ public String generateTestReport(String testId, List<Rule> 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;
}
}
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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()) {

Expand Down Expand Up @@ -401,7 +403,7 @@ private Map<String, String> 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 = "";
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class TestRerunOperatorService {
private ServletContext servletContext;

@Autowired
private List<String> rerunOperatorWhitelist;
private List<String> defaultRerunOperatorWhitelist;

@Autowired
private OperatorRepository operatorRepository;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public TestRerunService() throws IOException {
* @param useNewData information if a test should be repeated
* @return the updated configuration list
*/
public List<List<ParameterInstance>> editUseNewData(String testId, String useNewData) {
public List<List<ParameterInstance>> editUseNewData(String testId, boolean useNewData) {
TestDetails testDetails = testDetailsRepository.findById(testId).get();
List<List<ParameterInstance>> configList = testDetails.getConfig();


if (!Boolean.parseBoolean(useNewData)) {
if (!useNewData) {
testDetails.setUseNewData(false);

} else {
Expand All @@ -112,13 +112,13 @@ public List<List<ParameterInstance>> editUseNewData(String testId, String useNew
for (List<ParameterInstance> 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -260,15 +260,15 @@ 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());
rerunRule.setOwner(null);
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());
Expand Down Expand Up @@ -347,7 +347,7 @@ public void deleteRerunRules(TestDetails test) {
public ResponseEntity<String> addRerunOperators() {
ResponseEntity<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public ResponseEntity<Boolean> deleteTestReport(@PathVariable(value = "testId")
*/
@PostMapping(value = "/editConfig/{testId}")
public ResponseEntity<List<List<ParameterInstance>>> editConfig(@PathVariable(value = "testId") String testId,
@RequestBody String useNewData) {
@RequestBody boolean useNewData) {
List<List<ParameterInstance>> configList = testRerunService.editUseNewData(testId, useNewData);
return new ResponseEntity<>(configList, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/js/services/TestService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
5 changes: 3 additions & 2 deletions src/main/webapp/WEB-INF/views/templates/testing-tool.html
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ <h5 class="modal-title">Register the Components for the Test of your IoT-Applica
</div>
</div>
</td>
</tr>
<tr>
<td>Temperature Sensor (Planned)</td>
<td> Sensor Simulator that simulates sensor data of a temperature sensor,
Expand Down Expand Up @@ -1314,6 +1315,7 @@ <h5 class="modal-title">Register the Components for the Test of your IoT-Applica
</div>
</td>
</tr>
<!--
<tr>
<td>GPS Sensor</td>
<td>Sensor Simulator that simulates sensor data of a GPS sensor. The
Expand Down Expand Up @@ -1489,8 +1491,7 @@ <h5 class="modal-title">Register the Components for the Test of your IoT-Applica
</div>
</td>
</tr>

</tr>
-->
</tbody>
</table>

Expand Down

0 comments on commit 4e84579

Please sign in to comment.