|
a |
|
b/src/test/java/org/sbaresearch/owl/OwlApiFacadeIntegrationTest.java |
|
|
1 |
/**
|
|
|
2 |
* Copyright (c) 2013/2014 Verein zur Foerderung der IT-Sicherheit in Oesterreich (SBA).
|
|
|
3 |
* The work has been developed in the TIMBUS Project and the above-mentioned are Members of the TIMBUS Consortium.
|
|
|
4 |
* TIMBUS is supported by the European Union under the 7th Framework Programme for research and technological
|
|
|
5 |
* development and demonstration activities (FP7/2007-2013) under grant agreement no. 269940.
|
|
|
6 |
*
|
|
|
7 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
|
|
8 |
* the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
|
10 |
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including without
|
|
|
11 |
* limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTIBITLY, or FITNESS FOR A PARTICULAR
|
|
|
12 |
* PURPOSE. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise,
|
|
|
13 |
* unless required by applicable law or agreed to in writing, shall any Contributor be liable for damages, including
|
|
|
14 |
* any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this
|
|
|
15 |
* License or out of the use or inability to use the Work.
|
|
|
16 |
* See the License for the specific language governing permissions and limitation under the License.
|
|
|
17 |
*/
|
|
|
18 |
package org.sbaresearch.owl;
|
|
|
19 |
|
|
|
20 |
import com.hp.hpl.jena.query.QuerySolution;
|
|
|
21 |
import com.hp.hpl.jena.rdf.model.Model;
|
|
|
22 |
import junitparams.JUnitParamsRunner;
|
|
|
23 |
import junitparams.Parameters;
|
|
|
24 |
import org.junit.Assert;
|
|
|
25 |
import org.junit.BeforeClass;
|
|
|
26 |
import org.junit.Test;
|
|
|
27 |
import org.junit.experimental.categories.Category;
|
|
|
28 |
import org.junit.runner.RunWith;
|
|
|
29 |
import org.semanticweb.owlapi.apibinding.OWLManager;
|
|
|
30 |
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
|
|
|
31 |
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
|
|
|
32 |
|
|
|
33 |
import java.io.IOException;
|
|
|
34 |
import java.net.URISyntaxException;
|
|
|
35 |
import java.util.List;
|
|
|
36 |
|
|
|
37 |
import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
38 |
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
@Category(IntegrationTests.class)
|
|
|
42 |
@RunWith(JUnitParamsRunner.class)
|
|
|
43 |
public class OwlApiFacadeIntegrationTest {
|
|
|
44 |
|
|
|
45 |
@BeforeClass
|
|
|
46 |
public static void setUpClass() {
|
|
|
47 |
TestUtils.loadTimbusTrustStore();
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
@Test
|
|
|
51 |
@Parameters(
|
|
|
52 |
{"http://timbus.teco.edu/ontologies/Scenarios/MusicClassificationDSOs.owl, 39e989c6"}
|
|
|
53 |
)
|
|
|
54 |
public void testGetIndividualByUnqualifiedName_individualInImportedNamespace_shouldReturnIndividual(String url, String indivName) throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
|
|
|
55 |
OwlApiFacade owlApiFacade = createDefaultOwlApiFacade();
|
|
|
56 |
owlApiFacade.load(url);
|
|
|
57 |
Assert.assertNotNull(owlApiFacade.getIndividualByUnqualifiedName(indivName, true));
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
private OwlApiFacade createDefaultOwlApiFacade() {
|
|
|
61 |
return new OwlApiFacade(OWLManager.createOWLOntologyManager(), OWLManager.getOWLDataFactory());
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
@Test
|
|
|
65 |
public void testGetJenaModel_complexModel_shouldReturnJenaModel() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
|
|
|
66 |
OwlApiFacade owlApi = createDefaultOwlApiFacade();
|
|
|
67 |
owlApi.load(this.getClass().getResourceAsStream("/MusicClassification.owl"));
|
|
|
68 |
Model jenaModel = owlApi.getJenaModel(false);
|
|
|
69 |
Assert.assertNotNull(jenaModel);
|
|
|
70 |
Assert.assertEquals(5256, jenaModel.size());
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
@Test
|
|
|
74 |
public void testGetJenaModel_withImports_shouldReturnJenaModelContainingImportedIndivs() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
|
|
|
75 |
OwlApiFacade owlApi = createDefaultOwlApiFacade();
|
|
|
76 |
owlApi.load(this.getClass().getResourceAsStream("/MusicClassification.owl"));
|
|
|
77 |
Model jenaModel = owlApi.getJenaModel(false);
|
|
|
78 |
JenaQueryFacade jenaQueryFacade = new JenaQueryFacade(jenaModel);
|
|
|
79 |
List<String> tools = JenaQueryFacade.extractColumn(jenaQueryFacade.query("" +
|
|
|
80 |
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
|
|
|
81 |
"SELECT ?tool\n" +
|
|
|
82 |
"WHERE{\n" +
|
|
|
83 |
" ?tool rdfs:label ?label .\n" +
|
|
|
84 |
" FILTER(str(?label) = \"Base64_Encoder\") .\n" +
|
|
|
85 |
"}"), "tool");
|
|
|
86 |
Assert.assertThat(tools, contains("http://timbus.teco.edu/ontologies/Scenarios/MusicClassification.owl#39e989c6"));
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
@Test
|
|
|
90 |
@Parameters({"http://id.loc.gov/vocabulary/preservation/inhibitorTarget"})
|
|
|
91 |
public void testLoad_invalidDocumentIRI_shouldAddValidIRIToOntology(String url) throws OWLOntologyCreationException {
|
|
|
92 |
OwlApiFacade owlApi = createDefaultOwlApiFacade();
|
|
|
93 |
owlApi.load(url);
|
|
|
94 |
Assert.assertThat(owlApi.getOntology().getOntologyID().getOntologyIRI().toString(), equalTo(url));
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
@Test
|
|
|
99 |
public void testGetJenaModel_queryImportedIndivs_shouldReturnJenaModelContainingImportedIndivs() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
|
|
|
100 |
OwlApiFacade owlApi = createDefaultOwlApiFacade();
|
|
|
101 |
owlApi.load(this.getClass().getResourceAsStream("/MusicClassificationDSOs.owl"));
|
|
|
102 |
Model jenaModel = owlApi.getJenaModel(false);
|
|
|
103 |
JenaQueryFacade jenaQueryFacade = new JenaQueryFacade(jenaModel);
|
|
|
104 |
List<QuerySolution> results = jenaQueryFacade.query("" +
|
|
|
105 |
"PREFIX dio: <http://timbus.teco.edu/ontologies/DIO.owl#>\n" +
|
|
|
106 |
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
|
|
|
107 |
"SELECT ?tool ?readFormat ?writeFormat ?label\n" +
|
|
|
108 |
"WHERE{\n" +
|
|
|
109 |
" ?tool a dio:SystemSoftware .\n" +
|
|
|
110 |
" ?tool rdfs:label ?label .\n" +
|
|
|
111 |
" FILTER(str(?label) = \"Base64_Encoder\") .\n" +
|
|
|
112 |
" OPTIONAL {\n" +
|
|
|
113 |
" ?tool dio:hasAccessTypeRead ?readFormat .\n" +
|
|
|
114 |
" }\n" +
|
|
|
115 |
" OPTIONAL {\n" +
|
|
|
116 |
" ?tool dio:hasAccessTypeWrite ?writeFormat .\n" +
|
|
|
117 |
" }\n" +
|
|
|
118 |
"}");
|
|
|
119 |
List<String> tools = JenaQueryFacade.extractColumn(results, "tool");
|
|
|
120 |
Assert.assertThat(tools, contains("http://timbus.teco.edu/ontologies/Scenarios/MusicClassification.owl#39e989c6"));
|
|
|
121 |
}
|
|
|
122 |
}
|