19
19
20
20
package org .commonwl .view .workflow ;
21
21
22
- import org .commonwl .view .cwl .CWLValidationException ;
23
22
import org .commonwl .view .git .GitDetails ;
24
23
import org .commonwl .view .graphviz .GraphVizService ;
25
24
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 ;
27
27
import org .junit .Rule ;
28
28
import org .junit .Test ;
29
29
import org .junit .rules .TemporaryFolder ;
34
34
import org .springframework .data .web .PageableHandlerMethodArgumentResolver ;
35
35
import org .springframework .test .context .junit4 .SpringRunner ;
36
36
import org .springframework .test .web .servlet .MockMvc ;
37
+ import org .springframework .test .web .servlet .result .MockMvcResultMatchers ;
37
38
import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
38
39
import org .springframework .web .servlet .view .InternalResourceViewResolver ;
39
40
41
+ import java .io .IOException ;
42
+ import java .util .ArrayList ;
43
+ import java .util .List ;
44
+
40
45
import static org .hamcrest .core .Is .is ;
41
46
import static org .mockito .Matchers .anyObject ;
42
47
import static org .mockito .Matchers .anyString ;
@@ -114,7 +119,10 @@ public void newWorkflowFromGithubURL() throws Exception {
114
119
// Mock workflow service returning valid workflow
115
120
WorkflowService mockWorkflowService = Mockito .mock (WorkflowService .class );
116
121
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 ())
118
126
.thenReturn (mockQueuedWorkflow );
119
127
120
128
// Mock controller/MVC
@@ -142,7 +150,29 @@ public void newWorkflowFromGithubURL() throws Exception {
142
150
mockMvc .perform (post ("/workflows" )
143
151
.param ("url" , "https://github.com/owner/repoName/blob/branch/path/nonexistant.cwl" ))
144
152
.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" ));
146
176
147
177
// Valid workflow URL redirect
148
178
mockMvc .perform (post ("/workflows" )
@@ -169,7 +199,18 @@ public void directWorkflowURL() throws Exception {
169
199
.thenReturn (null );
170
200
when (mockWorkflowService .createQueuedWorkflow (anyObject ()))
171
201
.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 );
173
214
174
215
// Mock controller/MVC
175
216
WorkflowController workflowController = new WorkflowController (
@@ -192,10 +233,37 @@ public void directWorkflowURL() throws Exception {
192
233
.andExpect (view ().name ("loading" ))
193
234
.andExpect (model ().attribute ("queued" , is (mockQueuedWorkflow )));
194
235
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" ));
198
247
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" ));
199
267
}
200
268
201
269
/**
0 commit comments