Skip to content

Commit 9a4c52c

Browse files
authored
Merge pull request #95 from common-workflow-language/tests
Addition of Unit Testing
2 parents ddae3f4 + 80753ad commit 9a4c52c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+163552
-124
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ dist: trusty
44
language: java
55

66
services: mongodb
7+
8+
before_install:
9+
- sudo apt-get -qq update
10+
- sudo apt-get install graphviz

src/main/java/org/commonwl/view/cwl/CWLService.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private Map<String, CWLStep> getSteps(JsonNode cwlDoc) {
282282
// Explicit ID and other fields within each input list
283283
for (JsonNode step : steps) {
284284
CWLStep stepObject = new CWLStep(extractLabel(step), extractDoc(step),
285-
extractTypes(step), extractRun(step), getInputs(step), getOutputs(step));
285+
extractRun(step), getInputs(step));
286286
returnMap.put(extractID(step), stepObject);
287287
}
288288
} else if (steps.getClass() == ObjectNode.class) {
@@ -292,8 +292,7 @@ private Map<String, CWLStep> getSteps(JsonNode cwlDoc) {
292292
Map.Entry<String, JsonNode> stepNode = iterator.next();
293293
JsonNode stepJson = stepNode.getValue();
294294
CWLStep stepObject = new CWLStep(extractLabel(stepJson), extractDoc(stepJson),
295-
extractTypes(stepJson), extractRun(stepJson), getInputs(stepJson),
296-
getOutputs(stepJson));
295+
extractRun(stepJson), getInputs(stepJson));
297296
returnMap.put(stepNode.getKey(), stepObject);
298297
}
299298
}
@@ -311,7 +310,7 @@ private Map<String, CWLStep> getSteps(JsonNode cwlDoc) {
311310
private Map<String, CWLElement> getInputs(JsonNode cwlDoc) {
312311
if (cwlDoc != null) {
313312
if (cwlDoc.has(INPUTS)) {
314-
// For workflow/draft steps
313+
// For all version workflow inputs/outputs and draft steps
315314
return getInputsOutputs(cwlDoc.get(INPUTS));
316315
} else if (cwlDoc.has(IN)) {
317316
// For V1.0 steps
@@ -328,13 +327,11 @@ private Map<String, CWLElement> getInputs(JsonNode cwlDoc) {
328327
*/
329328
private Map<String, CWLElement> getOutputs(JsonNode cwlDoc) {
330329
if (cwlDoc != null) {
330+
// For all version workflow inputs/outputs and draft steps
331331
if (cwlDoc.has(OUTPUTS)) {
332-
// For workflow/draft steps
333332
return getInputsOutputs(cwlDoc.get(OUTPUTS));
334-
} else if (cwlDoc.has(OUT)) {
335-
// For V1.0 steps
336-
return getStepInputsOutputs(cwlDoc.get(OUT));
337333
}
334+
// Outputs are not gathered for v1 steps
338335
}
339336
return null;
340337
}
@@ -668,7 +665,7 @@ private String extractTypes(JsonNode typeNode) {
668665
}
669666

670667
// Add optional if null was included in the multiple types
671-
if (optional) typeDetails.append(" (Optional)");
668+
if (optional) typeDetails.append("?");
672669

673670
// Set the type to the constructed string
674671
return typeDetails.toString();

src/main/java/org/commonwl/view/cwl/CWLStep.java

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,16 @@ public class CWLStep {
2828

2929
private String label;
3030
private String doc;
31-
private String type;
3231
private String run;
3332
private CWLProcess runType;
34-
private Map<String, CWLElement> inputs;
35-
private Map<String, CWLElement> outputs;
33+
private Map<String, CWLElement> sources;
3634

37-
public CWLStep(String label, String doc, String type, String run,
38-
Map<String, CWLElement> inputs, Map<String, CWLElement> outputs) {
35+
public CWLStep(String label, String doc, String run,
36+
Map<String, CWLElement> sources) {
3937
this.label = label;
4038
this.doc = doc;
41-
this.type = type;
4239
this.run = run;
43-
this.inputs = inputs;
44-
this.outputs = outputs;
40+
this.sources = sources;
4541
}
4642

4743
public String getLabel() {
@@ -60,14 +56,6 @@ public void setDoc(String doc) {
6056
this.doc = doc;
6157
}
6258

63-
public String getType() {
64-
return type;
65-
}
66-
67-
public void setType(String type) {
68-
this.type = type;
69-
}
70-
7159
public String getRun() {
7260
return run;
7361
}
@@ -84,20 +72,8 @@ public void setRunType(CWLProcess runType) {
8472
this.runType = runType;
8573
}
8674

87-
public Map<String, CWLElement> getInputs() {
88-
return inputs;
89-
}
90-
91-
public void setInputs(Map<String, CWLElement> inputs) {
92-
this.inputs = inputs;
93-
}
94-
95-
public Map<String, CWLElement> getOutputs() {
96-
return outputs;
97-
}
98-
99-
public void setOutputs(Map<String, CWLElement> outputs) {
100-
this.outputs = outputs;
75+
public Map<String, CWLElement> getSources() {
76+
return sources;
10177
}
10278

10379
}

src/main/java/org/commonwl/view/docker/DockerService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class DockerService {
2020
public static String getDockerHubURL(String dockerPull) {
2121
Matcher m = dockerhubPattern.matcher(dockerPull);
2222
if (m.find()) {
23-
if (m.group(1).isEmpty()) {
24-
return "https://hub.docker.com/r/_/" + m.group(2);
23+
if (m.group(2) == null) {
24+
return "https://hub.docker.com/r/_/" + m.group(1);
2525
} else {
2626
return "https://hub.docker.com/r/" + m.group(1) + "/" + m.group(2);
2727
}

src/main/java/org/commonwl/view/github/GitHubService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public class GitHubService {
5454
private final CommitService commitService;
5555

5656
// URL validation for directory links
57-
private final String GITHUB_DIR_REGEX = "^https?:\\/\\/github\\.com\\/([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)\\/?(?:(?:tree|blob)\\/([^/]+)\\/?(.*)?)?$";
58-
private final Pattern githubDirPattern = Pattern.compile(GITHUB_DIR_REGEX);
57+
private static final String GITHUB_DIR_REGEX = "^https?:\\/\\/github\\.com\\/([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)\\/?(?:(?:tree|blob)\\/([^/]+)\\/?(.*)?)?$";
58+
private static final Pattern githubDirPattern = Pattern.compile(GITHUB_DIR_REGEX);
5959

6060
// URL validation for cwl files
61-
private final String GITHUB_CWL_REGEX = "^https?:\\/\\/github\\.com\\/([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)\\/?(?:tree|blob)\\/([^/]+)(?:\\/(.+\\.cwl))$";
62-
private final Pattern githubCwlPattern = Pattern.compile(GITHUB_CWL_REGEX);
61+
private static final String GITHUB_CWL_REGEX = "^https?:\\/\\/github\\.com\\/([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)\\/?(?:tree|blob)\\/([^/]+)(?:\\/(.+\\.cwl))$";
62+
private static final Pattern githubCwlPattern = Pattern.compile(GITHUB_CWL_REGEX);
6363

6464
private final boolean downloadWithAPI;
6565

src/main/java/org/commonwl/view/github/GithubDetails.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public String getURL() {
9797
*/
9898
public String getURL(String ref) {
9999
String url = "https://github.com/" + owner + "/" + repoName + "/tree/" + ref;
100-
if (path != null) {
100+
if (path != null && !path.equals("/")) {
101101
url += "/" + this.path;
102102
}
103103
return url;

src/main/java/org/commonwl/view/graphviz/DotWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ private void writeSteps(Workflow workflow) throws IOException {
173173
// Write links between the remaining steps
174174
int defaultCount = 0;
175175
for (Map.Entry<String, CWLStep> step : workflow.getSteps().entrySet()) {
176-
if (step.getValue().getInputs() != null) {
177-
for (Map.Entry<String, CWLElement> input : step.getValue().getInputs().entrySet()) {
176+
if (step.getValue().getSources() != null) {
177+
for (Map.Entry<String, CWLElement> input : step.getValue().getSources().entrySet()) {
178178
List<String> sourceIDs = input.getValue().getSourceIDs();
179179

180180
// Draw the default value on the graph if there are no step inputs (it is a constant)

src/main/java/org/commonwl/view/researchobject/ROBundleFactory.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
package org.commonwl.view.researchobject;
2121

2222
import org.apache.commons.io.FilenameUtils;
23-
import org.commonwl.view.github.GitHubService;
23+
import org.apache.taverna.robundle.Bundle;
2424
import org.commonwl.view.github.GithubDetails;
2525
import org.commonwl.view.workflow.Workflow;
2626
import org.commonwl.view.workflow.WorkflowRepository;
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
2929
import org.springframework.beans.factory.annotation.Autowired;
30-
import org.springframework.beans.factory.annotation.Value;
3130
import org.springframework.scheduling.annotation.Async;
3231
import org.springframework.scheduling.annotation.EnableAsync;
3332
import org.springframework.stereotype.Component;
@@ -47,34 +46,24 @@ public class ROBundleFactory {
4746

4847
private final Logger logger = LoggerFactory.getLogger(this.getClass());
4948

50-
private final String applicationName;
51-
private final String applicationURL;
52-
private final int singleFileSizeLimit;
53-
private final Path storageLocation;
5449
private final WorkflowRepository workflowRepository;
50+
private final ROBundleService roBundleService;
5551

5652
@Autowired
57-
public ROBundleFactory(@Value("${applicationName}") String applicationName,
58-
@Value("${applicationURL}") String applicationURL,
59-
@Value("${graphvizStorage}") Path graphvizStorage,
60-
@Value("${singleFileSizeLimit}") int singleFileSizeLimit,
53+
public ROBundleFactory(ROBundleService roBundleService,
6154
WorkflowRepository workflowRepository) {
62-
this.applicationName = applicationName;
63-
this.applicationURL = applicationURL;
64-
this.storageLocation = graphvizStorage;
6555
this.workflowRepository = workflowRepository;
66-
this.singleFileSizeLimit = singleFileSizeLimit;
56+
this.roBundleService = roBundleService;
6757
}
6858

6959
/**
7060
* Creates a new Workflow Research Object Bundle from a Github URL
7161
* and saves it to a file
72-
* @param githubService The service for Github API functionality
7362
* @param githubInfo Details of the Github repository
7463
* @throws IOException Any API errors which may have occurred
7564
*/
7665
@Async
77-
public void workflowROFromGithub(GitHubService githubService, GithubDetails githubInfo)
66+
public void workflowROFromGithub(GithubDetails githubInfo)
7867
throws IOException, InterruptedException {
7968
logger.info("Creating Research Object Bundle");
8069

@@ -83,16 +72,15 @@ public void workflowROFromGithub(GitHubService githubService, GithubDetails gith
8372
githubInfo.getBranch(), FilenameUtils.getPath(githubInfo.getPath()));
8473

8574
// Create a new Research Object Bundle with Github contents
86-
ROBundle bundle = new ROBundle(githubService, roDetails,
87-
applicationName, applicationURL, singleFileSizeLimit);
75+
Bundle bundle = roBundleService.newBundleFromGithub(roDetails);
8876

8977
// Save the bundle to the storage location in properties
90-
Path bundleLocation = bundle.saveToFile(storageLocation);
78+
Path bundleLocation = roBundleService.saveToFile(bundle);
9179

9280
// Add the path to the bundle to the bundle
9381
Workflow workflow = workflowRepository.findByRetrievedFrom(githubInfo);
9482

95-
// Chance that this thread could be created before workflow model is saved
83+
// Chance that this thread could be done before workflow model is saved
9684
int attempts = 5;
9785
while (attempts > 0 && workflow == null) {
9886
// Delay this thread by 0.5s and try again until success or too many attempts

0 commit comments

Comments
 (0)