Skip to content

Package: UpdateOperationsWithInheritanceRunner

UpdateOperationsWithInheritanceRunner

nameinstructionbranchcomplexitylinemethod
UpdateOperationsWithInheritanceRunner(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%
lambda$settingNonEmptyFieldInMappedSuperclassThrowsICViolationOnMerge$0()
M: 5 C: 14
74%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 3
60%
M: 0 C: 1
100%
settingNonEmptyFieldInMappedSuperclassThrowsICViolationOnMerge()
M: 0 C: 32
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testUpdateDataPropertyInEntitySuperclass()
M: 0 C: 76
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testUpdateFieldsOfEntityWithMappedSuperclass()
M: 0 C: 73
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
testUpdateObjectPropertyInMappedSuperclass()
M: 0 C: 82
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
updateAllowsSettingValueOfPolymorphicAttributeToInstanceOfDifferentSubtype()
M: 0 C: 85
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%

Coverage

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.exceptions.IntegrityConstraintViolatedException;
21: import cz.cvut.kbss.jopa.exceptions.RollbackException;
22: import cz.cvut.kbss.jopa.test.*;
23: import cz.cvut.kbss.jopa.test.environment.DataAccessor;
24: import cz.cvut.kbss.jopa.test.environment.Generators;
25: import cz.cvut.kbss.jopa.test.environment.PersistenceFactory;
26: import org.junit.jupiter.api.Test;
27: import org.slf4j.Logger;
28:
29: import static org.hamcrest.MatcherAssert.assertThat;
30: import static org.hamcrest.Matchers.instanceOf;
31: import static org.junit.jupiter.api.Assertions.*;
32:
33: public abstract class UpdateOperationsWithInheritanceRunner extends BaseInheritanceRunner {
34:
35: public UpdateOperationsWithInheritanceRunner(Logger logger, PersistenceFactory persistenceFactory,
36: DataAccessor dataAccessor) {
37: super(logger, persistenceFactory, dataAccessor);
38: }
39:
40: @Test
41: void testUpdateFieldsOfEntityWithMappedSuperclass() {
42: this.em = getEntityManager("UpdateEntityWithMappedSuperclass", true);
43: persist(entityQ, entityA);
44:
45: entityQ.setStringAttribute("newStringAttribute");
46: entityQ.setParentString("newParentStringAttribute");
47: entityQ.setLabel("newLabel");
48: em.getTransaction().begin();
49: em.merge(entityQ);
50: em.getTransaction().commit();
51:
52: final OWLClassQ res = findRequired(OWLClassQ.class, entityQ.getUri());
53: assertEquals(entityQ.getStringAttribute(), res.getStringAttribute());
54: assertEquals(entityQ.getParentString(), res.getParentString());
55: assertEquals(entityQ.getLabel(), res.getLabel());
56: }
57:
58: @Test
59: void testUpdateObjectPropertyInMappedSuperclass() {
60: this.em = getEntityManager("UpdateObjectPropertyInMappedSuperclass", true);
61: persist(entityQ, entityA);
62: final OWLClassA entityA2 = new OWLClassA(Generators.generateUri());
63: entityA2.setStringAttribute("entityA2StringAttribute");
64:
65: entityQ.setOwlClassA(entityA2);
66: em.getTransaction().begin();
67: em.merge(entityQ);
68: em.persist(entityA2);
69: em.getTransaction().commit();
70:
71: final OWLClassQ res = findRequired(OWLClassQ.class, entityQ.getUri());
72: assertNotNull(res.getOwlClassA());
73: assertEquals(entityA2.getUri(), res.getOwlClassA().getUri());
74: assertEquals(entityA2.getStringAttribute(), res.getOwlClassA().getStringAttribute());
75: assertNotNull(em.find(OWLClassA.class, entityA.getUri()));
76: }
77:
78: @Test
79: void settingNonEmptyFieldInMappedSuperclassThrowsICViolationOnMerge() {
80: this.em = getEntityManager("SettingNonEmptyFieldInMappedSuperclassThrowsICViolation", true);
81: persist(entityQ, entityA);
82:
83: final RollbackException ex = assertThrows(RollbackException.class, () -> {
84: entityQ.setOwlClassA(null);
85: em.getTransaction().begin();
86: em.merge(entityQ);
87: em.getTransaction().commit();
88: });
89: assertThat(ex.getCause(), instanceOf(IntegrityConstraintViolatedException.class));
90:
91: }
92:
93: @Test
94: void testUpdateDataPropertyInEntitySuperclass() {
95: this.em = getEntityManager("updateDataPropertyInEntitySuperclass", true);
96: persist(entityT, entityA);
97:
98: final String newName = "newName";
99: final int newInt = Generators.randomInt(Integer.MAX_VALUE);
100: entityT.setName(newName);
101: entityT.setIntAttribute(newInt);
102: final String newDescription = "new entity description";
103: em.getTransaction().begin();
104: final OWLClassT merged = em.merge(entityT);
105: merged.setDescription(newDescription);
106: em.getTransaction().commit();
107:
108: final OWLClassT result = findRequired(OWLClassT.class, entityT.getUri());
109: assertEquals(newName, result.getName());
110: assertEquals(newDescription, result.getDescription());
111: assertEquals(newInt, result.getIntAttribute().intValue());
112: }
113:
114: @Test
115: void updateAllowsSettingValueOfPolymorphicAttributeToInstanceOfDifferentSubtype() {
116: this.em = getEntityManager("updateAllowsSettingValueOfPolymorphicAttributeToInstanceOfDifferentSubtype", true);
117: persist(entityU, entityT, entityA);
118:
119: final OWLClassU newReference = new OWLClassU();
120: newReference.setName("UpdatedU");
121: newReference.setDescription("Description");
122:
123: em.getTransaction().begin();
124: em.persist(newReference);
125: final OWLClassU toUpdate = findRequired(OWLClassU.class, entityU.getUri());
126: toUpdate.setOwlClassS(newReference);
127: em.getTransaction().commit();
128:
129: final OWLClassU result = findRequired(OWLClassU.class, entityU.getUri());
130: assertTrue(result.getOwlClassS() instanceof OWLClassU);
131: assertEquals(newReference.getUri(), result.getOwlClassS().getUri());
132: assertNotNull(em.find(OWLClassS.class, entityT.getUri()));
133: }
134: }