Skip to content

Commit

Permalink
Overhaul of bpmn test process.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonharrer committed Sep 15, 2016
1 parent dc7da62 commit c5d3d4b
Show file tree
Hide file tree
Showing 35 changed files with 807 additions and 818 deletions.
6 changes: 1 addition & 5 deletions common/src/main/groovy/betsy/common/engines/EngineAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public interface EngineAPI<P> extends EngineLifecycle, IsEngine, HasLogs {
/**
* Deploy the given <code>process</code> to the current engine.
* Deployment is always synchronous.
*
* @param process to be deployed
*/
void deploy(String name, Path path);

Expand All @@ -33,15 +31,13 @@ public interface EngineAPI<P> extends EngineLifecycle, IsEngine, HasLogs {
/**
* Gets endpoint url of requested endpoint url. This url is used for testing the process later on.
*
* @param process the process
* @param name the process
* @return the url of the endpoint
*/
String getEndpointUrl(String name);

/**
* Store logs used for a specific process. This is required for analysis in case of error.
*
* @param process the process for which to store the logs.
*/
default void storeLogs(Path targetLogPath) {
FileTasks.mkdirs(targetLogPath);
Expand Down
4 changes: 0 additions & 4 deletions pebl/src/main/java/pebl/test/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public List<TestStep> getTestSteps() {
return testSteps;
}

public void setTestSteps(List<TestStep> testSteps) {
this.testSteps = testSteps;
}

public String getName() {
return name;
}
Expand Down
75 changes: 0 additions & 75 deletions pebl/src/main/java/pebl/test/VariableBasedTestCase.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pebl.test.steps;

import pebl.test.assertions.Trace;
import pebl.test.assertions.TraceTestAssertion;

public class GatherAndAssertTracesTestStep extends AssertableTestStep {

public GatherAndAssertTracesTestStep addTrace(Trace trace) {
getAssertions().add(new TraceTestAssertion(trace));

return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package pebl.test.steps;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import pebl.test.TestStep;

public class ProcessStartWithVariablesTestStep extends TestStep {

private List<Variable> variables = new LinkedList<>();
private String process;

public ProcessStartWithVariablesTestStep addVariable(Variable variable) {
this.variables.add(variable);

return this;
}

public List<Variable> getVariables() {
return Collections.unmodifiableList(variables);
}

public String getProcess() {
return process;
}

public void setProcess(String process) {
this.process = process;
}
}
39 changes: 0 additions & 39 deletions pebl/src/main/java/pebl/test/steps/VariableBasedTestStep.java

This file was deleted.

18 changes: 9 additions & 9 deletions src/main/groovy/betsy/bpmn/engines/BPMNEnginesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
import java.util.List;

import betsy.bpmn.model.BPMNAssertions;
import betsy.bpmn.model.BPMNTestCase;
import betsy.common.tasks.FileTasks;
import org.apache.log4j.Logger;
import pebl.test.TestCase;

public class BPMNEnginesUtil {

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

public static void substituteSpecificErrorsForGenericError(BPMNTestCase testCase, Path logDir) {
if (testCase.getAssertions().contains(BPMNAssertions.ERROR_GENERIC.toString())) {
public static void substituteSpecificErrorsForGenericError(TestCase testCase, Path logDir) {
if (TestCaseUtil.getTraceAssertions(testCase).contains(BPMNAssertions.ERROR_GENERIC.toString())){
List<String> toReplace = new ArrayList<>();
toReplace.add(BPMNAssertions.ERROR_DEPLOYMENT.toString());
toReplace.add(BPMNAssertions.ERROR_RUNTIME.toString());
FileTasks.replaceLogFileContent(toReplace, BPMNAssertions.ERROR_GENERIC.toString(), logDir);
}
}

public static void checkParallelExecution(BPMNTestCase testCase, Path logFile) {
public static void checkParallelExecution(TestCase testCase, Path logFile) {
// Only check on parallelism when asked for a parallel assertion
if (!testCase.getAssertions().contains(BPMNAssertions.EXECUTION_PARALLEL.toString())) {
if (!TestCaseUtil.getTraceAssertions(testCase).contains(BPMNAssertions.EXECUTION_PARALLEL.toString())) {
return;
}

Expand All @@ -43,18 +43,18 @@ public static void checkParallelExecution(BPMNTestCase testCase, Path logFile) {

}

public static void checkMarkerFileExists(BPMNTestCase testCase, Path logFile) {
if(!testCase.getAssertions().contains(BPMNAssertions.MARKER_EXISTS.toString())) {
public static void checkMarkerFileExists(TestCase testCase, Path logFile) {
if (!TestCaseUtil.getTraceAssertions(testCase).contains(BPMNAssertions.MARKER_EXISTS.toString())) {
return;
}
if (Files.exists(logFile.getParent().resolve("MARKER"))) {
BPMNAssertions.appendToFile(logFile, BPMNAssertions.MARKER_EXISTS);
}
}

public static void checkDataLog(BPMNTestCase testCase, Path logFile) {
public static void checkDataLog(TestCase testCase, Path logFile) {
// Only check when asked for a data type assertion
if (!testCase.getAssertions().contains(BPMNAssertions.DATA_CORRECT.toString())) {
if (!TestCaseUtil.getTraceAssertions(testCase).contains(BPMNAssertions.DATA_CORRECT.toString())) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/groovy/betsy/bpmn/engines/BPMNProcessStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public interface BPMNProcessStarter {
* @param variables
* @throws RuntimeException in case any failures are detected
*/
public void start(String processID, List<Variable> variables) throws RuntimeException;
void start(String processID, List<Variable> variables) throws RuntimeException;

/**
* Starts a new process instance but without any variables.
*
* @param processID
*/
public default void start(String processID) {
default void start(String processID) {
start(processID, Collections.emptyList());
}

Expand Down
55 changes: 55 additions & 0 deletions src/main/groovy/betsy/bpmn/engines/TestCaseUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package betsy.bpmn.engines;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import pebl.test.TestCase;
import pebl.test.assertions.Trace;
import pebl.test.assertions.TraceTestAssertion;
import pebl.test.steps.AssertableTestStep;
import pebl.test.steps.GatherAndAssertTracesTestStep;
import pebl.test.steps.ProcessStartWithVariablesTestStep;

public class TestCaseUtil {
public static String getKey(TestCase testCase) {
return testCase.getTestSteps().stream()
.filter(ts -> ts instanceof ProcessStartWithVariablesTestStep)
.map(ts -> (ProcessStartWithVariablesTestStep)ts)
.filter(ts -> !ts.getVariables().isEmpty())
.map(ProcessStartWithVariablesTestStep::getProcess)
.findFirst().orElseThrow(() -> new IllegalStateException("test case should a key somewhere: " + testCase));
}

public static List<String> getTraceAssertions(TestCase testCase) {
return Optional.of(testCase)
.map(tc -> tc.getTestSteps()
.stream()
.filter(ts -> ts instanceof GatherAndAssertTracesTestStep)
.map(ts -> (GatherAndAssertTracesTestStep) ts)
.map(AssertableTestStep::getAssertions)
.flatMap(ta -> ta.stream()
.filter(ts -> ts instanceof TraceTestAssertion)
.map(ts -> (TraceTestAssertion) ts)
.map(TraceTestAssertion::getTrace)
.map(Trace::getValue))
.collect(Collectors.toList())).orElse(Collections.emptyList());
}

public static String getNormalizedTestCaseName(TestCase testCase) {
StringBuilder sb = new StringBuilder();
sb.append("test").append(testCase.getNumber()).append("Assert");
for (String assertion : getTraceAssertions(testCase)) {
sb.append(capitalize(assertion));
}
return sb.toString();
}

private static String capitalize(String self) {
if (self == null || self.length() == 0) {
return self;
}
return Character.toUpperCase(self.charAt(0)) + self.substring(1);
}
}
20 changes: 9 additions & 11 deletions src/main/groovy/betsy/bpmn/engines/activiti/ActivitiEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import betsy.bpmn.engines.JsonHelper;
import betsy.bpmn.model.BPMNProcess;
import betsy.bpmn.model.BPMNTestBuilder;
import betsy.bpmn.model.BPMNTestCase;
import betsy.common.engines.tomcat.Tomcat;
import pebl.ProcessLanguage;
import betsy.common.model.engine.EngineExtended;
import betsy.common.tasks.FileTasks;
import betsy.common.tasks.XSLTTasks;
import betsy.common.util.ClasspathHelper;
import org.apache.log4j.Logger;
import pebl.ProcessLanguage;
import pebl.test.TestCase;

public class ActivitiEngine extends AbstractBPMNEngine {

Expand All @@ -30,21 +30,19 @@ public class ActivitiEngine extends AbstractBPMNEngine {

@Override
public void testProcess(BPMNProcess process) {
for (BPMNTestCase testCase : process.getTestCases()) {
for (TestCase testCase : process.getTestCases()) {
BPMNTester bpmnTester = new BPMNTester();
int testCaseNumber = testCase.getNumber();
bpmnTester.setSource(process.getTargetTestSrcPathWithCase(testCaseNumber));
bpmnTester.setTarget(process.getTargetTestBinPathWithCase(testCaseNumber));
bpmnTester.setReportPath(process.getTargetReportsPathWithCase(testCaseNumber));

ActivitiTester tester = new ActivitiTester();
tester.setTestCase(testCase);
tester.setBpmnTester(bpmnTester);
tester.setKey(process.getName());
tester.setInstanceLogFile(getInstanceLogFile(testCaseNumber));
tester.setLogDir(getTomcat().getTomcatLogsDir());

tester.runTest();
new ActivitiTester(
testCase,
getTomcat().getTomcatLogsDir(),
getInstanceLogFile(testCaseNumber),
bpmnTester
).runTest();
}
new BPMNTestcaseMerger(process.getTargetReportsPath()).mergeTestCases();
}
Expand Down

0 comments on commit c5d3d4b

Please sign in to comment.