Skip to content

Commit deea6c3

Browse files
author
Mark Robinson
committed
Add test for main CWL service
Gets workflows from community repo by commit ID to test
1 parent 79f3d04 commit deea6c3

File tree

3 files changed

+129
-1
lines changed

3 files changed

+129
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ private String extractTypes(JsonNode typeNode) {
668668
}
669669

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

673673
// Set the type to the constructed string
674674
return typeDetails.toString();
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package org.commonwl.view.cwl;
2+
3+
import org.commonwl.view.github.GithubDetails;
4+
import org.commonwl.view.workflow.Workflow;
5+
import org.commonwl.view.workflow.WorkflowOverview;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.boot.test.context.SpringBootTest;
12+
import org.springframework.test.context.junit4.SpringRunner;
13+
14+
import java.util.Map;
15+
16+
import static org.junit.Assert.*;
17+
18+
@RunWith(SpringRunner.class)
19+
@SpringBootTest
20+
public class CWLServiceTest {
21+
22+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
23+
24+
/**
25+
* Create a service to test
26+
*/
27+
@Autowired
28+
private CWLService cwlService;
29+
30+
/**
31+
* Test main parsing of a the LobSTR workflow CWL version draft-3
32+
*/
33+
@Test
34+
public void parseLobSTRDraft3Workflow() throws Exception {
35+
36+
// Get workflow from community repo by commit ID so it will not change
37+
GithubDetails lobSTRDraft3Details = new GithubDetails("common-workflow-language",
38+
"workflows", null, "workflows/lobSTR/lobSTR-workflow.cwl");
39+
Workflow lobSTRDraft3 = cwlService.parseWorkflow(lobSTRDraft3Details, "920c6be45f08e979e715a0018f22c532b024074f");
40+
41+
testLobSTRWorkflow(lobSTRDraft3);
42+
43+
// Extra docker requirement test
44+
assertEquals("true", lobSTRDraft3.getDockerLink());
45+
}
46+
47+
/**
48+
* Test main parsing of a the LobSTR workflow CWL version 1.0
49+
*/
50+
@Test
51+
public void parseLobSTRv1Workflow() throws Exception {
52+
53+
// Get workflow from community repo by commit ID so it will not change
54+
GithubDetails lobSTRv1Details = new GithubDetails("common-workflow-language",
55+
"workflows", null, "workflows/lobSTR/lobSTR-workflow.cwl");
56+
Workflow lobSTRv1 = cwlService.parseWorkflow(lobSTRv1Details, "933bf2a1a1cce32d88f88f136275535da9df0954");
57+
58+
testLobSTRWorkflow(lobSTRv1);
59+
60+
// Extra docker requirement test
61+
assertEquals("https://hub.docker.com/r/rabix/lobstr", lobSTRv1.getDockerLink());
62+
63+
}
64+
65+
/**
66+
* Validate a LobSTR workflow
67+
* See: https://github.com/common-workflow-language/workflows/tree/master/workflows/lobSTR
68+
*/
69+
private void testLobSTRWorkflow(Workflow lobSTR) throws Exception {
70+
71+
// Overall not null
72+
assertNotNull(lobSTR);
73+
74+
// Input Tests
75+
Map<String, CWLElement> inputs = lobSTR.getInputs();
76+
assertNotNull(inputs);
77+
assertEquals(8, inputs.size());
78+
assertNotNull(inputs.get("strinfo"));
79+
assertEquals("File", inputs.get("strinfo").getType());
80+
assertNotNull(inputs.get("p2"));
81+
assertEquals("File[]?", inputs.get("p2").getType());
82+
assertNotNull(inputs.get("rg-sample"));
83+
assertEquals("Use this in the read group SM tag", inputs.get("rg-sample").getDoc());
84+
85+
// Step tests
86+
Map<String, CWLStep> steps = lobSTR.getSteps();
87+
assertNotNull(steps);
88+
assertEquals(4, steps.size());
89+
assertNotNull(steps.get("lobSTR"));
90+
assertEquals("lobSTR-tool.cwl", steps.get("lobSTR").getRun());
91+
assertEquals(CWLProcess.COMMANDLINETOOL, steps.get("lobSTR").getRunType());
92+
assertNotNull(steps.get("samindex"));
93+
assertTrue(steps.get("samindex").getInputs().get("input").getSourceIDs().contains("samsort"));
94+
95+
// Output tests
96+
Map<String, CWLElement> outputs = lobSTR.getOutputs();
97+
assertNotNull(outputs);
98+
assertEquals(4, outputs.size());
99+
assertNotNull(outputs.get("bam_stats"));
100+
assertEquals("File", outputs.get("bam_stats").getType());
101+
assertTrue(outputs.get("bam").getSourceIDs().contains("samindex"));
102+
103+
}
104+
105+
/**
106+
* Test retrieval of a workflow overview for hello world example in cwl
107+
*/
108+
@Test
109+
public void getHelloWorkflowOverview() throws Exception {
110+
111+
// Get workflow from community repo by commit ID so it will not change
112+
GithubDetails helloDetails = new GithubDetails("common-workflow-language",
113+
"workflows", "8296e92d358bb5da4dc3c6e7aabefa89726e3409", "workflows/hello/hello.cwl");
114+
WorkflowOverview hello = cwlService.getWorkflowOverview(helloDetails);
115+
assertNotNull(hello);
116+
117+
// No docs for this workflow
118+
assertEquals("Hello World", hello.getLabel());
119+
assertEquals("Puts a message into a file using echo", hello.getDoc());
120+
assertEquals("hello.cwl", hello.getFileName());
121+
122+
}
123+
124+
}

src/test/java/org/commonwl/view/docker/DockerServiceTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Test;
44

55
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertNull;
67

78
public class DockerServiceTest {
89

@@ -21,6 +22,9 @@ public void getDockerHubURL() throws Exception {
2122
String test3 = DockerService.getDockerHubURL("ubuntu");
2223
assertEquals("https://hub.docker.com/r/_/ubuntu", test3);
2324

25+
String test4 = DockerService.getDockerHubURL(null);
26+
assertNull(test4);
27+
2428
}
2529

2630
}

0 commit comments

Comments
 (0)