Skip to content

Commit

Permalink
Enable setting of custom test folders for BPEL testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhard committed Aug 14, 2015
1 parent 342e1ed commit 4c67d1d
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,6 +8,7 @@ deploy.xml
.idea
tmp/
/test/
/test*
out/
build/
build-bvms/
Expand Down
10 changes: 9 additions & 1 deletion src/main/groovy/betsy/bpel/BPELBetsy.java
Expand Up @@ -4,6 +4,7 @@
import betsy.bpel.model.BPELProcess;
import betsy.bpel.model.BPELTestSuite;
import betsy.bpel.validation.BPELValidator;
import betsy.common.util.LogUtil;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -13,13 +14,16 @@ public class BPELBetsy {
private List<AbstractBPELEngine> engines = new ArrayList<>();
private List<BPELProcess> processes = new ArrayList<>();
private BPELComposite composite = new BPELComposite();
private String testFolderName;

public void execute() {
validate();

Collections.sort(processes);

BPELTestSuite testSuite = BPELTestSuite.createTests(engines, processes);
BPELTestSuite testSuite = BPELTestSuite.createTests(engines, processes, testFolderName);

LogUtil.setTestSuite(testSuite);

composite.setTestSuite(testSuite);
composite.execute();
Expand All @@ -45,6 +49,10 @@ public void setProcesses(List<BPELProcess> processes) {
this.processes = processes;
}

public void setTestFolder(String folderName){
testFolderName = folderName;
}

public BPELComposite getComposite() {
return composite;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/groovy/betsy/bpel/BPELMain.java
Expand Up @@ -15,6 +15,7 @@
import betsy.bpel.ws.TestPartnerServicePublisherExternal;
import betsy.common.HasName;
import betsy.common.config.Configuration;
import betsy.common.util.LogUtil;
import corebpel.CoreBPEL;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
Expand Down Expand Up @@ -64,6 +65,8 @@ public static void main(String[] args) {

betsy.setProcesses(params.getProcesses());
betsy.setEngines(params.getEngines());
betsy.setTestFolder(params.getTestFolderName());


// execute
try {
Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/betsy/bpel/cli/BPELCliParameter.java
Expand Up @@ -9,6 +9,7 @@ public interface BPELCliParameter {

List<AbstractBPELEngine> getEngines();
List<BPELProcess> getProcesses();
String getTestFolderName();

boolean openResultsInBrowser();
boolean checkDeployment();
Expand Down
10 changes: 10 additions & 0 deletions src/main/groovy/betsy/bpel/cli/BPELCliParser.java
Expand Up @@ -23,6 +23,11 @@ public List<BPELProcess> getProcesses() {
return Collections.emptyList();
}

@Override
public String getTestFolderName() {
return "test";
}

@Override
public boolean openResultsInBrowser() {
return false;
Expand Down Expand Up @@ -114,6 +119,11 @@ public List<BPELProcess> getProcesses() {
return new ProcessParser(cmd.getArgs()).parse();
}

@Override
public String getTestFolderName() {
return new TestFolderParser(cmd.getArgs()).parse();
}

@Override
public boolean openResultsInBrowser() {
return cmd.hasOption(OPEN_RESULTS_IN_BROWSER);
Expand Down
23 changes: 23 additions & 0 deletions src/main/groovy/betsy/bpel/cli/TestFolderParser.java
@@ -0,0 +1,23 @@
package betsy.bpel.cli;

/**
* Created by joerg on 14.08.2015.
*/
public class TestFolderParser {

private final String[] args;

private final String defaultFolderName = "test";

public TestFolderParser(String[] args){
this.args = args;
}

public String parse() {
if(args.length <= 2) {
return defaultFolderName;
} else {
return args[2];
}
}
}
37 changes: 37 additions & 0 deletions src/main/groovy/betsy/bpel/model/BPELTestSuite.java
Expand Up @@ -46,6 +46,43 @@ public static BPELTestSuite createTests(List<AbstractBPELEngine> engines, List<B
return test;
}

/**
* Factory method for a list of engines and processes.
*
* @param engines a list of engines to be included in the test suite
* @param processes a list of processes to be included in the test suite
* @param testFolderName a custom name for the test folder
* @return a test suite where each engine tests all passed processes
*/
public static BPELTestSuite createTests(List<AbstractBPELEngine> engines, List<BPELProcess> processes, String testFolderName) {
BPELTestSuite test = new BPELTestSuite();
test.setPath(Paths.get(testFolderName));

for (AbstractBPELEngine engine : engines) {

List<BPELProcess> clonedProcesses = processes.stream().map(BPELProcess::createCopyWithoutEngine).collect(Collectors.toList());

// link them
for (BPELProcess process : clonedProcesses) {
process.setEngine(engine);
engine.getProcesses().add(process);
}

// set parentFolder
engine.setParentFolder(test.getPath());
}

test.setEngines(engines);
test.setProcessesCount(getProcessesCount(engines));

Collections.shuffle(engines);
for (AbstractBPELEngine engine : engines) {
Collections.shuffle(engine.getProcesses());
}

return test;
}

public static int getProcessesCount(List<AbstractBPELEngine> engines) {
int result = 0;

Expand Down
19 changes: 17 additions & 2 deletions src/main/groovy/betsy/common/util/LogUtil.java
Expand Up @@ -9,6 +9,13 @@
import java.nio.file.Paths;

public class LogUtil {

private static TestSuite suite;

public static void setTestSuite(TestSuite testSuite){
suite = testSuite;
}

public static void log(final String name, Logger logger, Runnable closure) {
String previous = LogContext.getContext();
try {
Expand All @@ -26,8 +33,8 @@ public static void log(final String name, Logger logger, Runnable closure) {
stopwatch.stop();
logger.info("... finished in " + stopwatch.getFormattedDiff() + " | (" + stopwatch.getDiff() + "ms)");
try{
// TODO should use the TestSuite#getDurationsCsvFilePath method instead of hardcoding it to test here
new DurationCsv(Paths.get("test").resolve(TestSuite.getCsvDurationFile())).saveTaskDuration(name, stopwatch.getDiff());
// uses a non-default path if available
new DurationCsv(getCsvDurationFilePath()).saveTaskDuration(name, stopwatch.getDiff());
} catch (Exception e) {
logger.error("could not save task duration", e);
}
Expand All @@ -39,6 +46,14 @@ public static void log(final String name, Logger logger, Runnable closure) {

}

private static Path getCsvDurationFilePath() {
if(suite == null){
return Paths.get("test").resolve(TestSuite.getCsvDurationFile());
} else {
return suite.getCsvDurationFilePath();
}
}

public static void log(Path path, Logger logger, Runnable closure) {
log(path.toString(), logger, closure);
}
Expand Down

0 comments on commit 4c67d1d

Please sign in to comment.