Skip to content

Method: testPersistEntityExtendedBySubEntity()

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