Skip to content

Commit 79f3d04

Browse files
author
Mark Robinson
committed
Add tests for functionality with no network requirement
1 parent ddae3f4 commit 79f3d04

File tree

10 files changed

+306
-4
lines changed

10 files changed

+306
-4
lines changed

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/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 != "/") {
101101
url += "/" + this.path;
102102
}
103103
return url;

src/main/resources/templates/workflow.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ <h2>Steps</h2>
216216
(<span th:text="${step.value.runType}">Workflow</span>)
217217
</div>
218218
<div th:if="${step.value.run != null and step.value.runType == null}">
219-
<span th:text="${step.value.run} + '(?)'" class="notFound" data-tooltip="true" title="Not Found - Must be somewhere within this repository">workflow.cwl (?)</span>
219+
<span th:text="${step.value.run} + ' (?)'" class="notFound" data-tooltip="true" title="Not Found - Must be somewhere within this repository">workflow.cwl (?)</span>
220220
</div>
221221
</td>
222222
<td th:text="${step.value.label}">Label</td>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.commonwl.view.cwl;
2+
3+
import org.junit.Test;
4+
5+
import java.util.List;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class CWLElementTest {
10+
11+
/**
12+
* Test addition and retrieval of source IDs from a node
13+
* null values should not be added to the list
14+
*/
15+
@Test
16+
public void testSourceIDList() throws Exception {
17+
18+
CWLElement element = new CWLElement();
19+
20+
element.addSourceID("sourceID1");
21+
element.addSourceID("sourceID2");
22+
element.addSourceID(null);
23+
element.addSourceID("sourceID3");
24+
25+
List<String> sourceIDs = element.getSourceIDs();
26+
27+
assertEquals(3, sourceIDs.size());
28+
assertEquals("sourceID3", sourceIDs.get(2));
29+
30+
}
31+
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.commonwl.view.cwl;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class CWLProcessTest {
8+
9+
/**
10+
* Test toString method for enum
11+
*/
12+
@Test
13+
public void testToString() throws Exception {
14+
assertEquals("Workflow", CWLProcess.WORKFLOW.toString());
15+
assertEquals("Commandlinetool", CWLProcess.COMMANDLINETOOL.toString());
16+
assertEquals("Expressiontool", CWLProcess.EXPRESSIONTOOL.toString());
17+
}
18+
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.commonwl.view.docker;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class DockerServiceTest {
8+
9+
/**
10+
* Test conversion from docker pull tag to dockerhub URL
11+
*/
12+
@Test
13+
public void getDockerHubURL() throws Exception {
14+
15+
String test1 = DockerService.getDockerHubURL("stain/cwlviewer");
16+
assertEquals("https://hub.docker.com/r/stain/cwlviewer", test1);
17+
18+
String test2 = DockerService.getDockerHubURL("rabix/lobSTR");
19+
assertEquals("https://hub.docker.com/r/rabix/lobSTR", test2);
20+
21+
String test3 = DockerService.getDockerHubURL("ubuntu");
22+
assertEquals("https://hub.docker.com/r/_/ubuntu", test3);
23+
24+
}
25+
26+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.commonwl.view.github;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class GithubDetailsTest {
8+
9+
/**
10+
* Branch getter, should default to "master" if null
11+
*/
12+
@Test
13+
public void getBranch() throws Exception {
14+
GithubDetails details1 = new GithubDetails("owner", "repoName", "testbranch", "path/within/workflow.cwl");
15+
assertEquals("testbranch", details1.getBranch());
16+
17+
// Null branch should default to master
18+
GithubDetails details2 = new GithubDetails("owner", "repoName", null, null);
19+
assertEquals("master", details2.getBranch());
20+
}
21+
22+
/**
23+
* Path getter, should default to / if null
24+
*/
25+
@Test
26+
public void getPath() throws Exception {
27+
GithubDetails details1 = new GithubDetails("owner", "repoName", "branch", "subdir/");
28+
assertEquals("subdir/", details1.getPath());
29+
30+
GithubDetails details2 = new GithubDetails("owner", "repoName", "branch", "test/directory/structure.cwl");
31+
assertEquals("test/directory/structure.cwl", details2.getPath());
32+
33+
GithubDetails details3 = new GithubDetails("owner", "repoName", null, null);
34+
assertEquals("/", details3.getPath());
35+
}
36+
37+
/**
38+
* Construct a URL from Github details
39+
*/
40+
@Test
41+
public void getURL() throws Exception {
42+
GithubDetails details1 = new GithubDetails("owner", "repoName", "branch", "path/within/structure.cwl");
43+
assertEquals("https://github.com/owner/repoName/tree/branch/path/within/structure.cwl", details1.getURL());
44+
assertEquals("https://github.com/owner/repoName/tree/overrideBranch/path/within/structure.cwl",
45+
details1.getURL("overrideBranch"));
46+
47+
GithubDetails details2 = new GithubDetails("owner", "repoName", "branch", null);
48+
assertEquals("https://github.com/owner/repoName/tree/branch", details2.getURL());
49+
assertEquals("https://github.com/owner/repoName/tree/differentBranch", details2.getURL("differentBranch"));
50+
51+
}
52+
53+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package org.commonwl.view.graphviz;
2+
3+
import org.apache.commons.io.FileUtils;
4+
import org.commonwl.view.cwl.CWLElement;
5+
import org.commonwl.view.cwl.CWLProcess;
6+
import org.commonwl.view.cwl.CWLStep;
7+
import org.commonwl.view.workflow.Workflow;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
11+
import java.io.File;
12+
import java.io.StringWriter;
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
16+
import static org.junit.Assert.assertEquals;
17+
18+
public class DotWriterTest {
19+
20+
private Workflow testWorkflow;
21+
22+
/**
23+
* Manually make a workflow with multiple steps, default value,
24+
* nested workflow etc to test DOT generation
25+
* TODO: This is a pain, can it be made simpler?
26+
*/
27+
@Before
28+
public void setUp() throws Exception {
29+
30+
// Inputs
31+
Map<String, CWLElement> inputs = new HashMap<>();
32+
CWLElement input1 = new CWLElement();
33+
input1.setLabel("First Input");
34+
inputs.put("input1", input1);
35+
inputs.put("input2", new CWLElement());
36+
37+
// Steps
38+
Map<String, CWLStep> steps = new HashMap<>();
39+
40+
CWLElement step1InputElement = new CWLElement();
41+
step1InputElement.addSourceID("input1");
42+
step1InputElement.addSourceID("input2");
43+
Map<String, CWLElement> step1inputs = new HashMap<>();
44+
step1inputs.put("toolinput1", step1InputElement);
45+
CWLStep step1 = new CWLStep(null, null, null, null, step1inputs, null);
46+
steps.put("step1", step1);
47+
48+
CWLElement default1InputElement = new CWLElement();
49+
default1InputElement.setDefaultVal("examplefile.jar");
50+
Map<String, CWLElement> default1inputs = new HashMap<>();
51+
step1inputs.put("defaultInput", default1InputElement);
52+
CWLStep default1 = new CWLStep(null, null, null, null, default1inputs, null);
53+
steps.put("default1", default1);
54+
55+
CWLElement step2InputElement = new CWLElement();
56+
step2InputElement.addSourceID("step1");
57+
step2InputElement.addSourceID("default1");
58+
Map<String, CWLElement> step2inputs = new HashMap<>();
59+
step2inputs.put("toolinput1", step2InputElement);
60+
CWLStep step2 = new CWLStep(null, null, null, null, step2inputs, null);
61+
step2.setRunType(CWLProcess.WORKFLOW);
62+
steps.put("step2", step2);
63+
64+
// Output
65+
Map<String, CWLElement> outputs = new HashMap<>();
66+
CWLElement output = new CWLElement();
67+
output.setLabel("Single Output");
68+
output.setDoc("Description");
69+
output.addSourceID("step2");
70+
outputs.put("output", output);
71+
72+
// Save workflow model
73+
testWorkflow = new Workflow("Example Workflow", "Description", inputs, outputs, steps, null);
74+
}
75+
76+
/**
77+
* Test functionality to write a Workflow to DOT format
78+
*/
79+
@Test
80+
public void writeGraph() throws Exception {
81+
82+
StringWriter dotSource = new StringWriter();
83+
DotWriter dotWriter = new DotWriter(dotSource);
84+
85+
dotWriter.writeGraph(testWorkflow);
86+
87+
File expectedDot = new File("src/test/resources/graphviz/testWorkflow.dot");
88+
assertEquals(FileUtils.readFileToString(expectedDot), dotSource.toString());
89+
90+
}
91+
92+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.commonwl.view.workflow;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
8+
public class WorkflowFormTest {
9+
10+
/**
11+
* Test for the form stripping unnecessary trailing slashes from directory URLs
12+
*/
13+
@Test
14+
public void getGithubURL() throws Exception {
15+
16+
String unchangedURL = "https://github.com/common-workflow-language/workflows/tree/master/workflows/compile";
17+
WorkflowForm testForm = new WorkflowForm(unchangedURL);
18+
assertEquals(unchangedURL, testForm.getGithubURL());
19+
20+
WorkflowForm testForm2 = new WorkflowForm("https://github.com/common-workflow-language/workflows/tree/master/workflows/compile/");
21+
assertEquals("https://github.com/common-workflow-language/workflows/tree/master/workflows/compile", testForm2.getGithubURL());
22+
23+
testForm2.setGithubURL("https://github.com/common-workflow-language/workflows/tree/master/workflows/make-to-cwl/////");
24+
assertEquals("https://github.com/common-workflow-language/workflows/tree/master/workflows/make-to-cwl", testForm2.getGithubURL());
25+
26+
}
27+
28+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
digraph workflow {
2+
graph [
3+
bgcolor = "#eeeeee"
4+
color = "black"
5+
fontsize = "10"
6+
labeljust = "left"
7+
clusterrank = "local"
8+
ranksep = "0.22"
9+
nodesep = "0.05"
10+
]
11+
node [
12+
fontname = "Helvetica"
13+
fontsize = "10"
14+
fontcolor = "black"
15+
shape = "record"
16+
height = "0"
17+
width = "0"
18+
color = "black"
19+
fillcolor = "lightgoldenrodyellow"
20+
style = "filled"
21+
];
22+
edge [
23+
fontname="Helvetica"
24+
fontsize="8"
25+
fontcolor="black"
26+
color="black"
27+
arrowsize="0.7"
28+
];
29+
subgraph cluster_inputs {
30+
rank = "same";
31+
style = "dashed";
32+
label = "Workflow Inputs";
33+
"input2" [fillcolor="#94DDF4"];
34+
"input1" [fillcolor="#94DDF4",label="First Input";];
35+
}
36+
subgraph cluster_outputs {
37+
rank = "same";
38+
style = "dashed";
39+
label = "Workflow Outputs";
40+
"output" [fillcolor="#94DDF4",label="Single Output";];
41+
}
42+
"default1";
43+
"step2" [fillcolor="#F3CEA1"];
44+
"step1";
45+
"step2" -> "output";
46+
"step1" -> "step2";
47+
"default1" -> "step2";
48+
"input1" -> "step1";
49+
"input2" -> "step1";
50+
"default1" [label="examplefile.jar", fillcolor="#D5AEFC"]
51+
"default1" -> "step1";
52+
}

0 commit comments

Comments
 (0)