Skip to content

Commit 2514b73

Browse files
committed
Add tests for workflow overviews
1 parent 9b3934d commit 2514b73

File tree

3 files changed

+105
-6
lines changed

3 files changed

+105
-6
lines changed

src/test/java/org/commonwl/view/cwl/CWLServiceTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.jena.rdf.model.ModelFactory;
2525
import org.commonwl.view.git.GitDetails;
2626
import org.commonwl.view.workflow.Workflow;
27+
import org.commonwl.view.workflow.WorkflowOverview;
2728
import org.junit.Before;
2829
import org.junit.Rule;
2930
import org.junit.Test;
@@ -159,6 +160,48 @@ public void workflowOverSingleFileSizeLimitThrowsIOException() throws Exception
159160

160161
}
161162

163+
/**
164+
* Test retrieval of a workflow overview for hello world example in cwl
165+
*/
166+
@Test
167+
public void getHelloWorkflowOverview() throws Exception {
168+
169+
// Test cwl service
170+
CWLService cwlService = new CWLService(Mockito.mock(RDFService.class),
171+
Mockito.mock(CWLTool.class), 5242880);
172+
173+
// Run workflow overview
174+
File helloWorkflow = new File("src/test/resources/cwl/hello/hello.cwl");
175+
WorkflowOverview hello = cwlService.getWorkflowOverview(helloWorkflow);
176+
assertNotNull(hello);
177+
178+
// No docs for this workflow
179+
assertEquals("Hello World", hello.getLabel());
180+
assertEquals("Puts a message into a file using echo", hello.getDoc());
181+
assertEquals("hello.cwl", hello.getFileName());
182+
183+
}
184+
185+
/**
186+
* Test IOException is thrown when files are over limit with getWorkflowOverview
187+
*/
188+
@Test
189+
public void workflowOverviewOverSingleFileSizeLimitThrowsIOException() throws Exception {
190+
191+
// Test cwl service
192+
CWLService cwlService = new CWLService(Mockito.mock(RDFService.class),
193+
Mockito.mock(CWLTool.class), 0);
194+
195+
// File to test
196+
File helloWorkflow = new File("src/test/resources/cwl/hello/hello.cwl");
197+
198+
// Should throw IOException due to oversized file
199+
thrown.expect(IOException.class);
200+
thrown.expectMessage("File 'hello.cwl' is over singleFileSizeLimit - 672 bytes/0 bytes");
201+
cwlService.getWorkflowOverview(helloWorkflow);
202+
203+
}
204+
162205
/**
163206
* Validate a LobSTR workflow
164207
* See: https://github.com/common-workflow-language/workflows/tree/master/workflows/lobSTR

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ public void newWorkflowFromGithubURL() throws Exception {
100100
WorkflowFormValidator mockValidator = Mockito.mock(WorkflowFormValidator.class);
101101
when(mockValidator.validateAndParse(anyObject(), anyObject()))
102102
.thenReturn(null)
103-
.thenReturn(new GitDetails("https://repo.url/repo.git", "branch", "path/within"))
104-
.thenReturn(new GitDetails("https://repo.url/repo.git", "branch", "path/workflow.cwl"));
103+
.thenReturn(new GitDetails("https://github.com/owner/repoName.git", "branch", "path/within"))
104+
.thenReturn(new GitDetails("https://github.com/owner/repoName.git", "branch", "path/workflow.cwl"));
105105

106106
// The eventual accepted valid workflow
107107
Workflow mockWorkflow = Mockito.mock(Workflow.class);
108108
when(mockWorkflow.getRetrievedFrom())
109-
.thenReturn(new GitDetails("https://repo.url/repo.git", "branch", "path/workflow.cwl"));
109+
.thenReturn(new GitDetails("https://github.com/owner/repoName.git", "branch", "path/workflow.cwl"));
110110
QueuedWorkflow mockQueuedWorkflow = Mockito.mock(QueuedWorkflow.class);
111111
when(mockQueuedWorkflow.getTempRepresentation())
112112
.thenReturn(mockWorkflow);
@@ -132,17 +132,23 @@ public void newWorkflowFromGithubURL() throws Exception {
132132
.andExpect(status().isOk())
133133
.andExpect(view().name("index"));
134134

135+
// Valid directory URL redirect
136+
mockMvc.perform(post("/workflows")
137+
.param("url", "https://github.com/owner/repoName/blob/branch/path/within"))
138+
.andExpect(status().isFound())
139+
.andExpect(redirectedUrl("/workflows/github.com/owner/repoName/blob/branch/path/within"));
140+
135141
// Invalid workflow URL, go to index to show error
136142
mockMvc.perform(post("/workflows")
137-
.param("url", "https://github.com/owner/repoName/tree/branch/path/nonexistant.cwl"))
143+
.param("url", "https://github.com/owner/repoName/blob/branch/path/nonexistant.cwl"))
138144
.andExpect(status().isOk())
139145
.andExpect(view().name("index"));
140146

141147
// Valid workflow URL redirect
142148
mockMvc.perform(post("/workflows")
143-
.param("url", "https://repo.url/repo.git/branch/path/workflow.cwl"))
149+
.param("url", "https://github.com/owner/repoName/blob/branch/path/workflow.cwl"))
144150
.andExpect(status().isFound())
145-
.andExpect(redirectedUrl("/workflows/repo.url/repo.git/branch/path/workflow.cwl"));
151+
.andExpect(redirectedUrl("/workflows/github.com/owner/repoName/blob/branch/path/workflow.cwl"));
146152

147153
}
148154

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import java.io.File;
3737
import java.util.Date;
3838
import java.util.HashMap;
39+
import java.util.List;
3940

41+
import static junit.framework.TestCase.assertTrue;
4042
import static org.junit.Assert.assertEquals;
4143
import static org.mockito.Matchers.anyBoolean;
4244
import static org.mockito.Matchers.anyObject;
@@ -50,6 +52,54 @@ public class WorkflowServiceTest {
5052
@Rule
5153
public TemporaryFolder roBundleFolder = new TemporaryFolder();
5254

55+
/**
56+
* Getting a list of workflow overviews from a directory
57+
*/
58+
@Test
59+
public void getWorkflowsFromDirectory() throws Exception {
60+
61+
// Mock CWL service which returns simple overview once simulating 1 workflow found
62+
CWLService mockCWLService = Mockito.mock(CWLService.class);
63+
when(mockCWLService.getWorkflowOverview(anyObject()))
64+
.thenReturn(new WorkflowOverview("workflow.cwl", "label", "doc"))
65+
.thenReturn(new WorkflowOverview("workflow2.cwl", "label2", "doc2"))
66+
.thenReturn(null);
67+
68+
Repository mockRepo = Mockito.mock(Repository.class);
69+
when(mockRepo.getWorkTree()).thenReturn(new File("src/test/resources/cwl/hello"));
70+
71+
Git mockGitRepo = Mockito.mock(Git.class);
72+
when(mockGitRepo.getRepository()).thenReturn(mockRepo);
73+
74+
GitService mockGitService = Mockito.mock(GitService.class);
75+
when(mockGitService.getRepository(anyObject(), anyBoolean())).thenReturn(mockGitRepo);
76+
77+
// Create service under test
78+
WorkflowService testWorkflowService = new WorkflowService(
79+
mockGitService, mockCWLService,
80+
Mockito.mock(WorkflowRepository.class),
81+
Mockito.mock(QueuedWorkflowRepository.class),
82+
Mockito.mock(ROBundleFactory.class),
83+
Mockito.mock(GraphVizService.class),
84+
Mockito.mock(CWLToolRunner.class),
85+
Mockito.mock(GitSemaphore.class), 1);
86+
87+
// Get a list of workflows from the directory
88+
List<WorkflowOverview> list = testWorkflowService.getWorkflowsFromDirectory(
89+
new GitDetails(null, null, "/"));
90+
91+
// 1 workflow should be found
92+
assertTrue(list.size() == 2);
93+
assertEquals("workflow.cwl", list.get(0).getFileName());
94+
assertEquals("label", list.get(0).getLabel());
95+
assertEquals("doc", list.get(0).getDoc());
96+
97+
assertEquals("workflow2.cwl", list.get(1).getFileName());
98+
assertEquals("label2", list.get(1).getLabel());
99+
assertEquals("doc2", list.get(1).getDoc());
100+
101+
}
102+
53103
/**
54104
* Getting a workflow when cache has expired
55105
* And a new workflow needs to be created

0 commit comments

Comments
 (0)