Skip to content

Package: BaseRunner

BaseRunner

nameinstructionbranchcomplexitylinemethod
BaseRunner(Logger)
M: 4 C: 14
78%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 6
100%
M: 0 C: 1
100%
init()
M: 0 C: 165
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 36
100%
M: 0 C: 1
100%
persist(Object[])
M: 0 C: 29
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 24
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 6
100%
M: 0 C: 1
100%
verifyIndividualWasRemoved(URI)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.test.runner;
16:
17: import cz.cvut.kbss.jopa.model.EntityManager;
18: import cz.cvut.kbss.jopa.test.*;
19: import cz.cvut.kbss.jopa.test.environment.Triple;
20: import org.junit.After;
21: import org.junit.Rule;
22: import org.junit.rules.ExpectedException;
23: import org.slf4j.Logger;
24:
25: import java.net.URI;
26: import java.util.Collection;
27: import java.util.HashSet;
28: import java.util.Map;
29: import java.util.Set;
30:
31: import static org.junit.Assert.assertFalse;
32:
33: public abstract class BaseRunner {
34:
35: protected static final URI CONTEXT_ONE = URI.create("http://krizik.felk.cvut.cz/jopa/contexts#One");
36: protected static final URI CONTEXT_TWO = URI.create("http://krizik.felk.cvut.cz/jopa/contexts#Two");
37:
38:
39: protected final Logger logger;
40:
41: protected EntityManager em;
42:
43: protected OWLClassA entityA;
44: protected OWLClassB entityB;
45: protected OWLClassC entityC;
46: protected OWLClassD entityD;
47: // Generated IRI
48: protected OWLClassE entityE;
49: // Two relationships, cascade
50: protected OWLClassG entityG;
51: protected OWLClassH entityH;
52: // Lazy reference to OWLClassA
53: protected OWLClassI entityI;
54: protected OWLClassM entityM;
55: protected OWLClassN entityN;
56: protected OWLClassP entityP;
57: // Mapped superclass
58: protected OWLClassQ entityQ;
59:
60: @Rule
61: public ExpectedException thrown = ExpectedException.none();
62:
63: public BaseRunner(Logger logger) {
64:• assert logger != null;
65: this.logger = logger;
66: init();
67: }
68:
69: /**
70: * Initializes the test entities in the following manner:
71: * <pre>
72: * <ul>
73: * <li>entityA contains non-empty types</li>
74: * <li>entityB's properties are null</li>
75: * <li>entityC's simple and referenced lists are null</li>
76: * <li>entityD's reference to OWLClassA is set to entityA</li>
77: * <li>entityE's URI is left null for ID generation</li>
78: * <li>entityG's reference to OWLClassH is set to entityH</li>
79: * <li>entityH's reference to OWLClassA is set to entityA</li>
80: * <li>entityI's reference to OWLClassA is set to entityA</li>
81: * <li>entityM has all fields set to some values</li>
82: * <li>entityN has required fields set</li>
83: * <li>entityP's properties and uri are null</li>
84: * <li>entityQ's reference to OWLClassA is set to entityA</li>
85: * </ul>
86: * </pre>
87: */
88: private void init() {
89: this.entityA = new OWLClassA();
90: entityA.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityA"));
91: entityA.setStringAttribute("entityAStringAttribute");
92: final Set<String> types = new HashSet<>();
93: types.add("http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassU");
94: entityA.setTypes(types);
95: this.entityB = new OWLClassB();
96: entityB.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityB"));
97: entityB.setStringAttribute("entityBStringAttribute");
98: this.entityC = new OWLClassC();
99: entityC.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityC"));
100: this.entityD = new OWLClassD();
101: entityD.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityD"));
102: entityD.setOwlClassA(entityA);
103: this.entityE = new OWLClassE();
104: entityE.setStringAttribute("entityEStringAttribute");
105: this.entityH = new OWLClassH();
106: entityH.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityH"));
107: entityH.setOwlClassA(entityA);
108: this.entityG = new OWLClassG();
109: entityG.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityG"));
110: entityG.setOwlClassH(entityH);
111: this.entityI = new OWLClassI();
112: entityI.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityI"));
113: entityI.setOwlClassA(entityA);
114: this.entityM = new OWLClassM();
115: entityM.initializeTestValues(true);
116: this.entityN = new OWLClassN();
117: entityN.setStringAttribute("entityNStringAttribute");
118: this.entityP = new OWLClassP();
119: this.entityQ = new OWLClassQ();
120: entityQ.setStringAttribute("entityQStringAttribute");
121: entityQ.setParentString("entityQParentStringAttribute");
122: entityQ.setLabel("entityQLabel");
123: entityQ.setOwlClassA(entityA);
124: }
125:
126: @After
127: public void tearDown() throws Exception {
128:• if (em != null && em.isOpen()) {
129:• if (em.getTransaction().isActive()) {
130: em.getTransaction().rollback();
131: }
132: em.close();
133: em.getEntityManagerFactory().close();
134: }
135: }
136:
137: /**
138: * Persists the specified instance(s) in a separate transaction.
139: *
140: * @param entity Entity to persist
141: */
142: protected void persist(Object... entity) {
143: em.getTransaction().begin();
144:• for (Object ent : entity) {
145: em.persist(ent);
146: }
147: em.getTransaction().commit();
148: }
149:
150: /**
151: * Verifies that no statements with the specified individual as subject exist in the ontology any more.
152: *
153: * @param identifier Individual identifier
154: */
155: protected void verifyIndividualWasRemoved(URI identifier) {
156: // TODO There is a bug in OWL2Query - the query returns true, because it finds the top object and data property assertion for an individual
157: // which doesn't exist anymore (but is a part of the query)
158: final boolean remains = em.createNativeQuery("ASK WHERE { ?instance ?y ?z . }", Boolean.class)
159: .setParameter("instance", identifier).getSingleResult();
160: assertFalse(remains);
161: }
162:
163: protected abstract EntityManager getEntityManager(String repositoryName, boolean cacheEnabled);
164:
165: protected abstract EntityManager getEntityManager(String repositoryName, boolean cacheEnabled,
166: Map<String, String> properties);
167:
168: protected abstract void persistTestData(Collection<Triple> data, EntityManager em) throws Exception;
169:
170: protected abstract void verifyStatementsPresent(Collection<Triple> expected, EntityManager em) throws Exception;
171: }