Skip to content

Commit 2a8d0cb

Browse files
committed
Further test coverage
1 parent 6d14b76 commit 2a8d0cb

File tree

8 files changed

+108
-13
lines changed

8 files changed

+108
-13
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ public String toString() {
3535
case COMMANDLINETOOL:
3636
return "CommandLineTool";
3737
case EXPRESSIONTOOL:
38-
return "ExpressionTool";
3938
default:
40-
return super.toString();
39+
return "ExpressionTool";
4140
}
4241
}
4342
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void writeSteps(Workflow workflow) throws IOException {
105105
if (label == null) {
106106
writeLine(" \"" + step.getKey() + "\";");
107107
} else {
108-
writeLine(" \"" + step.getKey() + "\" [label=\"" + label + "\"]");
108+
writeLine(" \"" + step.getKey() + "\" [label=\"" + label + "\"];");
109109
}
110110
}
111111

src/main/java/org/commonwl/view/workflow/WorkflowController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
491491
.addObject("gitDetails", gitDetails);
492492
} else if (workflowOverviews.size() == 1) {
493493
return new ModelAndView("redirect:" + gitDetails.getInternalUrl() +
494-
"/" + workflowOverviews.get(0).getFileName());
494+
workflowOverviews.get(0).getFileName());
495495
} else {
496496
errors.rejectValue("url", "url.noWorkflowsInDirectory", "No workflow files were found in the given directory");
497497
}

src/test/java/org/commonwl/view/graphviz/ModelDotWriterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public void setUp() throws Exception {
7979
CWLStep step2 = new CWLStep(null, null, null, step2inputs);
8080
step2.setRunType(CWLProcess.WORKFLOW);
8181
step2.setRun("subworkflow.cwl");
82+
step2.setLabel("Label for step 2");
8283
steps.put("step2", step2);
8384

8485
// Output

src/test/java/org/commonwl/view/workflow/WorkflowControllerTest.java

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
package org.commonwl.view.workflow;
2121

22-
import org.commonwl.view.cwl.CWLValidationException;
2322
import org.commonwl.view.git.GitDetails;
2423
import org.commonwl.view.graphviz.GraphVizService;
2524
import org.commonwl.view.researchobject.ROBundleNotFoundException;
26-
import org.eclipse.jgit.api.errors.RefNotFoundException;
25+
import org.eclipse.jgit.api.errors.TransportException;
26+
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
2727
import org.junit.Rule;
2828
import org.junit.Test;
2929
import org.junit.rules.TemporaryFolder;
@@ -34,9 +34,14 @@
3434
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
3535
import org.springframework.test.context.junit4.SpringRunner;
3636
import org.springframework.test.web.servlet.MockMvc;
37+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
3738
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
3839
import org.springframework.web.servlet.view.InternalResourceViewResolver;
3940

41+
import java.io.IOException;
42+
import java.util.ArrayList;
43+
import java.util.List;
44+
4045
import static org.hamcrest.core.Is.is;
4146
import static org.mockito.Matchers.anyObject;
4247
import static org.mockito.Matchers.anyString;
@@ -114,7 +119,10 @@ public void newWorkflowFromGithubURL() throws Exception {
114119
// Mock workflow service returning valid workflow
115120
WorkflowService mockWorkflowService = Mockito.mock(WorkflowService.class);
116121
when(mockWorkflowService.createQueuedWorkflow(anyObject()))
117-
.thenThrow(new CWLValidationException("Error"))
122+
.thenThrow(new WorkflowNotFoundException())
123+
.thenThrow(new WrongRepositoryStateException("Some Error"))
124+
.thenThrow(new TransportException("No SSH Key"))
125+
.thenThrow(new IOException())
118126
.thenReturn(mockQueuedWorkflow);
119127

120128
// Mock controller/MVC
@@ -142,7 +150,29 @@ public void newWorkflowFromGithubURL() throws Exception {
142150
mockMvc.perform(post("/workflows")
143151
.param("url", "https://github.com/owner/repoName/blob/branch/path/nonexistant.cwl"))
144152
.andExpect(status().isOk())
145-
.andExpect(view().name("index"));
153+
.andExpect(view().name("index"))
154+
.andExpect(model().attributeHasFieldErrors("workflowForm", "url"));
155+
156+
// Git API error
157+
mockMvc.perform(post("/workflows")
158+
.param("url", "https://github.com/owner/repoName/blob/branch/path/cantbecloned.cwl"))
159+
.andExpect(status().isOk())
160+
.andExpect(view().name("index"))
161+
.andExpect(model().attributeHasFieldErrors("workflowForm", "url"));
162+
163+
// Unsupported SSH URL
164+
mockMvc.perform(post("/workflows")
165+
.param("url", "ssh://github.com/owner/repoName/blob/branch/path/workflow.cwl"))
166+
.andExpect(status().isOk())
167+
.andExpect(view().name("index"))
168+
.andExpect(model().attributeHasFieldErrors("workflowForm", "url"));
169+
170+
// Unexpected error
171+
mockMvc.perform(post("/workflows")
172+
.param("url", "ssh://github.com/owner/repoName/blob/branch/path/unexpected.cwl"))
173+
.andExpect(status().isOk())
174+
.andExpect(view().name("index"))
175+
.andExpect(model().attributeHasFieldErrors("workflowForm", "url"));
146176

147177
// Valid workflow URL redirect
148178
mockMvc.perform(post("/workflows")
@@ -169,7 +199,18 @@ public void directWorkflowURL() throws Exception {
169199
.thenReturn(null);
170200
when(mockWorkflowService.createQueuedWorkflow(anyObject()))
171201
.thenReturn(mockQueuedWorkflow)
172-
.thenThrow(new RefNotFoundException("A Git API Error"));
202+
.thenThrow(new WorkflowNotFoundException())
203+
.thenThrow(new WrongRepositoryStateException("Some Error"))
204+
.thenThrow(new TransportException("No SSH Key"))
205+
.thenThrow(new IOException());
206+
List<WorkflowOverview> listOfTwoOverviews = new ArrayList<>();
207+
listOfTwoOverviews.add(new WorkflowOverview("/workflow1.cwl", "label", "doc"));
208+
listOfTwoOverviews.add(new WorkflowOverview("/workflow2.cwl", "label2", "doc2"));
209+
List<WorkflowOverview> listOfOneOverview = new ArrayList<>();
210+
listOfOneOverview.add(new WorkflowOverview("/workflow1.cwl", "label", "doc"));
211+
when(mockWorkflowService.getWorkflowsFromDirectory(anyObject()))
212+
.thenReturn(listOfTwoOverviews)
213+
.thenReturn(listOfOneOverview);
173214

174215
// Mock controller/MVC
175216
WorkflowController workflowController = new WorkflowController(
@@ -192,10 +233,37 @@ public void directWorkflowURL() throws Exception {
192233
.andExpect(view().name("loading"))
193234
.andExpect(model().attribute("queued", is(mockQueuedWorkflow)));
194235

195-
// Error creating workflow
196-
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/badworkflow.cwl"))
197-
.andExpect(status().isFound());
236+
// Directory URL, select between
237+
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within"))
238+
.andExpect(status().isOk())
239+
.andExpect(view().name("selectworkflow"))
240+
.andExpect(model().attributeExists("gitDetails"))
241+
.andExpect(model().attributeExists("workflowOverviews"));
242+
243+
// Directory URL with only one workflow redirects
244+
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within"))
245+
.andExpect(status().isFound())
246+
.andExpect(redirectedUrl("/workflows/github.com/owner/reponame/blob/branch/path/within/workflow1.cwl"));
198247

248+
// Workflow not found
249+
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/nonexistant.cwl"))
250+
.andExpect(status().isFound())
251+
.andExpect(MockMvcResultMatchers.flash().attributeExists("errors"));
252+
253+
// Git API error
254+
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/cantbecloned.cwl"))
255+
.andExpect(status().isFound())
256+
.andExpect(MockMvcResultMatchers.flash().attributeExists("errors"));
257+
258+
// Submodules with SSH Url
259+
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/submodulewithssh.cwl"))
260+
.andExpect(status().isFound())
261+
.andExpect(MockMvcResultMatchers.flash().attributeExists("errors"));
262+
263+
// Unexpected error
264+
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/badworkflow.cwl"))
265+
.andExpect(status().isFound())
266+
.andExpect(MockMvcResultMatchers.flash().attributeExists("errors"));
199267
}
200268

201269
/**

src/test/java/org/commonwl/view/workflow/WorkflowFormValidatorTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ public void genericUrl() throws Exception {
9393

9494
}
9595

96+
/**
97+
* Packed URL
98+
*/
99+
@Test
100+
public void packedUrl() throws Exception {
101+
102+
WorkflowForm githubUrl = new WorkflowForm("https://github.com/MarkRobbo/workflows/tree/master/packed.cwl#workflowId");
103+
Errors errors = new BeanPropertyBindingResult(githubUrl, "workflowForm");
104+
GitDetails details = workflowFormValidator.validateAndParse(githubUrl, errors);
105+
106+
assertNotNull(details);
107+
assertEquals("https://github.com/MarkRobbo/workflows.git", details.getRepoUrl());
108+
assertEquals("master", details.getBranch());
109+
assertEquals("packed.cwl", details.getPath());
110+
assertEquals("workflowId", details.getPackedId());
111+
assertFalse(errors.hasErrors());
112+
113+
}
114+
96115
/**
97116
* Empty URL
98117
*/

src/test/java/org/commonwl/view/workflow/WorkflowServiceTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public class WorkflowServiceTest {
5252
@Rule
5353
public TemporaryFolder roBundleFolder = new TemporaryFolder();
5454

55+
/**
56+
* Retry the running of cwltool
57+
*/
58+
@Test
59+
public void retryCwltoolGeneration() throws Exception {
60+
61+
}
62+
5563
/**
5664
* Getting a list of workflow overviews from a directory
5765
*/

src/test/resources/graphviz/testWorkflow.dot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ digraph workflow {
4040
"output" [fillcolor="#94DDF4",label="Single Output";];
4141
}
4242
"default1";
43-
"step2";
43+
"step2" [label="Label for step 2"];
4444
"step1";
4545
"step2" -> "output";
4646
"step1" -> "step2";

0 commit comments

Comments
 (0)