Skip to content

Package: CreateOperationsWithInheritanceRunner

CreateOperationsWithInheritanceRunner

nameinstructionbranchcomplexitylinemethod
CreateOperationsWithInheritanceRunner(Logger, PersistenceFactory, DataAccessor)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testPersistEntityExtendedBySubEntity()
M: 0 C: 65
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testPersistEntityWithEntitySuperclass()
M: 0 C: 85
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
testPersistEntityWithMappedSuperclass()
M: 0 C: 86
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 17
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.test.OWLClassQ;
18: import cz.cvut.kbss.jopa.test.OWLClassS;
19: import cz.cvut.kbss.jopa.test.OWLClassT;
20: import cz.cvut.kbss.jopa.test.environment.DataAccessor;
21: import cz.cvut.kbss.jopa.test.environment.PersistenceFactory;
22: import org.junit.Test;
23: import org.slf4j.Logger;
24:
25: import static org.junit.Assert.*;
26:
27: public abstract class CreateOperationsWithInheritanceRunner extends BaseInheritanceRunner {
28:
29: protected CreateOperationsWithInheritanceRunner(Logger logger, PersistenceFactory persistenceFactory, DataAccessor dataAccessor) {
30: super(logger, persistenceFactory, dataAccessor);
31: }
32:
33: @Test
34: public void testPersistEntityWithMappedSuperclass() {
35: this.em = getEntityManager("PersistEntityWithMappedSuperclass", false);
36: em.getTransaction().begin();
37: em.persist(entityA);
38: em.persist(entityQ);
39: em.getTransaction().commit();
40: em.clear();
41:
42: assertNotNull(entityQ.getUri());
43: final OWLClassQ result = em.find(OWLClassQ.class, entityQ.getUri());
44: assertNotNull(result);
45: assertEquals(entityQ.getStringAttribute(), result.getStringAttribute());
46: assertEquals(entityQ.getParentString(), result.getParentString());
47: assertEquals(entityQ.getLabel(), result.getLabel());
48: assertNotNull(result.getOwlClassA());
49: assertEquals(entityQ.getOwlClassA().getUri(), result.getOwlClassA().getUri());
50: assertEquals(entityA.getStringAttribute(), result.getOwlClassA().getStringAttribute());
51: assertEquals(entityA.getTypes(), result.getOwlClassA().getTypes());
52: }
53:
54: @Test
55: public void testPersistEntityWithEntitySuperclass() {
56: this.em = getEntityManager("PersistEntityWithEntitySuperclass", false);
57: em.getTransaction().begin();
58: em.persist(entityA);
59: em.persist(entityT);
60: em.getTransaction().commit();
61: em.clear();
62:
63: assertNotNull(entityT.getUri());
64: final OWLClassT result = em.find(OWLClassT.class, entityT.getUri());
65: assertNotNull(result);
66: assertEquals(entityT.getName(), result.getName());
67: assertEquals(entityT.getDescription(), result.getDescription());
68: assertEquals(entityT.getIntAttribute(), result.getIntAttribute());
69: assertNotNull(result.getOwlClassA());
70: assertEquals(entityA.getUri(), result.getOwlClassA().getUri());
71: assertEquals(entityA.getStringAttribute(), result.getOwlClassA().getStringAttribute());
72: assertEquals(entityA.getTypes(), result.getOwlClassA().getTypes());
73: }
74:
75: @Test
76: public void testPersistEntityExtendedBySubEntity() {
77: this.em = getEntityManager("PersistEntityExtendedBySubEntity", false);
78: final OWLClassS entityS = new OWLClassS();
79: entityS.setName("Supertype");
80: entityS.setDescription("Supertype is a type with a subclass.");
81: em.getTransaction().begin();
82: em.persist(entityS);
83: em.getTransaction().commit();
84: em.clear();
85:
86: assertNotNull(entityS.getUri());
87: final OWLClassS resultS = em.find(OWLClassS.class, entityS.getUri());
88: assertNotNull(resultS);
89: assertEquals(entityS.getName(), resultS.getName());
90: assertEquals(entityS.getDescription(), resultS.getDescription());
91: em.clear();
92: assertNull(em.find(OWLClassT.class, entityS.getUri()));
93: }
94: }