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: 129
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 28
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: 4 C: 25
86%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 7
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2011 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 org.junit.After;
20:
21: import java.net.URI;
22: import java.util.HashSet;
23: import java.util.Map;
24: import java.util.Set;
25: import java.util.logging.Logger;
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:
52: public BaseRunner(Logger logger) {
53:• assert logger != null;
54: this.logger = logger;
55: init();
56: }
57:
58: /**
59: * Initializes the test entities in the following manner:
60: * <pre>
61: * <ul>
62: * <li>entityA contains non-empty types</li>
63: * <li>entityB's properties are null</li>
64: * <li>entityC's simple and referenced lists are null</li>
65: * <li>entityD's reference to OWLClassA is set to entityA</li>
66: * <li>entityE's URI is left null for ID generation</li>
67: * <li>entityG's reference to OWLClassH is set to entityH</li>
68: * <li>entityH's reference to OWLClassA is set to entityA</li>
69: * <li>entityI's reference to OWLClassA is set to entityA</li>
70: * <li>entityM has all fields set to some values</li>
71: * </ul>
72: * </pre>
73: */
74: private void init() {
75: this.entityA = new OWLClassA();
76: entityA.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityA"));
77: entityA.setStringAttribute("entityAStringAttribute");
78: final Set<String> types = new HashSet<>();
79: types.add("http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassU");
80: entityA.setTypes(types);
81: this.entityB = new OWLClassB();
82: entityB.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityB"));
83: entityB.setStringAttribute("entityBStringAttribute");
84: this.entityC = new OWLClassC();
85: entityC.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityC"));
86: this.entityD = new OWLClassD();
87: entityD.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityD"));
88: entityD.setOwlClassA(entityA);
89: this.entityE = new OWLClassE();
90: entityE.setStringAttribute("entityEStringAttribute");
91: this.entityH = new OWLClassH();
92: entityH.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityH"));
93: entityH.setOwlClassA(entityA);
94: this.entityG = new OWLClassG();
95: entityG.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityG"));
96: entityG.setOwlClassH(entityH);
97: this.entityI = new OWLClassI();
98: entityI.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityI"));
99: entityI.setOwlClassA(entityA);
100: this.entityM = new OWLClassM();
101: entityM.initializeTestValues(true);
102: }
103:
104: @After
105: public void tearDown() throws Exception {
106:• assert em != null;
107:• if (em.isOpen()) {
108:• if (em.getTransaction().isActive()) {
109: em.getTransaction().rollback();
110: }
111: em.close();
112: em.getEntityManagerFactory().close();
113: }
114: }
115:
116: /**
117: * Persists the specified instance in a separate transaction.
118: *
119: * @param entity Entity to persist
120: */
121: protected void persist(Object... entity) {
122: em.getTransaction().begin();
123:• for (Object ent : entity) {
124: em.persist(ent);
125: }
126: em.getTransaction().commit();
127: }
128:
129: protected abstract EntityManager getEntityManager(String repositoryName, boolean cacheEnabled);
130:
131: protected abstract EntityManager getEntityManager(String repositoryName, boolean cacheEnabled,
132: Map<String, String> properties);
133: }