Skip to content

Package: BaseRunner

BaseRunner

nameinstructionbranchcomplexitylinemethod
BaseRunner(Logger)
M: 4 C: 11
73%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 5
100%
M: 0 C: 1
100%
init()
M: 0 C: 143
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 31
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: 4
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: 7
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: * <p>
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: * <p>
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 org.junit.After;
20: import org.slf4j.Logger;
21:
22: import java.net.URI;
23: import java.util.HashSet;
24: import java.util.Map;
25: import java.util.Set;
26:
27: public abstract class BaseRunner {
28:
29: protected static final URI CONTEXT_ONE = URI
30: .create("http://krizik.felk.cvut.cz/jopa/contexts#One");
31: protected static final URI CONTEXT_TWO = URI
32: .create("http://krizik.felk.cvut.cz/jopa/contexts#Two");
33:
34:
35: protected final Logger logger;
36:
37: protected EntityManager em;
38:
39: protected OWLClassA entityA;
40: protected OWLClassB entityB;
41: protected OWLClassC entityC;
42: protected OWLClassD entityD;
43: // Generated IRI
44: protected OWLClassE entityE;
45: // Two relationships, cascade
46: protected OWLClassG entityG;
47: protected OWLClassH entityH;
48: // Lazy reference to OWLClassA
49: protected OWLClassI entityI;
50: protected OWLClassM entityM;
51: protected OWLClassN entityN;
52: protected OWLClassP entityP;
53:
54: public BaseRunner(Logger logger) {
55:• assert logger != null;
56: this.logger = logger;
57: init();
58: }
59:
60: /**
61: * Initializes the test entities in the following manner:
62: * <pre>
63: * <ul>
64: * <li>entityA contains non-empty types</li>
65: * <li>entityB's properties are null</li>
66: * <li>entityC's simple and referenced lists are null</li>
67: * <li>entityD's reference to OWLClassA is set to entityA</li>
68: * <li>entityE's URI is left null for ID generation</li>
69: * <li>entityG's reference to OWLClassH is set to entityH</li>
70: * <li>entityH's reference to OWLClassA is set to entityA</li>
71: * <li>entityI's reference to OWLClassA is set to entityA</li>
72: * <li>entityM has all fields set to some values</li>
73: * <li>entityN has required fields set</li>
74: * <li>entityP's properties and uri are null</li>
75: * </ul>
76: * </pre>
77: */
78: private void init() {
79: this.entityA = new OWLClassA();
80: entityA.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityA"));
81: entityA.setStringAttribute("entityAStringAttribute");
82: final Set<String> types = new HashSet<>();
83: types.add("http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassU");
84: entityA.setTypes(types);
85: this.entityB = new OWLClassB();
86: entityB.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityB"));
87: entityB.setStringAttribute("entityBStringAttribute");
88: this.entityC = new OWLClassC();
89: entityC.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityC"));
90: this.entityD = new OWLClassD();
91: entityD.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityD"));
92: entityD.setOwlClassA(entityA);
93: this.entityE = new OWLClassE();
94: entityE.setStringAttribute("entityEStringAttribute");
95: this.entityH = new OWLClassH();
96: entityH.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityH"));
97: entityH.setOwlClassA(entityA);
98: this.entityG = new OWLClassG();
99: entityG.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityG"));
100: entityG.setOwlClassH(entityH);
101: this.entityI = new OWLClassI();
102: entityI.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityI"));
103: entityI.setOwlClassA(entityA);
104: this.entityM = new OWLClassM();
105: entityM.initializeTestValues(true);
106: this.entityN = new OWLClassN();
107: entityN.setStringAttribute("entityNStringAttribute");
108: this.entityP = new OWLClassP();
109: }
110:
111: @After
112: public void tearDown() throws Exception {
113:• if (em != null) {
114:• if (em.isOpen()) {
115:• if (em.getTransaction().isActive()) {
116: em.getTransaction().rollback();
117: }
118: em.close();
119: em.getEntityManagerFactory().close();
120: }
121: }
122: }
123:
124: /**
125: * Persists the specified instance(s) in a separate transaction.
126: *
127: * @param entity Entity to persist
128: */
129: protected void persist(Object... entity) {
130: em.getTransaction().begin();
131:• for (Object ent : entity) {
132: em.persist(ent);
133: }
134: em.getTransaction().commit();
135: }
136:
137: protected abstract EntityManager getEntityManager(String repositoryName, boolean cacheEnabled);
138:
139: protected abstract EntityManager getEntityManager(String repositoryName, boolean cacheEnabled,
140: Map<String, String> properties);
141: }