Switch to unified view

a b/src/test/java/org/sbaresearch/owl/JenaQueryFacadeIntegrationTest.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.BeforeClass;
25
import org.junit.Test;
26
import org.junit.experimental.categories.Category;
27
import org.junit.runner.RunWith;
28
29
import java.util.List;
30
31
import static junit.framework.Assert.assertEquals;
32
import static junit.framework.TestCase.assertNotNull;
33
34
@Category(IntegrationTests.class)
35
@RunWith(JUnitParamsRunner.class)
36
public class JenaQueryFacadeIntegrationTest {
37
38
    public static final String ONTOLOGY_FILE_NAME = "/test.owl";
39
40
    @BeforeClass
41
    public static void setUpClass() {
42
        TestUtils.loadTimbusTrustStore();
43
    }
44
45
    @Test(expected = UnableToReadModelException.class)
46
    public void getModelFromPath_invalidPath_shouldThrowException() {
47
        JenaQueryFacade.getModelFromPath(ONTOLOGY_FILE_NAME + "blah", false);
48
    }
49
50
    @Test
51
    @Parameters({"/test.owl", "/MusicClassification.owl"})
52
    public void getModelFromPath_validPath_shouldReturnModel(String path) {
53
        Model knowledgeBase = JenaQueryFacade.getModelFromPath(getClass().getResource(path).getFile(), false);
54
        assertNotNull(knowledgeBase);
55
    }
56
57
    @Test
58
    @Parameters({"/MusicClassificationDSOs.owl"})
59
    public void getModelFromPath_queryImportedIndivs_shouldFindIndivs(String path) {
60
        Model knowledgeBase = JenaQueryFacade.getModelFromPath(getClass().getResource(path).getFile(), false);
61
        JenaQueryFacade queryFacade = new JenaQueryFacade(knowledgeBase);
62
        List<QuerySolution> result = queryFacade.query("PREFIX dio: <http://timbus.teco.edu/ontologies/DIO.owl#>\n" +
63
                "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
64
                "SELECT ?tool ?readFormat ?writeFormat ?label\n" +
65
                "WHERE{\n" +
66
                "    ?tool a dio:SystemSoftware .\n" +
67
                "    ?tool rdfs:label ?label .\n" +
68
                "    FILTER(str(?label) = \"Base64_Encoder\") .\n" +
69
                "    OPTIONAL {\n" +
70
                "        ?tool dio:hasAccessTypeRead ?readFormat .\n" +
71
                "    }\n" +
72
                "    OPTIONAL {\n" +
73
                "        ?tool dio:hasAccessTypeWrite ?writeFormat .\n" +
74
                "    }\n" +
75
                "}");
76
        assertEquals(1, result.size());
77
    }
78
79
    @Test
80
    @Parameters({"http://timbus.teco.edu/ontologies/Scenarios/MusicClassificationDSOs.owl"})
81
    public void getModelFromPath_queryImportedIndivsFromUrl_shouldFindIndivs(String path) {
82
        Model knowledgeBase = JenaQueryFacade.getModelFromPath(path, false);
83
        JenaQueryFacade queryFacade = new JenaQueryFacade(knowledgeBase);
84
        List<QuerySolution> result = queryFacade.query("PREFIX dio: <http://timbus.teco.edu/ontologies/DIO.owl#>\n" +
85
                "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
86
                "SELECT ?tool ?readFormat ?writeFormat ?label\n" +
87
                "WHERE{\n" +
88
                "    ?tool a dio:SystemSoftware .\n" +
89
                "    ?tool rdfs:label ?label .\n" +
90
                "    FILTER(str(?label) = \"Base64_Encoder\") .\n" +
91
                "    OPTIONAL {\n" +
92
                "        ?tool dio:hasAccessTypeRead ?readFormat .\n" +
93
                "    }\n" +
94
                "    OPTIONAL {\n" +
95
                "        ?tool dio:hasAccessTypeWrite ?writeFormat .\n" +
96
                "    }\n" +
97
                "}");
98
        assertEquals(1, result.size());
99
    }
100
101
}