Skip to content

Method: testPersistEntityExtendedBySubEntity()

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.test.runner;
19:
20: import cz.cvut.kbss.jopa.test.OWLClassQ;
21: import cz.cvut.kbss.jopa.test.OWLClassS;
22: import cz.cvut.kbss.jopa.test.OWLClassT;
23: import cz.cvut.kbss.jopa.test.environment.DataAccessor;
24: import cz.cvut.kbss.jopa.test.environment.PersistenceFactory;
25: import org.junit.jupiter.api.Test;
26: import org.slf4j.Logger;
27:
28: import static org.junit.jupiter.api.Assertions.*;
29:
30: public abstract class CreateOperationsWithInheritanceRunner extends BaseInheritanceRunner {
31:
32: protected CreateOperationsWithInheritanceRunner(Logger logger, PersistenceFactory persistenceFactory,
33: DataAccessor dataAccessor) {
34: super(logger, persistenceFactory, dataAccessor);
35: }
36:
37: @Test
38: void testPersistEntityWithMappedSuperclass() {
39: this.em = getEntityManager("PersistEntityWithMappedSuperclass", false);
40: em.getTransaction().begin();
41: em.persist(entityA);
42: em.persist(entityQ);
43: em.getTransaction().commit();
44: em.clear();
45:
46: assertNotNull(entityQ.getUri());
47: final OWLClassQ result = em.find(OWLClassQ.class, entityQ.getUri());
48: assertNotNull(result);
49: assertEquals(entityQ.getStringAttribute(), result.getStringAttribute());
50: assertEquals(entityQ.getParentString(), result.getParentString());
51: assertEquals(entityQ.getLabel(), result.getLabel());
52: assertNotNull(result.getOwlClassA());
53: assertEquals(entityQ.getOwlClassA().getUri(), result.getOwlClassA().getUri());
54: assertEquals(entityA.getStringAttribute(), result.getOwlClassA().getStringAttribute());
55: assertEquals(entityA.getTypes(), result.getOwlClassA().getTypes());
56: }
57:
58: @Test
59: void testPersistEntityWithEntitySuperclass() {
60: this.em = getEntityManager("PersistEntityWithEntitySuperclass", false);
61: em.getTransaction().begin();
62: em.persist(entityA);
63: em.persist(entityT);
64: em.getTransaction().commit();
65: em.clear();
66:
67: assertNotNull(entityT.getUri());
68: final OWLClassT result = em.find(OWLClassT.class, entityT.getUri());
69: assertNotNull(result);
70: assertEquals(entityT.getName(), result.getName());
71: assertEquals(entityT.getDescription(), result.getDescription());
72: assertEquals(entityT.getIntAttribute(), result.getIntAttribute());
73: assertNotNull(result.getOwlClassA());
74: assertEquals(entityA.getUri(), result.getOwlClassA().getUri());
75: assertEquals(entityA.getStringAttribute(), result.getOwlClassA().getStringAttribute());
76: assertEquals(entityA.getTypes(), result.getOwlClassA().getTypes());
77: }
78:
79: @Test
80: void testPersistEntityExtendedBySubEntity() {
81: this.em = getEntityManager("PersistEntityExtendedBySubEntity", false);
82: final OWLClassS entityS = new OWLClassS();
83: entityS.setName("Supertype");
84: entityS.setDescription("Supertype is a type with a subclass.");
85: em.getTransaction().begin();
86: em.persist(entityS);
87: em.getTransaction().commit();
88: em.clear();
89:
90: assertNotNull(entityS.getUri());
91: final OWLClassS resultS = em.find(OWLClassS.class, entityS.getUri());
92: assertNotNull(resultS);
93: assertEquals(entityS.getName(), resultS.getName());
94: assertEquals(entityS.getDescription(), resultS.getDescription());
95: em.clear();
96: assertNull(em.find(OWLClassT.class, entityS.getUri()));
97: }
98: }