1
|
package eu.dnetlib.utils.ontologies;
|
2
|
|
3
|
import org.apache.commons.lang3.StringUtils;
|
4
|
import org.junit.Assert;
|
5
|
import org.junit.Test;
|
6
|
|
7
|
import java.io.IOException;
|
8
|
import java.io.InputStream;
|
9
|
|
10
|
import static org.junit.Assert.*;
|
11
|
|
12
|
/**
|
13
|
* Created by claudio on 12/12/2016.
|
14
|
*/
|
15
|
public class OntologyLoaderTest {
|
16
|
|
17
|
private String basePath = "/eu/dnetlib/test/profiles/OntologyDSResources/OntologyDSResourceType/";
|
18
|
|
19
|
@Test
|
20
|
public void testLoadOntologyFromCp() {
|
21
|
|
22
|
final InputStream i = getClass().getResourceAsStream(basePath + "result_result_relations.xml");
|
23
|
|
24
|
Ontology o = OntologyLoader.loadOntologyFromCp(i);
|
25
|
checkOntology(o);
|
26
|
|
27
|
String supplement = o.inverseOf("isSupplementedBy");
|
28
|
assertEquals(supplement, "isSupplementTo");
|
29
|
|
30
|
String part = o.inverseOf("isPartOf");
|
31
|
assertEquals(part, "hasPart");
|
32
|
}
|
33
|
|
34
|
@Test
|
35
|
public void testLoadOntologiesFromCp() throws IOException {
|
36
|
|
37
|
OntologyLoader.loadOntologiesFromCp().values().forEach(o -> checkOntology(o));
|
38
|
}
|
39
|
|
40
|
@Test
|
41
|
public void testLoadOntologiesSerialization() throws IOException {
|
42
|
|
43
|
final Ontologies o = OntologyLoader.loadOntologiesFromCp();
|
44
|
assertNotNull(o);
|
45
|
|
46
|
final String json = o.toJson(true);
|
47
|
|
48
|
assertFalse(StringUtils.isBlank(json));
|
49
|
assertFalse("{}".equals(json.trim()));
|
50
|
|
51
|
//System.out.println(json);
|
52
|
|
53
|
assertTrue(StringUtils.isNoneBlank(json));
|
54
|
|
55
|
final Ontologies o1 = OntologyLoader.loadOntologies(json);
|
56
|
|
57
|
assertNotNull(o1);
|
58
|
|
59
|
o1.entrySet().forEach(e -> checkOntology(e.getValue()));
|
60
|
}
|
61
|
|
62
|
private void checkOntology(Ontology o) {
|
63
|
Assert.assertNotNull(o);
|
64
|
Assert.assertTrue(StringUtils.isNotBlank(o.getCode()));
|
65
|
Assert.assertTrue(StringUtils.isNotBlank(o.getDescription()));
|
66
|
Assert.assertNotNull(o.getTerms().values());
|
67
|
|
68
|
o.getTerms().values().forEach(it -> {
|
69
|
Assert.assertTrue(StringUtils.isNotBlank(it.getCode()));
|
70
|
Assert.assertTrue(StringUtils.isNotBlank(it.getEncoding()));
|
71
|
Assert.assertTrue(StringUtils.isNotBlank(it.getEnglishName()));
|
72
|
Assert.assertTrue(StringUtils.isNotBlank(it.getNativeName()));
|
73
|
Assert.assertTrue(StringUtils.isNotBlank(it.getInverseCode()));
|
74
|
Assert.assertNotNull(o.getTerms().get(it.getInverseCode()));
|
75
|
});
|
76
|
}
|
77
|
}
|