-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFOOPSTest.java
More file actions
434 lines (395 loc) · 16.5 KB
/
Copy pathFOOPSTest.java
File metadata and controls
434 lines (395 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
package fair;
import entities.checks.*;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.FOOPSController;
import server.FileTooLargeException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.*;
public class FOOPSTest {
Logger logger = LoggerFactory.getLogger(FOOPSController.class);
/**
* This test verifies that the 61 concepts in the conceptual_mapping vocabulary are documented.
* The test uses skos for descriptions.
* One of the labels uses obo:0000118 (alt label)
*/
@Test
public void skosAndRdfsAnnotationsUsedForOntology(){
try{
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("conceptual_mapping.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
assertEquals (61,f.getOntology().getTermsWithDescription().size());
assertEquals (61,f.getOntology().getTermsWithLabel().size());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test verifies that an ontology with a blank node as an author works
*/
@Test
public void blankNodesInAnnotations(){
try{
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("test_blank_node.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
// there must be one author
assertEquals (1,f.getOntology().getAuthors().size());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test verifies if an ontology with uri purl.something.org passes as persistent
*/
@Test
public void persistentURI(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("test_persistent_uri.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
Check_PURL1_PersistentURIs check = new Check_PURL1_PersistentURIs(f.getOntology());
check.check();
// URI should be persistent
assertEquals(Constants.OK, check.getStatus());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test verifies if the access rights of an ontology are properly detected
*/
@Test
public void accessRightsArePresent(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("test_rights.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
Check_OM4_1_License check = new Check_OM4_1_License(f.getOntology());
check.check();
// URI should be persistent
assertEquals(Constants.OK, check.getStatus());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file for test_rights.ttl");
fail();
}
}
/**
* This test verifies that an ontology with all metadata passes the metadata tests
*/
@Test
public void annotatedOntology(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("ontology_100.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
Check_OM1_MinimumMetadata ch1 = new Check_OM1_MinimumMetadata(f.getOntology());
ch1.check();
Check_OM2_RecommendedMetadata ch2 = new Check_OM2_RecommendedMetadata(f.getOntology());
ch2.check();
Check_OM3_DetailedMetadata ch3 = new Check_OM3_DetailedMetadata(f.getOntology());
ch3.check();
// all metadata is in the ontology
assertEquals(Constants.OK, ch1.getStatus());
assertEquals(Constants.OK, ch2.getStatus());
assertEquals(Constants.OK, ch3.getStatus());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test verifies that an ontology passes the availability in registry through an annotation
* (schema:includedInDataCatalog)
*/
@Test
public void ontologyInDataCatalog(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("ontology_included_in_catalog.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
Check_FIND3_FindOntologyInRegistry ch1 = new Check_FIND3_FindOntologyInRegistry(f.getOntology());
ch1.check();
// all metadata is in the ontology
assertEquals(Constants.OK, ch1.getStatus());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test verifies that an ontology with a link to a pdf and access right correctly defines a license
* Even if the license does not resolve
*/
@Test
public void ontologyWithStrangeLicense(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("weird_license.owl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
Check_OM4_1_License ch1 = new Check_OM4_1_License(f.getOntology());
Check_OM4_2_LicenseIsResolvable ch2 = new Check_OM4_2_LicenseIsResolvable(f.getOntology());
ch1.check();
ch2.check();
// all metadata is in the ontology
assertEquals(Constants.OK, ch1.getStatus());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test verifies that if an ontology extends metadata properties, they still get accepted.
*/
@Test
public void testExtendedProperties(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("test_extended_annotation_properties.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
Check_OM1_MinimumMetadata ch1 = new Check_OM1_MinimumMetadata(f.getOntology());
ch1.check();
// all metadata is in the ontology
assertEquals(Constants.OK, ch1.getStatus());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test tries to load an ontology with errors (should fail)
*/
@Test
public void testOntologyWithErrors(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("test_onto_with_errors.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
assertEquals(null,f.getOntology().getOntologyModel());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test tries to load a skos vocabulary
*/
@Test
public void testSKOS(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("skos_example.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
Check_VOC3_TermMetadataLabel l = new Check_VOC3_TermMetadataLabel(f.getOntology());
l.check();
assertEquals(Constants.OK,l.getStatus());
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* Local Test to verify exceptions when files are too big.
*/
@Test
public void testFileTooBig(){
Path tempDir = null;
try {
tempDir = Files.createTempDirectory("test");
File testFile = tempDir.resolve("large_test_file.bin").toFile();
// Create a file slightly larger than 50 MB (51 MB)
try (FileOutputStream fos = new FileOutputStream(testFile)) {
byte[] buffer = new byte[1024 * 1024]; // 1 MB buffer
for (int i = 0; i < 51; i++) {
fos.write(buffer);
}
}
assertThrows(FileTooLargeException.class, () -> {
new FOOPS(testFile.getAbsolutePath(), true);
});
}catch(Exception e){
throw new RuntimeException("Test failed due to IOException: " + e.getMessage(), e);
}finally {
if (tempDir != null && Files.exists(tempDir)) {
try {
Files.delete(tempDir);
} catch (IOException ignored) {
// Swallow exception if tempDir isn't empty
tempDir.toFile().deleteOnExit();
}
}
}
}
/**
* This test verifies that imports are skipped thanks to the lazy loading.
* The ontology @h2kg.rdf (issue 237) contains remote imports that should not be loaded.
*/
@Test
public void testLazyLoadingSkipsImports() {
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("@h2kg.rdf").getFile());
long start = System.currentTimeMillis();
FOOPS f = new FOOPS(is.toString(), true);
long end = System.currentTimeMillis();
// Ontology must load successfully
assertNotNull(f.getOntology().getOntologyModel());
// Only the main ontology should be loaded (imports blocked). We convert into dev/null
int loadedOntologies = f.getOntology().getOntologyModel()
.getOWLOntologyManager()
.getOntologies()
.size();
assertEquals(
"Lazy loading failed: more than one ontology was loaded (imports were not blocked)",
1,
loadedOntologies
);
assertTrue(
"Ontology loading took too long; imports may not be blocked",
(end - start) < 2000
);
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file for lazy loading test", e);
fail();
}
}
/**
* This test verifies that GET /tests returns test metadata (instead of just an array of ids) including
* title, description, endpointURL, isDefinedBy and landingPage (Issue 224)
*/
@Test
public void testGetTestsReturnsMetadata() {
String result = Constants.getFullListOfTestsMetadata();
assertNotNull(result);
assertTrue("Result must contain @id", result.contains("\"@id\""));
assertTrue("Result must contain title", result.contains("\"title\""));
assertTrue("Result must contain description", result.contains("\"description\""));
assertTrue("Result must contain endpointURL", result.contains("\"endpointURL\""));
assertTrue("Result must contain isDefinedBy", result.contains("\"isDefinedBy\""));
assertTrue("Result must contain landingPage", result.contains("\"landingPage\""));
assertTrue("Result must contain FIND1", result.contains(Constants.FIND1_URL));
assertTrue("Result must contain URI2", result.contains(Constants.URI2_URL));
}
/**
* This test verifies that the JSON-LD output contains the
* required 'isDefinedBy' and 'landingPage' fields (Issue 242)
*/
@Test
public void testOutputContainsNewFields() {
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("skos_example.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
f.fairTest();
String jsonOutput = f.exportJSONLD();
assertNotNull(jsonOutput);
assertTrue("JSON-LD must contain 'isDefinedBy'", jsonOutput.contains("\"isDefinedBy\""));
assertTrue("JSON-LD must contain 'landingPage'", jsonOutput.contains("\"landingPage\""));
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file");
fail();
}
}
/**
* This test verifies that temporary folders are cleaned up even when
* an exception occurs during FOOPS initialization (Issue 236)
*/
@Test
public void testTemporaryFoldersAreCleanedUpOnError() {
// Count folders foops* before the test
File workDir = new File(".");
File[] before = workDir.listFiles(f -> f.isDirectory() && f.getName().startsWith("foops"));
int countBefore = before != null ? before.length : 0;
// Attempt to load an invalid URI, which should fail
try {
FOOPS f = new FOOPS("no-es-una-uri", false);
f.removeTemporaryFolders();
} catch (Exception e) {
// We expect this to fail, so we do nothing
}
File[] after = workDir.listFiles(f -> f.isDirectory() && f.getName().startsWith("foops"));
int countAfter = after != null ? after.length : 0;
assertEquals("No temporary folders should be left after a failed initialization",
countBefore, countAfter);
}
/**
* This test verifies that the test version is included in the JSON-LD output (issue 214).
*/
@Test
public void testVersionInJsonLdOutput(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("skos_example.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
f.fairTest();
String jsonld = f.exportJSONLD();
assertTrue("Test version should be present in JSON-LD output",
jsonld.contains(Constants.FOOPS_TEST_VERSION));
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file", e);
fail();
}
}
/**
* This test verifies that the test version is included in the JSON-LD output
* when running multiple tests (result set path, (issue 214).
*/
@Test
public void testVersionInJsonLdResultSetOutput(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("skos_example.ttl").getFile());
// isFromFile=true triggers FileBenchmark which has multiple checks,
// forcing the result set code path in exportJSONLD()
FOOPS f = new FOOPS(is.toString(), true);
f.fairTest();
String jsonld = f.exportJSONLD();
assertTrue("Test version should be present in result set JSON-LD output",
jsonld.contains(Constants.FOOPS_TEST_VERSION));
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file", e);
fail();
}
}
/**
* This test verifies that void:uriSpace is recognized
* as an alternative to vann:preferredNamespaceUri for the namespace URI.
*/
@Test
public void testVoidUriSpaceRecognized(){
try {
ClassLoader classLoader = getClass().getClassLoader();
File is = new File(classLoader.getResource("test_void_urispace.ttl").getFile());
FOOPS f = new FOOPS(is.toString(), true);
assertEquals("http://example.org/test_void#", f.getOntology().getNamespaceUri());
assertTrue(f.getOntology().getSupportedMetadata().contains(Constants.FOOPS_NS_URI));
f.removeTemporaryFolders();
} catch (Exception e) {
logger.error("Could not load the resource file", e);
fail();
}
}
}