53
53
54
54
public class ROBundleServiceTest {
55
55
56
- private static Git gitRepo ;
56
+ private static ROBundleService roBundleService ;
57
+ private static ROBundleService roBundleServiceZeroSizeLimit ;
57
58
58
59
@ Before
59
60
public void setUp () throws Exception {
60
61
Repository mockRepo = Mockito .mock (Repository .class );
61
62
when (mockRepo .getWorkTree ()).thenReturn (new File ("src/test/resources/cwl/" ));
62
63
63
- gitRepo = Mockito .mock (Git .class );
64
+ Git gitRepo = Mockito .mock (Git .class );
64
65
when (gitRepo .getRepository ()).thenReturn (mockRepo );
65
- }
66
-
67
- /**
68
- * Use a temporary directory for testing
69
- */
70
- @ Rule
71
- public TemporaryFolder roBundleFolder = new TemporaryFolder ();
72
-
73
- /**
74
- * Generate a Research Object bundle from lobstr and check it
75
- */
76
- @ Test
77
- public void generateAndSaveROBundle () throws Exception {
78
66
79
67
// Get mock Git service
80
68
GitService mockGitService = Mockito .mock (GitService .class );
@@ -106,23 +94,42 @@ public void generateAndSaveROBundle() throws Exception {
106
94
when (mockRdfService .getModel (anyObject (), anyObject ()))
107
95
.thenReturn ("@prefix cwl: <https://w3id.org/cwl/cwl#> ." .getBytes ());
108
96
97
+ // Create new RO bundle
98
+ roBundleService = new ROBundleService (roBundleFolder .getRoot ().toPath (),
99
+ "CWL Viewer" , "https://view.commonwl.org" , 5242880 ,
100
+ mockGraphvizService , mockGitService , mockRdfService ,
101
+ Mockito .mock (GitSemaphore .class ), mockCwlTool );
102
+ roBundleServiceZeroSizeLimit = new ROBundleService (roBundleFolder .getRoot ().toPath (),
103
+ "CWL Viewer" , "https://view.commonwl.org" , 0 ,
104
+ mockGraphvizService , mockGitService , mockRdfService ,
105
+ Mockito .mock (GitSemaphore .class ), mockCwlTool );
106
+ }
107
+
108
+ /**
109
+ * Use a temporary directory for testing
110
+ */
111
+ @ Rule
112
+ public TemporaryFolder roBundleFolder = new TemporaryFolder ();
113
+
114
+ /**
115
+ * Generate a Research Object bundle from lobstr and check it
116
+ */
117
+ @ Test
118
+ public void generateAndSaveROBundle () throws Exception {
119
+
109
120
// Workflow details
110
- GitDetails lobSTRv1Details = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
121
+ GitDetails lobSTRdraft3Details = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
111
122
"933bf2a1a1cce32d88f88f136275535da9df0954" , "workflows/lobSTR/lobSTR-workflow.cwl" );
112
- Workflow lobSTRv1 = Mockito .mock (Workflow .class );
113
- when (lobSTRv1 .getID ()).thenReturn ("testID" );
114
- when (lobSTRv1 .getRetrievedFrom ()).thenReturn (lobSTRv1Details );
123
+ Workflow lobSTRdraft3 = Mockito .mock (Workflow .class );
124
+ when (lobSTRdraft3 .getID ()).thenReturn ("testID" );
125
+ when (lobSTRdraft3 .getRetrievedFrom ()).thenReturn (lobSTRdraft3Details );
115
126
116
127
// RO details
117
- GitDetails lobSTRv1RODetails = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
128
+ GitDetails lobSTRdraft3RODetails = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
118
129
"933bf2a1a1cce32d88f88f136275535da9df0954" , "lobstr-draft3/" );
119
130
120
131
// Create new RO bundle
121
- ROBundleService bundleService = new ROBundleService (roBundleFolder .getRoot ().toPath (),
122
- "CWL Viewer" , "https://view.commonwl.org" , 5242880 ,
123
- mockGraphvizService , mockGitService , mockRdfService ,
124
- Mockito .mock (GitSemaphore .class ), mockCwlTool );
125
- Bundle bundle = bundleService .createBundle (lobSTRv1 , lobSTRv1RODetails );
132
+ Bundle bundle = roBundleService .createBundle (lobSTRdraft3 , lobSTRdraft3RODetails );
126
133
Path bundleRoot = bundle .getRoot ().resolve ("workflow" );
127
134
128
135
// Check bundle exists
@@ -138,7 +145,7 @@ public void generateAndSaveROBundle() throws Exception {
138
145
// Check cwl aggregation information
139
146
PathMetadata cwlAggregate = manifest .getAggregation (
140
147
bundleRoot .resolve ("lobSTR-workflow.cwl" ));
141
- assertEquals ("https://w3id.org/cwl/v/git/null/workflows/lobSTR /lobSTR-workflow.cwl?format=raw" ,
148
+ assertEquals ("https://w3id.org/cwl/v/git/null/lobstr-draft3 /lobSTR-workflow.cwl?format=raw" ,
142
149
cwlAggregate .getRetrievedFrom ().toString ());
143
150
assertEquals ("Mark Robinson" , cwlAggregate .getAuthoredBy ().get (0 ).getName ());
144
151
assertEquals (
"mailto:[email protected] " ,
cwlAggregate .
getAuthoredBy ().
get (
0 ).
getUri ().
toString ());
@@ -165,7 +172,7 @@ public void generateAndSaveROBundle() throws Exception {
165
172
history .get (0 ).toString ());
166
173
167
174
// Save and check it exists in the temporary folder
168
- bundleService .saveToFile (bundle );
175
+ roBundleService .saveToFile (bundle );
169
176
File [] fileList = roBundleFolder .getRoot ().listFiles ();
170
177
assertTrue (fileList .length == 1 );
171
178
for (File ro : fileList ) {
@@ -182,58 +189,27 @@ public void generateAndSaveROBundle() throws Exception {
182
189
@ Test
183
190
public void filesOverLimit () throws Exception {
184
191
185
- // Get mock Git service
186
- GitService mockGitService = Mockito .mock (GitService .class );
187
- when (mockGitService .getRepository (anyObject (), anyBoolean ())).thenReturn (gitRepo );
188
-
189
- Set <HashableAgent > authors = new HashSet <>();
190
- authors .
add (
new HashableAgent (
"Mark Robinson" ,
null ,
new URI (
"mailto:[email protected] " )));
191
- when (mockGitService .getAuthors (anyObject (), anyObject ()))
192
- .thenReturn (authors );
193
-
194
- // Mock Graphviz service
195
- GraphVizService mockGraphvizService = Mockito .mock (GraphVizService .class );
196
- when (mockGraphvizService .getGraph (anyString (), anyString (), anyString ()))
197
- .thenReturn (new File ("src/test/resources/graphviz/testVis.png" ))
198
- .thenReturn (new File ("src/test/resources/graphviz/testVis.svg" ));
199
-
200
- // Mock CWLTool
201
- CWLTool mockCwlTool = Mockito .mock (CWLTool .class );
202
- when (mockCwlTool .getPackedVersion (anyString ()))
203
- .thenReturn ("cwlVersion: v1.0" );
204
- when (mockCwlTool .getRDF (anyString ()))
205
- .thenReturn ("@prefix cwl: <https://w3id.org/cwl/cwl#> ." );
206
-
207
- // Mock RDF Service
208
- ResultSet emptyResult = Mockito .mock (ResultSet .class );
209
- when (emptyResult .hasNext ()).thenReturn (false );
210
- RDFService mockRdfService = Mockito .mock (RDFService .class );
211
- when (mockRdfService .getAuthors (anyString (), anyString ())).thenReturn (emptyResult );
212
-
213
192
// Workflow details
214
- GitDetails lobSTRv1Details = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
193
+ GitDetails lobSTRdraft3Details = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
215
194
"933bf2a1a1cce32d88f88f136275535da9df0954" , "workflows/lobSTR/lobSTR-workflow.cwl" );
216
- Workflow lobSTRv1 = Mockito .mock (Workflow .class );
217
- when (lobSTRv1 .getID ()).thenReturn ("testID" );
218
- when (lobSTRv1 .getRetrievedFrom ()).thenReturn (lobSTRv1Details );
195
+ Workflow lobSTRdraft3 = Mockito .mock (Workflow .class );
196
+ when (lobSTRdraft3 .getID ()).thenReturn ("testID" );
197
+ when (lobSTRdraft3 .getRetrievedFrom ()).thenReturn (lobSTRdraft3Details );
219
198
220
199
// RO details
221
- GitDetails lobSTRv1RODetails = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
222
- "933bf2a1a1cce32d88f88f136275535da9df0954" , "lobstr-draft3/lobSTR-workflow.cwl " );
200
+ GitDetails lobSTRdraft3RoDetails = new GitDetails ("https://github.com/common-workflow-language/workflows.git" ,
201
+ "933bf2a1a1cce32d88f88f136275535da9df0954" , "lobstr-draft3/" );
223
202
224
203
// Create new RO bundle
225
- ROBundleService bundleService = new ROBundleService (roBundleFolder .getRoot ().toPath (),
226
- "CWL Viewer" , "https://view.commonwl.org" , 0 , mockGraphvizService ,
227
- mockGitService , mockRdfService , Mockito .mock (GitSemaphore .class ), mockCwlTool );
228
- Bundle bundle = bundleService .createBundle (lobSTRv1 , lobSTRv1RODetails );
204
+ Bundle bundle = roBundleServiceZeroSizeLimit .createBundle (lobSTRdraft3 , lobSTRdraft3RoDetails );
229
205
230
206
Manifest manifest = bundle .getManifest ();
231
207
232
208
// Check files are externally linked in the aggregate
233
209
assertEquals (14 , manifest .getAggregates ().size ());
234
210
235
211
PathMetadata urlAggregate = manifest .getAggregation (
236
- new URI ("https://raw.githubusercontent.com/common-workflow-language/workflows/933bf2a1a1cce32d88f88f136275535da9df0954/ lobstr-draft3/lobSTR-workflow.cwl/ models/illumina_v3.pcrfree.stepmodel" ));
212
+ new URI ("https://w3id.org/cwl/v/git/null/ lobstr-draft3/models/illumina_v3.pcrfree.stepmodel?format=raw " ));
237
213
assertEquals ("Mark Robinson" , urlAggregate .getAuthoredBy ().get (0 ).getName ());
238
214
239
215
}
0 commit comments