Skip to content

Commit

Permalink
reapply changes in ActivitiTester for faster SA execution
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgeiger committed Sep 23, 2016
1 parent b4101e0 commit 910eaae
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package betsy.bpmn.engines.activiti;

import betsy.bpmn.engines.BPMNProcessInstanceOutcomeChecker;
import betsy.bpmn.engines.JsonHelper;
import org.json.JSONObject;


public class ActivitiApiBasedProcessOutcomeChecker implements BPMNProcessInstanceOutcomeChecker {

@Override
public ProcessInstanceOutcome checkProcessOutcome(String name) {
return isProcessDeployed(name) ? ProcessInstanceOutcome.OK : ProcessInstanceOutcome.UNDEPLOYED_PROCESS;
}

private boolean isProcessDeployed(String key) {
String checkDeploymentUrl = ActivitiEngine.URL + "/service/repository/deployments?name="+key+".bpmn";

JSONObject result = JsonHelper.get(checkDeploymentUrl, 200);
if(result.getInt("size")!=1) {
return false;
}

return true;
}
}
81 changes: 48 additions & 33 deletions src/main/groovy/betsy/bpmn/engines/activiti/ActivitiTester.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package betsy.bpmn.engines.activiti;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -42,56 +44,69 @@ public void runTest() {

Path logFile = logDir.resolve("activiti.log");

BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeBeforeTest = new ActivitiLogBasedProcessInstanceOutcomeChecker(logFile).checkProcessOutcome(key);
BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeBeforeTest = new ActivitiApiBasedProcessOutcomeChecker().checkProcessOutcome(key);
if (outcomeBeforeTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.UNDEPLOYED_PROCESS) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_DEPLOYMENT);
}

for (TestStep testStep : testCase.getTestSteps()) {
if (testStep instanceof ProcessStartWithVariablesTestStep) {
// skip execution if deployment is expected to fail
if (TestCaseUtil.getTraceAssertions(testCase).contains(BPMNAssertions.ERROR_DEPLOYMENT.toString())) {
LOGGER.info("Skipping execution of process as deployment is expected to have failed.");
// if deployment has not failed the logX.txt file has to be generated for further test processing
if(!Files.exists(instanceLogFile)) {
try {
ProcessStartWithVariablesTestStep processStartWithVariablesTestStep = (ProcessStartWithVariablesTestStep) testStep;
List<Variable> variables = processStartWithVariablesTestStep.getVariables();
new ActivitiProcessStarter().start(processStartWithVariablesTestStep.getProcess(), variables);
} catch (Exception e) {
LOGGER.info("Could not start process", e);

BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeAfterTest =
new ActivitiLogBasedProcessInstanceOutcomeChecker(logFile).checkProcessOutcome(key);
Files.createFile(instanceLogFile);
} catch (IOException e) {
LOGGER.warn("Creation of file "+instanceLogFile+" failed.", e);
}
}
} else {
for (TestStep testStep : testCase.getTestSteps()) {
if (testStep instanceof ProcessStartWithVariablesTestStep) {
try {
ProcessStartWithVariablesTestStep processStartWithVariablesTestStep = (ProcessStartWithVariablesTestStep) testStep;
List<Variable> variables = processStartWithVariablesTestStep.getVariables();
new ActivitiProcessStarter().start(processStartWithVariablesTestStep.getProcess(), variables);
} catch (Exception e) {
LOGGER.info("Could not start process", e);

BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeAfterTest = new ActivitiLogBasedProcessInstanceOutcomeChecker(
logFile).checkProcessOutcome(key);
if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.RUNTIME) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_RUNTIME);
} else if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.PROCESS_INSTANCE_ABORTED_BECAUSE_ERROR_EVENT_THROWN) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_THROWN_ERROR_EVENT);
}
}
} else if (testStep instanceof DelayTestStep) {
WaitTasks.sleep(((DelayTestStep) testStep).getTimeToWaitAfterwards());
} else if (testStep instanceof GatherTracesTestStep) {
BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeAfterTest = new ActivitiLogBasedProcessInstanceOutcomeChecker(
logFile).checkProcessOutcome(key);
if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.RUNTIME) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_RUNTIME);
} else if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.PROCESS_INSTANCE_ABORTED_BECAUSE_ERROR_EVENT_THROWN) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_THROWN_ERROR_EVENT);
}
}
} else if (testStep instanceof DelayTestStep) {
WaitTasks.sleep(((DelayTestStep) testStep).getTimeToWaitAfterwards());
} else if (testStep instanceof GatherTracesTestStep) {
BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeAfterTest =
new ActivitiLogBasedProcessInstanceOutcomeChecker(logFile).checkProcessOutcome(key);
if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.RUNTIME) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_RUNTIME);
} else if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.PROCESS_INSTANCE_ABORTED_BECAUSE_ERROR_EVENT_THROWN) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_THROWN_ERROR_EVENT);
}

// Check on parallel execution
BPMNEnginesUtil.checkParallelExecution(testCase, instanceLogFile);
// Check on parallel execution
BPMNEnginesUtil.checkParallelExecution(testCase, instanceLogFile);

// Check whether MARKER file exists
BPMNEnginesUtil.checkMarkerFileExists(testCase, instanceLogFile);
// Check whether MARKER file exists
BPMNEnginesUtil.checkMarkerFileExists(testCase, instanceLogFile);

// Check data type
BPMNEnginesUtil.checkDataLog(testCase, instanceLogFile);
// Check data type
BPMNEnginesUtil.checkDataLog(testCase, instanceLogFile);
}

BPMNEnginesUtil.substituteSpecificErrorsForGenericError(testCase, instanceLogFile);
}
}

LOGGER.info("contents of log file " + instanceLogFile + ": " + FileTasks.readAllLines(instanceLogFile));
BPMNEnginesUtil.substituteSpecificErrorsForGenericError(testCase, instanceLogFile);

bpmnTester.test();
}
LOGGER.info("contents of log file " + instanceLogFile + ": " + FileTasks.readAllLines(instanceLogFile));

}
bpmnTester.test();
}

}

0 comments on commit 910eaae

Please sign in to comment.