-
Notifications
You must be signed in to change notification settings - Fork 14
/
DummyInferredStorageConnectorTest.java
107 lines (91 loc) · 4.64 KB
/
DummyInferredStorageConnectorTest.java
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
/**
* Copyright (C) 2020 Czech Technical University in Prague
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.cvut.kbss.ontodriver.jena.connector;
import cz.cvut.kbss.ontodriver.Statement;
import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
import cz.cvut.kbss.ontodriver.jena.query.AbstractResultSet;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.vocabulary.RDF;
import org.junit.Before;
import org.junit.Test;
import java.util.Collections;
import static cz.cvut.kbss.ontodriver.jena.connector.StorageTestUtil.*;
import static org.apache.jena.rdf.model.ResourceFactory.createResource;
import static org.junit.Assert.*;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
public class DummyInferredStorageConnectorTest {
private StorageConnector wrappedConnector;
private InferredStorageConnector connector;
@Before
public void setUp() {
final DriverConfiguration configuration = StorageTestUtil.createConfiguration("test:uri");
final SharedStorageConnector wrapped = new SharedStorageConnector(configuration);
wrapped.storage = spy(wrapped.storage);
this.wrappedConnector = spy(wrapped);
generateTestData(wrapped.storage.getDataset());
this.connector = new DummyInferredStorageConnector(wrappedConnector);
}
@Test
public void containsWithInferenceByDefaultUsesRegularContains() {
assertEquals(wrappedConnector.contains(RESOURCE, RDF.type, createResource(TYPE_ONE), Collections.emptySet()),
connector.containsWithInference(RESOURCE, RDF.type, createResource(TYPE_ONE), Collections.emptySet()));
}
@Test
public void containsWithInferenceInContextByDefaultUsesRegularContainsInContext() {
assertEquals(wrappedConnector.contains(RESOURCE, RDF.type, createResource(TYPE_TWO), Collections.singleton(NAMED_GRAPH)),
connector.containsWithInference(RESOURCE, RDF.type, createResource(TYPE_TWO), Collections.singleton(NAMED_GRAPH)));
}
@Test
public void findWithInferenceByDefaultUsesRegularFind() {
assertEquals(wrappedConnector.find(RESOURCE, RDF.type, null, Collections.emptySet()),
connector.findWithInference(RESOURCE, RDF.type, null, Collections.emptySet()));
}
@Test
public void findWithInferenceInContextByDefaultUsesRegularFindInContext() {
assertEquals(wrappedConnector.find(RESOURCE, RDF.type, null, Collections.singleton(NAMED_GRAPH)),
connector.findWithInference(RESOURCE, RDF.type, null, Collections.singleton(NAMED_GRAPH)));
}
@Test
public void isConsistentReturnsTrue() {
assertTrue(connector.isConsistent(null));
}
@Test
public void isContextConsistentReturnsTrue() {
assertTrue(connector.isConsistent(NAMED_GRAPH));
}
@Test
public void executeSelectQueryForwardsCallToWrappedConnector() throws Exception {
final Query query = QueryFactory.create("SELECT * WHERE { ?x ?y ?z . }");
final AbstractResultSet resultSet =
connector.executeSelectQuery(query, Statement.StatementOntology.TRANSACTIONAL);
assertNotNull(resultSet);
verify(wrappedConnector).executeSelectQuery(query, Statement.StatementOntology.TRANSACTIONAL);
}
@Test
public void executeAskQueryForwardsCallToWrappedConnector() throws Exception {
final Query query = QueryFactory.create("ASK { ?x a <" + TYPE_ONE + "> . }");
final AbstractResultSet resultSet = connector.executeAskQuery(query, Statement.StatementOntology.CENTRAL);
assertNotNull(resultSet);
verify(wrappedConnector).executeAskQuery(query, Statement.StatementOntology.CENTRAL);
}
@Test
public void executeUpdateQueryForwardsCallToWrappedConnector() throws Exception {
final String query = "INSERT DATA { _:b1 a <" + TYPE_ONE + "> . }";
connector.executeUpdate(query, Statement.StatementOntology.TRANSACTIONAL);
verify(wrappedConnector).executeUpdate(query, Statement.StatementOntology.TRANSACTIONAL);
}
}