From 8cc651fbd2f626fe452fa346b2070451155b7160 Mon Sep 17 00:00:00 2001 From: tfli <tfli@d-velop.de> Date: Mon, 22 Nov 2021 18:59:29 +0100 Subject: [PATCH] Added data dependencies of flow to dsl --- .../rest/service/change/ChangeController.java | 9 +- .../rest/service/test/TestService.java | 108 ++++++++++-------- 2 files changed, 67 insertions(+), 50 deletions(-) diff --git a/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/rest/service/change/ChangeController.java b/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/rest/service/change/ChangeController.java index 029611d..2794b98 100644 --- a/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/rest/service/change/ChangeController.java +++ b/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/rest/service/change/ChangeController.java @@ -119,6 +119,10 @@ public class ChangeController { */ List<Flow> flows = oldDSL.getFlows(); + MigrationResultWrapper migrationResultWrapper = migrationService.detectChanges(oldDSL, newDSL); + + migrationResultWrapperDTO = migrationService.convertMigrationResultWrapper(migrationResultWrapper); + for(Flow flow : flows) { List<Test> oldTests = oldDSL.getTestsForFlow(flow); @@ -128,11 +132,6 @@ public class ChangeController { } } - MigrationResultWrapper migrationResultWrapper = migrationService.detectChanges(oldDSL, newDSL); - - migrationResultWrapperDTO = migrationService.convertMigrationResultWrapper(migrationResultWrapper); - - return migrationResultWrapperDTO; } catch (IOException e) { diff --git a/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/rest/service/test/TestService.java b/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/rest/service/test/TestService.java index da57802..929bbb2 100644 --- a/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/rest/service/test/TestService.java +++ b/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/rest/service/test/TestService.java @@ -59,6 +59,7 @@ import de.fhmuenster.masterthesis.testgeneratorDSL.BPMNDiagram; import de.fhmuenster.masterthesis.testgeneratorDSL.ExternalTopic; import de.fhmuenster.masterthesis.testgeneratorDSL.Flow; import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElement; +import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElementReference; import de.fhmuenster.masterthesis.testgeneratorDSL.Mock; import de.fhmuenster.masterthesis.testgeneratorDSL.Test; import de.fhmuenster.masterthesis.testgeneratorDSL.Variable; @@ -74,6 +75,8 @@ public class TestService { private long millisDataStart; private long millisDataEnd; + private List<String> taskIds = new ArrayList<String>(); + @Autowired private FlowService flowService; @Autowired @@ -139,7 +142,7 @@ public class TestService { BPMNDiagram bpmnDiagram = serializer.getBPMNDiagram("process"); List<FlowElement> flowElementsCheck = serializer.getFlowElements(); - + if (bpmnDiagram != null && flowElementsCheck.isEmpty()) { BPMNBundle bpmnBundle = BPMNParseUtils.readBPMNBundle(project); List<DMNBundle> dmnBundles = BPMNParseUtils.readDMNBundles(project); @@ -197,7 +200,7 @@ public class TestService { variables.forEach(var -> serializer.addVariable(var)); externalTopics.forEach(externalTopic -> serializer.addExternalTopic(externalTopic)); flows.forEach(flow -> serializer.addFlow(flow)); - + setDataDependencies(flows, bpmnIOParameters); serializer.serialize(); } @@ -205,6 +208,25 @@ public class TestService { e.printStackTrace(); } } + + public void setDataDependencies(List<Flow> flows, BPMNIOParameters bpmnIOParams) { + for(Flow f: flows) { + int dependencies = 0; + List<FlowElementReference> fer = f.getInclElements(); + for(FlowElementReference flowElementReference: fer) { + FlowElement flowElement = flowElementReference.getRef(); + int inputVariableSize = bpmnIOParams.getInputVariables(flowElement.getName()).size(); + int outputVariableSize = bpmnIOParams.getOutputVariables(flowElement.getName()).size(); + if(inputVariableSize != 0) { + dependencies += inputVariableSize; + } + if(outputVariableSize != 0) { + dependencies += outputVariableSize; + } + } + f.setDependency(dependencies); + } + } public void addTest(BPMNTestcase testcase, ProjectDirectories projectDirectories) { Path testspecificationPath = ProjectDirectoryUtils.getTestspecificationPath(projectDirectories); @@ -215,7 +237,6 @@ public class TestService { checkTestIdAlreadyTaken(testcase.getName(), serializer); addTest(testcase, serializer, projectDirectories); - serializer.serialize(); } catch (IOException e) { e.printStackTrace(); @@ -231,10 +252,9 @@ public class TestService { if (!testId.equals(testcase.getName())) { checkTestIdAlreadyTaken(testcase.getName(), serializer); } - + Test testToDelete = getTest(testId, serializer); serializer.deleteTest(testToDelete.getName()); - addTest(testcase, serializer, projectDirectories); serializer.serialize(); @@ -246,10 +266,11 @@ public class TestService { private void addTest(BPMNTestcase testcase, TestgeneratorDSLSerializer serializer, ProjectDirectories projectDirectories) { Flow flow = serializer.getFlow(testcase.getFlow()); + List<FlowElement> flowElements = serializer.getFlowElements(); List<Variable> variables = serializer.getVariables(); List<Mock> mocks = mockService.getMocks(testcase.getMocks(), projectDirectories); - + Test newTest = TestConverter.getTest(testcase, flow, flowElements, variables, mocks); serializer.addTest(newTest); } @@ -350,48 +371,36 @@ public class TestService { private FlowElement getFlowElement(org.camunda.bpm.model.bpmn.instance.FlowElement flowElement, List<Variable> variables, BPMNFormFields formFields, BPMNExpressions expressions, BPMNIOParameters bpmnIOParameters, List<ExternalTopic> externalTopics) { - if (flowElement instanceof StartEvent) { List<Variable> startVariables = filterFlowElementVariables(variables, formFields.getVariablesForTask(flowElement.getId())); + + int dependencies = startVariables.size(); return TestgeneratorDSLObjectCreator.createStartFlowElement(flowElement.getId(), startVariables); } else if (flowElement instanceof EndEvent) { return TestgeneratorDSLObjectCreator.createEndFlowElement(flowElement.getId()); } else if (flowElement instanceof Gateway) { return TestgeneratorDSLObjectCreator.createGatewayFlowElement(flowElement.getId()); } else if (flowElement instanceof UserTask) { - List<String> inputVariableNames = new ArrayList<>(); - inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElement.getId())); - List<String> outputVariableNames = new ArrayList<>(); - outputVariableNames.addAll(bpmnIOParameters.getOutputVariables(flowElement.getId())); - List<Variable> inputVariables = filterFlowElementVariables(variables, inputVariableNames); - List<Variable> outputVariables = filterFlowElementVariables(variables, outputVariableNames); - + List<Variable> inputVariables = getInputVariables(flowElement.getId(), bpmnIOParameters, variables); + List<Variable> outputVariables = getOutputVariables(flowElement.getId(), bpmnIOParameters, variables); + int dependencies = inputVariables.size() + outputVariables.size(); return TestgeneratorDSLObjectCreator.createUserTaskFlowElement(flowElement.getId(), inputVariables, outputVariables, flowElement.getName()); } else if (flowElement instanceof ManualTask) { - List<String> inputVariableNames = new ArrayList<>(); - inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElement.getId())); - List<String> outputVariableNames = new ArrayList<>(); - outputVariableNames.addAll(bpmnIOParameters.getOutputVariables(flowElement.getId())); - List<Variable> inputVariables = filterFlowElementVariables(variables, inputVariableNames); - List<Variable> outputVariables = filterFlowElementVariables(variables, outputVariableNames); + List<Variable> inputVariables = getInputVariables(flowElement.getId(), bpmnIOParameters, variables); + List<Variable> outputVariables = getOutputVariables(flowElement.getId(), bpmnIOParameters, variables); + int dependencies = inputVariables.size() + outputVariables.size(); return TestgeneratorDSLObjectCreator.createManualTaskFlowElement(flowElement.getId(), inputVariables, outputVariables, flowElement.getName()); } else if (flowElement instanceof ScriptTask) { - List<String> inputVariableNames = new ArrayList<>(); - inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElement.getId())); - List<String> outputVariableNames = new ArrayList<>(); - outputVariableNames.addAll(bpmnIOParameters.getOutputVariables(flowElement.getId())); - List<Variable> inputVariables = filterFlowElementVariables(variables, inputVariableNames); - List<Variable> outputVariables = filterFlowElementVariables(variables, outputVariableNames); + List<Variable> inputVariables = getInputVariables(flowElement.getId(), bpmnIOParameters, variables); + List<Variable> outputVariables = getOutputVariables(flowElement.getId(), bpmnIOParameters, variables); + int dependencies = inputVariables.size() + outputVariables.size(); return TestgeneratorDSLObjectCreator.createScriptTaskFlowElement(flowElement.getId(), inputVariables, outputVariables, flowElement.getName()); } else if (flowElement instanceof BusinessRuleTask) { String resultVariable = BPMNParseUtils.getResultVariable((BusinessRuleTask) flowElement); - List<String> inputVariableNames = new ArrayList<>(); - inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElement.getId())); - List<String> outputVariableNames = new ArrayList<>(); - outputVariableNames.addAll(bpmnIOParameters.getOutputVariables(flowElement.getId())); - List<Variable> inputVariables = filterFlowElementVariables(variables, inputVariableNames); - List<Variable> outputVariables = filterFlowElementVariables(variables, outputVariableNames); + List<Variable> inputVariables = getInputVariables(flowElement.getId(), bpmnIOParameters, variables); + List<Variable> outputVariables = getOutputVariables(flowElement.getId(), bpmnIOParameters, variables); + int dependencies = inputVariables.size() + outputVariables.size(); return TestgeneratorDSLObjectCreator.createBusinessRuleTaskFlowElement(flowElement.getId(), resultVariable, inputVariables, outputVariables, flowElement.getName()); } else if (flowElement instanceof ServiceTask) { @@ -400,23 +409,17 @@ public class TestService { ExternalTopic externalTopic = getExternalTopic(externalTopics, externalTopicTextual); if (delegate != null) { - List<String> inputVariableNames = new ArrayList<>(); - inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElement.getId())); - List<String> outputVariableNames = new ArrayList<>(); - outputVariableNames.addAll(bpmnIOParameters.getOutputVariables(flowElement.getId())); - List<Variable> inputVariables = filterFlowElementVariables(variables, inputVariableNames); - List<Variable> outputVariables = filterFlowElementVariables(variables, outputVariableNames); + List<Variable> inputVariables = getInputVariables(flowElement.getId(), bpmnIOParameters, variables); + List<Variable> outputVariables = getOutputVariables(flowElement.getId(), bpmnIOParameters, variables); + int dependencies = inputVariables.size() + outputVariables.size(); return TestgeneratorDSLObjectCreator.createDelegateServiceTaskFlowElement(flowElement.getId(), delegate, inputVariables, outputVariables, flowElement.getName()); } else if (externalTopic != null) { List<VariableDeclaration> hardcodedVariables = BPMNParseUtils.getHardcodedVariables(flowElement.getId(), variables, bpmnIOParameters); - List<String> inputVariableNames = new ArrayList<>(); - inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElement.getId())); - List<String> outputVariableNames = new ArrayList<>(); - outputVariableNames.addAll(bpmnIOParameters.getOutputVariables(flowElement.getId())); - List<Variable> inputVariables = filterFlowElementVariables(variables, inputVariableNames); - List<Variable> outputVariables = filterFlowElementVariables(variables, outputVariableNames); + List<Variable> inputVariables = getInputVariables(flowElement.getId(), bpmnIOParameters, variables); + List<Variable> outputVariables = getOutputVariables(flowElement.getId(), bpmnIOParameters, variables); + int dependencies = inputVariables.size() + outputVariables.size(); return TestgeneratorDSLObjectCreator.createExternalServiceTaskFlowElement(flowElement.getId(), externalTopic, hardcodedVariables, flowElement.getName(), inputVariables, outputVariables); } else { @@ -428,9 +431,24 @@ public class TestService { } + throw new UnsupportedFlowElementException(flowElement.getId()); } - + + private List<Variable> getInputVariables(String flowElementId, BPMNIOParameters bpmnIOParameters, List<Variable> variables) { + List<String> inputVariableNames = new ArrayList<>(); + inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElementId)); + List<Variable> inputVariables = filterFlowElementVariables(variables, inputVariableNames); + return inputVariables; + } + + private List<Variable> getOutputVariables(String flowElementId, BPMNIOParameters bpmnIOParameters, List<Variable> variables) { + List<String> outputVariableNames = new ArrayList<>(); + outputVariableNames.addAll(bpmnIOParameters.getOutputVariables(flowElementId)); + List<Variable> outputVariables = filterFlowElementVariables(variables, outputVariableNames); + return outputVariables; + } + private List<Flow> getFlows(BPMNDiagram bpmn, BPMNFlowSet flowSet, List<FlowElement> flowElements) { return flowSet.getFlows().stream() // .map(flow -> createFlow(bpmn, flow, flowElements)) // -- GitLab