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: 159
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 34
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(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityA"));
90: entityA.setStringAttribute("entityAStringAttribute");
91: final Set<String> types = new HashSet<>();
92: types.add("http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassU");
93: entityA.setTypes(types);
94: this.entityB = new OWLClassB();
95: entityB.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityB"));
96: entityB.setStringAttribute("entityBStringAttribute");
97: this.entityC = new OWLClassC();
98: entityC.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityC"));
99: this.entityD = new OWLClassD(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityD"));
100: entityD.setOwlClassA(entityA);
101: this.entityE = new OWLClassE();
102: entityE.setStringAttribute("entityEStringAttribute");
103: this.entityH = new OWLClassH();
104: entityH.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityH"));
105: entityH.setOwlClassA(entityA);
106: this.entityG = new OWLClassG();
107: entityG.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityG"));
108: entityG.setOwlClassH(entityH);
109: this.entityI = new OWLClassI();
110: entityI.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityI"));
111: entityI.setOwlClassA(entityA);
112: this.entityM = new OWLClassM();
113: entityM.initializeTestValues(true);
114: this.entityN = new OWLClassN();
115: entityN.setStringAttribute("entityNStringAttribute");
116: this.entityP = new OWLClassP();
117: this.entityQ = new OWLClassQ();
118: entityQ.setStringAttribute("entityQStringAttribute");
119: entityQ.setParentString("entityQParentStringAttribute");
120: entityQ.setLabel("entityQLabel");
121: entityQ.setOwlClassA(entityA);
122: }
123:
124: @After
125: public void tearDown() throws Exception {
126:• if (em != null && em.isOpen()) {
127:• if (em.getTransaction().isActive()) {
128: em.getTransaction().rollback();
129: }
130: em.close();
131: em.getEntityManagerFactory().close();
132: }
133: }
134:
135: /**
136: * Persists the specified instance(s) in a separate transaction.
137: *
138: * @param entity Entity to persist
139: */
140: protected void persist(Object... entity) {
141: em.getTransaction().begin();
142:• for (Object ent : entity) {
143: em.persist(ent);
144: }
145: em.getTransaction().commit();
146: }
147:
148: /**
149: * Verifies that no statements with the specified individual as subject exist in the ontology any more.
150: *
151: * @param identifier Individual identifier
152: */
153: protected void verifyIndividualWasRemoved(URI identifier) {
154: // TODO There is a bug in OWL2Query - the query returns true, because it finds the top object and data property assertion for an individual
155: // which doesn't exist anymore (but is a part of the query)
156: final boolean remains = em.createNativeQuery("ASK WHERE { ?instance ?y ?z . }", Boolean.class)
157: .setParameter("instance", identifier).getSingleResult();
158: assertFalse(remains);
159: }
160:
161: protected abstract EntityManager getEntityManager(String repositoryName, boolean cacheEnabled);
162:
163: protected abstract EntityManager getEntityManager(String repositoryName, boolean cacheEnabled,
164: Map<String, String> properties);
165:
166: protected abstract void persistTestData(Collection<Triple> data, EntityManager em) throws Exception;
167:
168: protected abstract void verifyStatementsPresent(Collection<Triple> expected, EntityManager em) throws Exception;
169: }