Skip to content

Commit

Permalink
Create GenericBPMNTester instead of engine specific ones
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgeiger committed Sep 28, 2016
1 parent 90d8487 commit 7300943
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 273 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package betsy.bpmn.engines.activiti;
package betsy.bpmn.engines;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

import betsy.bpmn.engines.BPMNEnginesUtil;
import betsy.bpmn.engines.BPMNProcessInstanceOutcomeChecker;
import betsy.bpmn.engines.BPMNTester;
import betsy.bpmn.model.BPMNAssertions;
import betsy.bpmn.model.BPMNProcess;
import betsy.common.tasks.FileTasks;
Expand All @@ -24,33 +21,41 @@
import pebl.test.steps.vars.ProcessStartWithVariablesTestStep;
import pebl.test.steps.vars.Variable;

public class ActivitiTester {
private static final Logger LOGGER = Logger.getLogger(ActivitiTester.class);
public class GenericBPMNTester {

private static final Logger LOGGER = Logger.getLogger(GenericBPMNTester.class);

private final BPMNProcess bpmnProcess;
private final TestCase testCase;
private final Path logDir;
private final Path instanceLogFile;
private final BPMNTester bpmnTester;

public ActivitiTester(BPMNProcess bpmnProcess, TestCase testCase, Path logDir, Path instanceLogFile, BPMNTester bpmnTester) {
private final BPMNProcessInstanceOutcomeChecker checkerOutcomeAfter;
private final BPMNProcessStarter processStarter;
private final BPMNProcessInstanceOutcomeChecker checkerOutcomeBefore;

public GenericBPMNTester(BPMNProcess bpmnProcess, TestCase testCase, Path instanceLogFile,
BPMNTester bpmnTester,
BPMNProcessInstanceOutcomeChecker checkerOutcomeBefore,
BPMNProcessInstanceOutcomeChecker checkerOutcomeAfter,
BPMNProcessStarter processStarter) {
this.bpmnProcess = bpmnProcess;
this.testCase = Objects.requireNonNull(testCase);
this.logDir = Objects.requireNonNull(logDir);
this.instanceLogFile = Objects.requireNonNull(instanceLogFile);
this.bpmnTester = Objects.requireNonNull(bpmnTester);
this.checkerOutcomeBefore = Objects.requireNonNull(checkerOutcomeBefore);
this.checkerOutcomeAfter = Objects.requireNonNull(checkerOutcomeAfter);
this.processStarter = Objects.requireNonNull(processStarter);
}


/**
* runs a single test
*/
public void runTest() {

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

for (TestStep testStep : testCase.getTestSteps()) {
if (testStep instanceof DeployableCheckTestStep) {
BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeBeforeTest = new ActivitiApiBasedProcessOutcomeChecker()
BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeBeforeTest = checkerOutcomeBefore
.checkProcessOutcome(bpmnProcess.getName());
if (outcomeBeforeTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.UNDEPLOYED_PROCESS) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_DEPLOYMENT);
Expand All @@ -59,42 +64,38 @@ public void runTest() {
try {
ProcessStartWithVariablesTestStep processStartWithVariablesTestStep = (ProcessStartWithVariablesTestStep) testStep;
List<Variable> variables = processStartWithVariablesTestStep.getVariables();
new ActivitiProcessStarter().start(processStartWithVariablesTestStep.getProcess(), variables);
processStarter.start(processStartWithVariablesTestStep.getProcess(), variables);
} catch (Exception e) {
LOGGER.info("Could not start process", e);

BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeAfterTest = new ActivitiLogBasedProcessInstanceOutcomeChecker(
logFile).checkProcessOutcome(bpmnProcess.getName());
if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.RUNTIME) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_RUNTIME);
} else if (outcomeAfterTest
BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeAfterTest = checkerOutcomeAfter.checkProcessOutcome(bpmnProcess.getName());
if (outcomeAfterTest
== BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.PROCESS_INSTANCE_ABORTED_BECAUSE_ERROR_EVENT_THROWN) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_THROWN_ERROR_EVENT);
// do not log at this time
} else {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_RUNTIME);
}
}
} else if (testStep instanceof DelayTestStep) {
WaitTasks.sleep(((DelayTestStep) testStep).getTimeToWaitAfterwards());
} else if (testStep instanceof GatherTracesTestStep) {
// Skip further processing if process is expected to be undeployed
if(testStep.getAssertions().stream().filter(a -> a instanceof TraceTestAssertion && ((TraceTestAssertion) a).getTrace().equals(new Trace(BPMNAssertions.ERROR_DEPLOYMENT.toString())))
.findFirst().isPresent()) {
if(!Files.exists(instanceLogFile)) {
try {
Files.createFile(instanceLogFile);
} catch (IOException e) {
LOGGER.warn("Creation of log file failed.", e);
}
}

if(shouldDeploymentFail(testStep)) {
// Skip further processing if process is expected to be undeployed
break;
}

BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeAfterTest = new ActivitiLogBasedProcessInstanceOutcomeChecker(
logFile).checkProcessOutcome(bpmnProcess.getName());
BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome outcomeAfterTest = checkerOutcomeAfter.checkProcessOutcome(bpmnProcess.getName());
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 (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.PROCESS_INSTANCE_ABORTED) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_PROCESS_ABORTED);
} else if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.PROCESS_INSTANCE_ABORTED_BECAUSE_ERROR_EVENT_THROWN) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_THROWN_ERROR_EVENT);
} else if (outcomeAfterTest == BPMNProcessInstanceOutcomeChecker.ProcessInstanceOutcome.PROCESS_INSTANCE_ABORTED_BECAUSE_ESCALATION_EVENT_THROWN) {
BPMNAssertions.appendToFile(instanceLogFile, BPMNAssertions.ERROR_THROWN_ESCALATION_EVENT);
}

// Check on parallel execution
Expand All @@ -116,4 +117,21 @@ public void runTest() {
bpmnTester.test();
}

private boolean shouldDeploymentFail(TestStep testStep) {
if(testStep.getAssertions().stream().filter(a -> a instanceof TraceTestAssertion && ((TraceTestAssertion) a).getTrace().equals(new Trace(
BPMNAssertions.ERROR_DEPLOYMENT.toString())))
.findFirst().isPresent()) {
// Ensure existence of instanceLogFile for JUnit test execution
if(!Files.exists(instanceLogFile)) {
try {
Files.createFile(instanceLogFile);
} catch (IOException e) {
LOGGER.warn("Creation of log file failed.", e);
}
}
return true;
}

return false;
}
}
10 changes: 6 additions & 4 deletions src/main/groovy/betsy/bpmn/engines/activiti/ActivitiEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import betsy.bpmn.engines.BPMNProcessStarter;
import betsy.bpmn.engines.BPMNTestcaseMerger;
import betsy.bpmn.engines.BPMNTester;
import betsy.bpmn.engines.GenericBPMNTester;
import betsy.bpmn.engines.JsonHelper;
import betsy.bpmn.model.BPMNProcess;
import betsy.bpmn.model.BPMNTestBuilder;
Expand Down Expand Up @@ -37,12 +38,13 @@ public void testProcess(BPMNProcess process) {
bpmnTester.setTarget(process.getTargetTestBinPathWithCase(testCaseNumber));
bpmnTester.setReportPath(process.getTargetReportsPathWithCase(testCaseNumber));

new ActivitiTester(
process,
new GenericBPMNTester(process,
testCase,
getTomcat().getTomcatLogsDir(),
getInstanceLogFile(process.getName(), testCaseNumber),
bpmnTester
bpmnTester,
new ActivitiApiBasedProcessOutcomeChecker(),
new ActivitiLogBasedProcessInstanceOutcomeChecker(getTomcat().getTomcatLogsDir().resolve("activiti.log")),
new ActivitiProcessStarter()
).runTest();
}
new BPMNTestcaseMerger(process.getTargetReportsPath()).mergeTestCases();
Expand Down
10 changes: 6 additions & 4 deletions src/main/groovy/betsy/bpmn/engines/camunda/CamundaEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import betsy.bpmn.engines.BPMNProcessStarter;
import betsy.bpmn.engines.BPMNTestcaseMerger;
import betsy.bpmn.engines.BPMNTester;
import betsy.bpmn.engines.GenericBPMNTester;
import betsy.bpmn.model.BPMNProcess;
import betsy.bpmn.model.BPMNTestBuilder;
import betsy.common.config.Configuration;
Expand Down Expand Up @@ -174,12 +175,13 @@ public void testProcess(BPMNProcess process) {
bpmnTester.setTarget(process.getTargetTestBinPathWithCase(testCaseNumber));
bpmnTester.setReportPath(process.getTargetReportsPathWithCase(testCaseNumber));

new CamundaTester(
process,
new GenericBPMNTester(process,
testCase,
getTomcatLogsDir(),
getInstanceLogFile(process.getName(), testCaseNumber),
bpmnTester
bpmnTester,
new CamundaApiBasedProcessInstanceOutcomeChecker(),
new CamundaLogBasedProcessInstanceOutcomeChecker(FileTasks.findFirstMatchInFolder(getTomcatLogsDir(), "catalina*")),
new CamundaProcessStarter()
).runTest();
}

Expand Down
111 changes: 0 additions & 111 deletions src/main/groovy/betsy/bpmn/engines/camunda/CamundaTester.java

This file was deleted.

18 changes: 11 additions & 7 deletions src/main/groovy/betsy/bpmn/engines/jbpm/JbpmEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import javax.xml.namespace.QName;

import betsy.bpmn.engines.AbstractBPMNEngine;
import betsy.bpmn.engines.BPMNProcessInstanceOutcomeChecker;
import betsy.bpmn.engines.BPMNProcessStarter;
import betsy.bpmn.engines.BPMNTestcaseMerger;
import betsy.bpmn.engines.BPMNTester;
import betsy.bpmn.engines.GenericBPMNTester;
import betsy.bpmn.model.BPMNProcess;
import betsy.bpmn.model.BPMNTestBuilder;
import betsy.common.config.Configuration;
import pebl.ProcessLanguage;
import betsy.common.model.engine.EngineExtended;
import betsy.common.tasks.ConsoleTasks;
import betsy.common.tasks.FileTasks;
Expand All @@ -28,6 +29,7 @@
import betsy.common.timeouts.timeout.TimeoutRepository;
import betsy.common.util.ClasspathHelper;
import org.apache.log4j.Logger;
import pebl.ProcessLanguage;
import pebl.test.TestCase;

public class JbpmEngine extends AbstractBPMNEngine {
Expand Down Expand Up @@ -87,7 +89,7 @@ public void deploy(String name, Path path) {
JbpmDeployer deployer = new JbpmDeployer(getJbpmnUrl(), deploymentId);
deployer.deploy();

TimeoutRepository.getTimeout("Jbpm.deploy").waitFor(() -> isDeployed(new QName(name)));
TimeoutRepository.getTimeout("Jbpm.deploy").waitFor(deployer::isDeploymentFinished);
}

@Override
Expand Down Expand Up @@ -203,13 +205,15 @@ public void testProcess(final BPMNProcess process) {
bpmnTester.setTarget(process.getTargetTestBinPathWithCase(testCaseNumber));
bpmnTester.setReportPath(process.getTargetReportsPathWithCase(testCaseNumber));

new JbpmTester(
process,
BPMNProcessInstanceOutcomeChecker checker = createProcessOutcomeChecker(process.getName());

new GenericBPMNTester(process,
testCase,
bpmnTester,
createProcessOutcomeChecker(process.getName()),
getInstanceLogFile(process.getName(), testCaseNumber),
getJbossLogDir().resolve("server.log")
bpmnTester,
checker,
checker,
new JbpmProcessStarter()
).runTest();
}

Expand Down
Loading

0 comments on commit 7300943

Please sign in to comment.