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%
settingNonEmptyFieldInMappedSuperclassThrowsICViolationOnMerge()
M: 5 C: 43
90%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 7
78%
M: 0 C: 1
100%
testUpdateDataPropertyInEntitySuperclass()
M: 0 C: 79
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: 74
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: 83
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: 89
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%

Coverage

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