22
22
import org .apache .jena .query .*;
23
23
import org .apache .jena .rdf .model .Model ;
24
24
import org .apache .jena .rdf .model .ModelFactory ;
25
- import org .commonwl .view .github .GitDetails ;
26
- import org .commonwl .view .github .GitService ;
25
+ import org .commonwl .view .git .GitDetails ;
27
26
import org .commonwl .view .workflow .Workflow ;
28
- import org .commonwl .view .workflow .WorkflowOverview ;
29
27
import org .junit .Before ;
30
28
import org .junit .Rule ;
31
29
import org .junit .Test ;
@@ -63,7 +61,7 @@ public void setUp() throws Exception {
63
61
Model workflowModel = ModelFactory .createDefaultModel ();
64
62
workflowModel .read (new ByteArrayInputStream (readFileToString (packedWorkflowRdf ).getBytes ()), null , "TURTLE" );
65
63
Dataset workflowDataset = DatasetFactory .create ();
66
- workflowDataset .addNamedModel ("https ://cdn.rawgit. com/common-workflow-language/workflows/master /workflows/make-to-cwl/dna.cwl#main" , workflowModel );
64
+ workflowDataset .addNamedModel ("http ://localhost:3030/cwlviewer/github. com/common-workflow-language/workflows/blob/549c973ccc01781595ce562dea4cedc6c9540fe0 /workflows/make-to-cwl/dna.cwl#main" , workflowModel );
67
65
68
66
Answer queryRdf = new Answer <ResultSet >() {
69
67
@ Override
@@ -76,7 +74,7 @@ public ResultSet answer(InvocationOnMock invocation) throws Throwable {
76
74
}
77
75
};
78
76
79
- this .rdfService = Mockito .spy (new RDFService ("http://madeup.endpoint /" ));
77
+ this .rdfService = Mockito .spy (new RDFService ("http://localhost:3030/cwlviewer /" ));
80
78
Mockito .doAnswer (queryRdf ).when (rdfService ).runQuery (anyObject ());
81
79
Mockito .doReturn (true ).when (rdfService ).graphExists (anyString ());
82
80
}
@@ -92,45 +90,21 @@ public ResultSet answer(InvocationOnMock invocation) throws Throwable {
92
90
*/
93
91
@ Test
94
92
public void parseLobSTRDraft3WorkflowNative () throws Exception {
95
-
96
- // Get mock Github service
97
- GitService mockGithubService = getMockGithubService ("workflows/lobSTR/" ,
98
- "src/test/resources/cwl/lobstr-draft3/" );
99
-
100
- // Test cwl service
101
- CWLService cwlService = new CWLService (mockGithubService ,
102
- rdfService , new CWLTool (), 5242880 );
103
-
104
- // Get workflow from community repo by commit ID so it will not change
105
- GitDetails lobSTRDraft3Details = new GitDetails ("common-workflow-language" ,
106
- "workflows" , null , "workflows/lobSTR/lobSTR-workflow.cwl" );
107
- Workflow lobSTRDraft3 = cwlService .parseWorkflowNative (lobSTRDraft3Details , "920c6be45f08e979e715a0018f22c532b024074f" );
108
-
93
+ CWLService cwlService = new CWLService (rdfService , Mockito .mock (CWLTool .class ), 5242880 );
94
+ Workflow lobSTRDraft3 = cwlService .parseWorkflowNative (
95
+ new File ("src/test/resources/cwl/lobstr-draft3/lobSTR-workflow.cwl" ));
109
96
testLobSTRWorkflow (lobSTRDraft3 , true );
110
-
111
97
}
112
98
113
99
/**
114
100
* Test native loading parsing of a the LobSTR workflow CWL version 1.0
115
101
*/
116
102
@ Test
117
103
public void parseLobSTRv1WorkflowNative () throws Exception {
118
-
119
- // Get mock Github service
120
- GitService mockGithubService = getMockGithubService ("workflows/lobSTR/" ,
121
- "src/test/resources/cwl/lobstr-draft3/" );
122
-
123
- // Test cwl service
124
- CWLService cwlService = new CWLService (mockGithubService ,
125
- rdfService , new CWLTool (), 5242880 );
126
-
127
- // Get workflow from community repo by commit ID so it will not change
128
- GitDetails lobSTRv1Details = new GitDetails ("common-workflow-language" ,
129
- "workflows" , null , "workflows/lobSTR/lobSTR-workflow.cwl" );
130
- Workflow lobSTRv1 = cwlService .parseWorkflowNative (lobSTRv1Details , "933bf2a1a1cce32d88f88f136275535da9df0954" );
131
-
104
+ CWLService cwlService = new CWLService (rdfService , new CWLTool (), 5242880 );
105
+ Workflow lobSTRv1 = cwlService .parseWorkflowNative (
106
+ new File ("src/test/resources/cwl/lobstr-v1/lobSTR-workflow.cwl" ));
132
107
testLobSTRWorkflow (lobSTRv1 , true );
133
-
134
108
}
135
109
136
110
/**
@@ -146,15 +120,18 @@ public void parseWorkflowWithCwltool() throws Exception {
146
120
.thenReturn (readFileToString (packedWorkflowRdf ));
147
121
148
122
// CWLService to test
149
- CWLService cwlService = new CWLService (Mockito .mock (GitService .class ),
150
- rdfService , mockCwlTool , 5242880 );
123
+ CWLService cwlService = new CWLService (rdfService , mockCwlTool , 5242880 );
151
124
152
- GitDetails githubInfo = new GitDetails ("common-workflow-language" ,
153
- "workflows" , "549c973ccc01781595ce562dea4cedc6c9540fe0" ,
154
- "workflows/make-to-cwl/dna.cwl" );
125
+ GitDetails gitInfo = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
126
+ "549c973ccc01781595ce562dea4cedc6c9540fe0" , "workflows/make-to-cwl/dna.cwl" );
127
+ Workflow basicModel = new Workflow (null , null , null , null , null , null );
128
+ basicModel .setRetrievedFrom (gitInfo );
129
+ basicModel .setPackedWorkflowID ("main" );
130
+ basicModel .setLastCommit ("549c973ccc01781595ce562dea4cedc6c9540fe0" );
155
131
156
132
// Parse the workflow
157
- Workflow workflow = cwlService .parseWorkflowWithCwltool (githubInfo , "master" , "main" );
133
+ Workflow workflow = cwlService .parseWorkflowWithCwltool (basicModel ,
134
+ new File ("src/test/resources/cwl/make_to_cwl/dna.cwl" ));
158
135
159
136
// Check basic information
160
137
assertNotNull (workflow );
@@ -167,58 +144,18 @@ public void parseWorkflowWithCwltool() throws Exception {
167
144
}
168
145
169
146
/**
170
- * Test retrieval of a workflow overview for hello world example in cwl
147
+ * Test IOException is thrown when files are over limit
171
148
*/
172
149
@ Test
173
- public void getHelloWorkflowOverview () throws Exception {
174
-
175
- // Mock githubService class
176
- GitService mockGithubService = Mockito .mock (GitService .class );
177
- File workflowFile = new File ("src/test/resources/cwl/hello/hello.cwl" );
178
- when (mockGithubService .downloadFile (anyObject ()))
179
- .thenReturn (readFileToString (workflowFile ));
180
-
181
- // Test cwl service
182
- CWLService cwlService = new CWLService (mockGithubService ,
183
- rdfService , Mockito .mock (CWLTool .class ), 5242880 );
184
-
185
- // Run workflow overview
186
- GitDetails helloDetails = new GitDetails ("common-workflow-language" ,
187
- "workflows" , "8296e92d358bb5da4dc3c6e7aabefa89726e3409" , "workflows/hello/hello.cwl" );
188
- WorkflowOverview hello = cwlService .getWorkflowOverview (helloDetails );
189
- assertNotNull (hello );
190
-
191
- // No docs for this workflow
192
- assertEquals ("Hello World" , hello .getLabel ());
193
- assertEquals ("Puts a message into a file using echo" , hello .getDoc ());
194
- assertEquals ("hello.cwl" , hello .getFileName ());
195
-
196
- }
197
-
198
- /**
199
- * Test IOException is thrown when files are over limit with getWorkflowOverview
200
- */
201
- @ Test
202
- public void workflowOverviewOverSingleFileSizeLimitThrowsIOException () throws Exception {
203
-
204
- // Mock githubService class
205
- GitService mockGithubService = Mockito .mock (GitService .class );
206
- File workflowFile = new File ("src/test/resources/cwl/hello/hello.cwl" );
207
- when (mockGithubService .downloadFile (anyObject ()))
208
- .thenReturn (readFileToString (workflowFile ));
209
-
210
- // Test cwl service with 0 filesize limit
211
- CWLService cwlService = new CWLService (mockGithubService ,
212
- Mockito .mock (RDFService .class ), Mockito .mock (CWLTool .class ), 0 );
213
-
214
- // Run workflow overview
215
- GitDetails helloDetails = new GitDetails ("common-workflow-language" ,
216
- "workflows" , "8296e92d358bb5da4dc3c6e7aabefa89726e3409" , "workflows/hello/hello.cwl" );
150
+ public void workflowOverSingleFileSizeLimitThrowsIOException () throws Exception {
217
151
218
152
// Should throw IOException due to oversized files
219
153
thrown .expect (IOException .class );
220
- thrown .expectMessage ("File 'workflows/hello/hello.cwl' is over singleFileSizeLimit - 672 bytes/0 bytes" );
221
- cwlService .getWorkflowOverview (helloDetails );
154
+ thrown .expectMessage ("File 'lobSTR-workflow.cwl' is over singleFileSizeLimit - 2 KB/0 bytes" );
155
+
156
+ CWLService cwlService = new CWLService (rdfService , Mockito .mock (CWLTool .class ), 0 );
157
+ cwlService .parseWorkflowNative (
158
+ new File ("src/test/resources/cwl/lobstr-draft3/lobSTR-workflow.cwl" ));
222
159
223
160
}
224
161
@@ -265,26 +202,4 @@ private void testLobSTRWorkflow(Workflow lobSTR, boolean nativeParsed) throws Ex
265
202
}
266
203
}
267
204
268
- /**
269
- * Get a mock GithubService which redirects downloads to the filesystem
270
- */
271
- private GitService getMockGithubService (String originalFolder ,
272
- String resourcesFolder ) throws IOException {
273
- GitService mockGithubService = Mockito .mock (GitService .class );
274
- Answer fileAnswer = new Answer <String >() {
275
- @ Override
276
- public String answer (InvocationOnMock invocation ) throws Throwable {
277
- Object [] args = invocation .getArguments ();
278
- GitDetails details = (GitDetails ) args [0 ];
279
- File workflowFile = new File (resourcesFolder
280
- + details .getPath ().replace (originalFolder , "" ));
281
- return readFileToString (workflowFile );
282
- }
283
- };
284
- when (mockGithubService .downloadFile (anyObject ())).thenAnswer (fileAnswer );
285
- when (mockGithubService .downloadFile (anyObject (), anyObject ())).thenAnswer (fileAnswer );
286
-
287
- return mockGithubService ;
288
- }
289
-
290
205
}
0 commit comments