Skip to content

Package: RetrieveOperationsWithInheritanceRunner

RetrieveOperationsWithInheritanceRunner

nameinstructionbranchcomplexitylinemethod
RetrieveOperationsWithInheritanceRunner(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%
findLoadsInstanceOfSuperclassFromCacheWhenTypeMatchesAndIsSpecifiedAsReturnType()
M: 0 C: 44
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
findLoadsMostConcreteSubclassOfAbstractAncestor()
M: 0 C: 43
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
findLoadsMostSpecificSubclassFromCache()
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
findLoadsSubclassOfAbstractParent()
M: 0 C: 87
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
findLoadsSubclassWhenSuperclassIsPassedInAndTypeCorrespondsToSubclass()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
findLoadsSuperclassInstanceWhenRequestedAndClassAssertionIsPresent()
M: 0 C: 53
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
findReadsAttributesOfEntitySuperclass()
M: 0 C: 51
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
findReadsAttributesOfMappedSuperclass()
M: 0 C: 131
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 22
100%
M: 0 C: 1
100%
findReturnsMostSpecificSubtypeWhenReturnTypeIsAbstractAncestor()
M: 0 C: 56
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
findReturnsNullWhenMatchingClassIsAbstract()
M: 0 C: 46
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
findThrowsAmbiguousTypeExceptionWhenIndividualHasMultipleMostSpecificTypes()
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
findThrowsAmbiguousTypeExceptionWhenIndividualHasMultipleMostSpecificTypesInCache()
M: 0 C: 76
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
lambda$0()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$1()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
loadingEntityLoadsCorrectSubtypeInPolymorphicAttribute()
M: 0 C: 59
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
loadingEntityLoadsExactMatchOfPolymorphicAttribute()
M: 0 C: 66
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
triplesForA()
M: 0 C: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
triplesForEntityT()
M: 0 C: 84
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
verifyEntityTAttributes(OWLClassT)
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2019 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.test.runner;
14:
15: import cz.cvut.kbss.jopa.model.EntityManager;
16: import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
17: import cz.cvut.kbss.jopa.oom.exceptions.AmbiguousEntityTypeException;
18: import cz.cvut.kbss.jopa.test.*;
19: import cz.cvut.kbss.jopa.test.environment.DataAccessor;
20: import cz.cvut.kbss.jopa.test.environment.Generators;
21: import cz.cvut.kbss.jopa.test.environment.PersistenceFactory;
22: import cz.cvut.kbss.jopa.test.environment.Triple;
23: import cz.cvut.kbss.jopa.vocabulary.RDF;
24: import cz.cvut.kbss.jopa.vocabulary.RDFS;
25: import org.junit.jupiter.api.Test;
26: import org.slf4j.Logger;
27:
28: import java.net.URI;
29: import java.util.ArrayList;
30: import java.util.Collection;
31:
32: import static org.junit.jupiter.api.Assertions.*;
33:
34: public abstract class RetrieveOperationsWithInheritanceRunner extends BaseInheritanceRunner {
35:
36: public RetrieveOperationsWithInheritanceRunner(Logger logger, PersistenceFactory persistenceFactory,
37: DataAccessor dataAccessor) {
38: super(logger, persistenceFactory, dataAccessor);
39: }
40:
41: @Test
42: void findReadsAttributesOfMappedSuperclass() throws Exception {
43: final Collection<Triple> data = new ArrayList<>();
44: entityQ.setUri(Generators.generateUri());
45: data.add(
46: new Triple(entityQ.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_Q)));
47: data.add(new Triple(entityQ.getUri(), URI.create(RDFS.LABEL), entityQ.getLabel()));
48: data.add(
49: new Triple(entityQ.getUri(), URI.create(Vocabulary.P_Q_PARENT_STRING_ATTRIBUTE),
50: entityQ.getParentString()));
51: data.add(new Triple(entityQ.getUri(), URI.create(Vocabulary.P_Q_STRING_ATTRIBUTE),
52: entityQ.getStringAttribute()));
53: data.addAll(triplesForA());
54: data.add(new Triple(entityQ.getUri(), URI.create(Vocabulary.P_HAS_OWL_CLASS_A), entityA.getUri()));
55: final EntityManager em = getEntityManager("findReadsAttributesOfMappedSuperclass", false);
56: persistTestData(data, em);
57:
58: final OWLClassQ result = em.find(OWLClassQ.class, entityQ.getUri());
59: assertNotNull(result);
60: assertEquals(entityQ.getStringAttribute(), result.getStringAttribute());
61: assertEquals(entityQ.getLabel(), result.getLabel());
62: assertEquals(entityQ.getParentString(), result.getParentString());
63: assertNotNull(result.getOwlClassA());
64: assertEquals(entityQ.getOwlClassA().getUri(), result.getOwlClassA().getUri());
65: }
66:
67: private Collection<Triple> triplesForA() {
68: final Collection<Triple> data = new ArrayList<>();
69: entityA.setUri(Generators.generateUri());
70: data.add(
71: new Triple(entityA.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_A)));
72: data.add(new Triple(entityA.getUri(), URI.create(Vocabulary.P_A_STRING_ATTRIBUTE),
73: entityA.getStringAttribute()));
74: return data;
75: }
76:
77: @Test
78: void findReadsAttributesOfEntitySuperclass() throws Exception {
79: final Collection<Triple> data = triplesForEntityT();
80: final EntityManager em = getEntityManager("findReadsAttributesOfEntitySuperclass", false);
81: persistTestData(data, em);
82:
83: final OWLClassT result = em.find(OWLClassT.class, entityT.getUri());
84: assertNotNull(result);
85: assertEquals(entityT.getName(), result.getName());
86: assertEquals(entityT.getDescription(), result.getDescription());
87: assertEquals(entityT.getIntAttribute(), result.getIntAttribute());
88: assertNotNull(result.getOwlClassA());
89: assertEquals(entityA.getUri(), result.getOwlClassA().getUri());
90: }
91:
92: private Collection<Triple> triplesForEntityT() {
93: final Collection<Triple> data = new ArrayList<>();
94: entityT.setUri(Generators.generateUri());
95: data.add(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_T)));
96: data.add(new Triple(entityT.getUri(), URI.create(RDFS.LABEL), entityT.getName()));
97: data.add(new Triple(entityT.getUri(), URI.create(Vocabulary.DC_DESCRIPTION), entityT.getDescription()));
98: data.add(new Triple(entityT.getUri(), URI.create(Vocabulary.P_T_INTEGER_ATTRIBUTE), entityT.getIntAttribute()));
99: data.addAll(triplesForA());
100: data.add(new Triple(entityT.getUri(), URI.create(Vocabulary.P_HAS_OWL_CLASS_A), entityA.getUri()));
101: return data;
102: }
103:
104: @Test
105: void findLoadsSuperclassInstanceWhenRequestedAndClassAssertionIsPresent() throws Exception {
106: final EntityManager em = getEntityManager("findLoadsSuperclassInstanceWhenRequestedAndClassAssertionIsPresent",
107: false);
108: final Collection<Triple> data = triplesForEntityT();
109: data.add(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_S)));
110: persistTestData(data, em);
111:
112: final OWLClassS result = em.find(OWLClassS.class, entityT.getUri());
113: assertNotNull(result);
114: assertEquals(entityT.getName(), result.getName());
115: assertEquals(entityT.getDescription(), result.getDescription());
116: assertTrue(result.getTypes().contains(Vocabulary.C_OWL_CLASS_T));
117: }
118:
119: @Test
120: void findLoadsSubclassWhenSuperclassIsPassedInAndTypeCorrespondsToSubclass() throws Exception {
121: final Collection<Triple> data = triplesForEntityT();
122:
123: final EntityManager em = getEntityManager(
124: "findLoadsSubclassWhenSuperclassIsPassedInAndTypeCorrespondsToSubclass",
125: false);
126: persistTestData(data, em);
127:
128: final OWLClassS result = em.find(OWLClassS.class, entityT.getUri());
129: assertNotNull(result);
130: assertTrue(result instanceof OWLClassT);
131: verifyEntityTAttributes((OWLClassT) result);
132: }
133:
134: private void verifyEntityTAttributes(OWLClassT result) {
135: assertEquals(entityT.getName(), result.getName());
136: assertEquals(entityT.getDescription(), result.getDescription());
137: assertEquals(entityT.getIntAttribute(), result.getIntAttribute());
138: assertEquals(entityT.getOwlClassA().getUri(), result.getOwlClassA().getUri());
139: }
140:
141: @Test
142: void findLoadsSubclassOfAbstractParent() throws Exception {
143: final Collection<Triple> data = new ArrayList<>();
144: entityT.setUri(Generators.generateUri());
145: data.add(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_S)));
146: data.add(new Triple(entityT.getUri(), URI.create(RDFS.LABEL), entityT.getName()));
147: data.add(new Triple(entityT.getUri(), URI.create(Vocabulary.DC_DESCRIPTION), entityT.getDescription()));
148:
149: final EntityManager em = getEntityManager("findLoadsSubclassOfAbstractParent", false);
150: persistTestData(data, em);
151:
152: final OWLClassSParent result = em.find(OWLClassSParent.class, entityT.getUri());
153: assertNotNull(result);
154: assertTrue(result instanceof OWLClassS);
155: final OWLClassS sResult = (OWLClassS) result;
156: assertEquals(entityT.getName(), sResult.getName());
157: assertEquals(entityT.getDescription(), sResult.getDescription());
158: }
159:
160: @Test
161: void findLoadsMostConcreteSubclassOfAbstractAncestor() throws Exception {
162: final Collection<Triple> data = triplesForEntityT();
163: data.add(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_S)));
164:
165: final EntityManager em = getEntityManager("findLoadsMostConcreteSubclassOfAbstractAncestor", false);
166: persistTestData(data, em);
167:
168: final OWLClassSParent result = em.find(OWLClassSParent.class, entityT.getUri());
169: assertNotNull(result);
170: assertTrue(result instanceof OWLClassT);
171: verifyEntityTAttributes((OWLClassT) result);
172: }
173:
174: @Test
175: void findReturnsNullWhenMatchingClassIsAbstract() throws Exception {
176: final Collection<Triple> data = triplesForEntityT();
177: data.remove(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_T)));
178: data.add(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_S_PARENT)));
179:
180: final EntityManager em = getEntityManager("findReturnsNullWhenMatchingClassIsAbstract", false);
181: persistTestData(data, em);
182:
183: assertNull(em.find(OWLClassSParent.class, entityT.getUri()));
184: }
185:
186: @Test
187: void findReturnsMostSpecificSubtypeWhenReturnTypeIsAbstractAncestor() throws Exception {
188: final Collection<Triple> data = triplesForEntityT();
189: data.add(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_S)));
190: data.add(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_S_PARENT)));
191:
192: final EntityManager em = getEntityManager("findReturnsMostSpecificSubtypeWhenReturnTypeIsAbstractAncestor",
193: false);
194: persistTestData(data, em);
195:
196: final OWLClassSParent result = em.find(OWLClassSParent.class, entityT.getUri());
197: assertNotNull(result);
198: assertTrue(result instanceof OWLClassT);
199: verifyEntityTAttributes((OWLClassT) result);
200: }
201:
202: @Test
203: void findLoadsMostSpecificSubclassFromCache() {
204: this.em = getEntityManager("findLoadsMostSpecificSubclassFromCache", true);
205: persist(entityT, entityA);
206:
207: final OWLClassSParent result = em.find(OWLClassSParent.class, entityT.getUri());
208: assertNotNull(result);
209: assertTrue(result instanceof OWLClassT);
210: verifyEntityTAttributes((OWLClassT) result);
211: }
212:
213: @Test
214: void findLoadsInstanceOfSuperclassFromCacheWhenTypeMatchesAndIsSpecifiedAsReturnType() {
215: this.em = getEntityManager("findLoadsInstanceOfSuperclassWhenTypeMatchesAndIsSpecifiedAsReturnType", true);
216: persist(entityT, entityA);
217:
218: final OWLClassS result = em.find(OWLClassS.class, entityT.getUri());
219: assertNotNull(result);
220: assertEquals(entityT.getName(), result.getName());
221: assertEquals(entityT.getDescription(), result.getDescription());
222: }
223:
224: @Test
225: void findThrowsAmbiguousTypeExceptionWhenIndividualHasMultipleMostSpecificTypes() throws Exception {
226: final Collection<Triple> data = triplesForEntityT();
227: data.add(new Triple(entityT.getUri(), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_U)));
228: this.em = getEntityManager("findThrowsAmbiguousTypeExceptionWhenIndividualHasMultipleMostSpecificTypes", false);
229: persistTestData(data, em);
230:
231: assertThrows(AmbiguousEntityTypeException.class, () -> em.find(OWLClassS.class, entityT.getUri()));
232: }
233:
234: @Test
235: void findThrowsAmbiguousTypeExceptionWhenIndividualHasMultipleMostSpecificTypesInCache() {
236: this.em = getEntityManager("findThrowsAmbiguousTypeExceptionWhenIndividualHasMultipleMostSpecificTypesInCache",
237: true);
238: persist(entityT, entityA);
239: em.clear();
240: final OWLClassU sameIndividual = new OWLClassU();
241: sameIndividual.setUri(entityT.getUri());
242: sameIndividual.setName(entityT.getName());
243: persist(sameIndividual);
244: assertTrue(em.getEntityManagerFactory().getCache()
245: .contains(OWLClassT.class, entityT.getUri(), new EntityDescriptor()));
246: assertTrue(em.getEntityManagerFactory().getCache()
247: .contains(OWLClassU.class, sameIndividual.getUri(), new EntityDescriptor()));
248:
249: assertThrows(AmbiguousEntityTypeException.class, () -> em.find(OWLClassS.class, entityT.getUri()));
250: }
251:
252: @Test
253: void loadingEntityLoadsExactMatchOfPolymorphicAttribute() {
254: this.em = getEntityManager("loadingEntityLoadsExactMatchOfPolymorphicAttribute", false);
255: final OWLClassS s = new OWLClassS();
256: s.setName("s");
257: s.setDescription("S - description");
258: entityU.setOwlClassS(s);
259: persist(entityU, s);
260:
261: final OWLClassU result = em.find(OWLClassU.class, entityU.getUri());
262: assertNotNull(result);
263: assertNotNull(result.getOwlClassS());
264: assertEquals(s.getUri(), result.getOwlClassS().getUri());
265: assertEquals(s.getName(), result.getOwlClassS().getName());
266: assertEquals(s.getDescription(), result.getOwlClassS().getDescription());
267: }
268:
269: @Test
270: void loadingEntityLoadsCorrectSubtypeInPolymorphicAttribute() {
271: this.em = getEntityManager("loadingEntityLoadsCorrectSubtypeInPolymorphicAttribute", false);
272: persist(entityU, entityT, entityA);
273:
274: final OWLClassU result = em.find(OWLClassU.class, entityU.getUri());
275: assertNotNull(result.getOwlClassS());
276: assertTrue(result.getOwlClassS() instanceof OWLClassT);
277: final OWLClassT tResult = (OWLClassT) result.getOwlClassS();
278: verifyEntityTAttributes(tResult);
279: assertNotNull(tResult.getOwlClassA());
280: assertEquals(entityA.getUri(), tResult.getOwlClassA().getUri());
281: }
282: }