Skip to content

Package: DeleteOperationsRunner

DeleteOperationsRunner

nameinstructionbranchcomplexitylinemethod
DeleteOperationsRunner(Logger)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
clearingDatatypeCollectionRemovesAllValues()
M: 6 C: 52
90%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 0 C: 10
100%
M: 0 C: 1
100%
lambda$0(URI)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$1(OWLClassP, URI)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
removeDeletesAllPropertyAssertionsMappedByEntity()
M: 0 C: 85
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
removeEntityTwiceInOneTransactionRemovesIt()
M: 0 C: 57
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
resolveCProperties()
M: 21 C: 48
70%
M: 4 C: 8
67%
M: 3 C: 4
57%
M: 2 C: 9
82%
M: 0 C: 1
100%
settingDatatypeCollectionToNullRemovesAllValues()
M: 0 C: 50
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testClearUriTypes()
M: 0 C: 52
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testRemoveAllValuesOfPluralPlainIdentifierObjectProperty()
M: 0 C: 52
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testRemoveAllValuesOfTypedUnmappedProperty()
M: 0 C: 75
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
testRemoveAllValuesOfUnmappedProperty()
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%
testRemoveCascade()
M: 0 C: 154
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 30
100%
M: 0 C: 1
100%
testRemoveDetached()
M: 5 C: 52
91%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 10
83%
M: 0 C: 1
100%
testRemoveDetachedWithCascadedReferenceUsingMergeAndRemove()
M: 0 C: 103
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
testRemoveFromReferencedList()
M: 3 C: 121
98%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 2 C: 24
92%
M: 0 C: 1
100%
testRemoveFromSimpleList()
M: 3 C: 121
98%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 2 C: 24
92%
M: 0 C: 1
100%
testRemoveListOwner()
M: 0 C: 110
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
testRemoveMergedWithCascading()
M: 0 C: 116
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 22
100%
M: 0 C: 1
100%
testRemoveNotYetCommitted()
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testRemoveReference()
M: 63 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
testRemoveSimple()
M: 0 C: 52
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testRemoveTypedUnmappedPropertyValue()
M: 5 C: 103
95%
M: 2 C: 10
83%
M: 2 C: 5
71%
M: 2 C: 20
91%
M: 0 C: 1
100%
testRemoveUnmappedPropertyValue()
M: 1 C: 129
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 22
100%
M: 0 C: 1
100%
testSetAnnotationPropertyValueContainingUriToNull()
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%
testSetAnnotationPropertyValueToNull()
M: 0 C: 55
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
verifyDatatypePropertiesRemoved()
M: 0 C: 36
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 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.model.annotations.Id;
18: import cz.cvut.kbss.jopa.model.annotations.OWLAnnotationProperty;
19: import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty;
20: import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty;
21: import cz.cvut.kbss.jopa.test.*;
22: import cz.cvut.kbss.jopa.test.environment.Generators;
23: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
24: import org.junit.Ignore;
25: import org.junit.Test;
26: import org.slf4j.Logger;
27:
28: import java.lang.reflect.Field;
29: import java.net.URI;
30: import java.util.*;
31:
32: import static org.junit.Assert.*;
33:
34: public abstract class DeleteOperationsRunner extends BaseRunner {
35:
36: public DeleteOperationsRunner(Logger logger) {
37: super(logger);
38: }
39:
40: @Test
41: public void testRemoveSimple() {
42: this.em = getEntityManager("SimpleRemove", false);
43: persist(entityA);
44:
45: final OWLClassA a = em.find(OWLClassA.class, entityA.getUri());
46: assertNotNull(a);
47: em.getTransaction().begin();
48: em.remove(a);
49: em.getTransaction().commit();
50:
51: assertNull(em.find(OWLClassA.class, entityA.getUri()));
52: verifyIndividualWasRemoved(entityA.getUri());
53: }
54:
55: // TODO First we need to resolve referential integrity
56: @Ignore
57: @Test
58: public void testRemoveReference() {
59: this.em = getEntityManager("RemoveReference", false);
60: persist(entityD, entityA);
61:
62: final OWLClassA a = em.find(OWLClassA.class, entityA.getUri());
63: assertNotNull(a);
64: em.getTransaction().begin();
65: em.remove(a);
66: em.getTransaction().commit();
67:
68: final OWLClassD res = em.find(OWLClassD.class, entityD.getUri());
69: assertNotNull(res);
70: assertNull(em.find(OWLClassA.class, entityA.getUri()));
71: }
72:
73: @Test
74: public void testRemoveCascade() {
75: this.em = getEntityManager("RemoveCascade", false);
76: em.getTransaction().begin();
77: em.persist(entityG);
78: assertTrue(em.contains(entityG));
79: assertTrue(em.contains(entityH));
80: assertTrue(em.contains(entityA));
81: em.getTransaction().commit();
82:
83: em.getTransaction().begin();
84: final OWLClassG g = em.find(OWLClassG.class, entityG.getUri());
85: final OWLClassH h = em.find(OWLClassH.class, entityH.getUri());
86: final OWLClassA a = em.find(OWLClassA.class, entityA.getUri());
87: assertNotNull(g);
88: assertNotNull(h);
89: assertNotNull(a);
90: assertTrue(em.contains(g));
91: assertTrue(em.contains(h));
92: assertTrue(em.contains(a));
93: assertNotNull(g);
94: em.remove(g);
95: assertFalse(em.contains(g));
96: assertFalse(em.contains(h));
97: assertFalse(em.contains(a));
98: em.getTransaction().commit();
99:
100: assertNull(em.find(OWLClassG.class, entityG.getUri()));
101: assertNull(em.find(OWLClassH.class, entityH.getUri()));
102: assertNull(em.find(OWLClassA.class, entityA.getUri()));
103: verifyIndividualWasRemoved(entityG.getUri());
104: verifyIndividualWasRemoved(entityH.getUri());
105: verifyIndividualWasRemoved(entityA.getUri());
106: }
107:
108: @Test(expected = IllegalArgumentException.class)
109: public void testRemoveDetached() {
110: this.em = getEntityManager("RemoveDetached", false);
111: assertNull(entityE.getUri());
112: persist(entityE);
113: assertNotNull(entityE.getUri());
114:
115: em.getTransaction().begin();
116: final OWLClassE e = em.find(OWLClassE.class, entityE.getUri());
117: assertNotNull(e);
118: assertTrue(em.contains(e));
119: em.detach(e);
120: assertFalse(em.contains(e));
121: em.remove(e);
122: }
123:
124: @Test
125: public void testRemoveFromSimpleList() {
126: this.em = getEntityManager("RemoveFromSimpleList", false);
127: final int size = 5;
128: entityC.setSimpleList(Generators.createSimpleList(size));
129: em.getTransaction().begin();
130: em.persist(entityC);
131: entityC.getSimpleList().forEach(em::persist);
132: em.getTransaction().commit();
133:
134: final int randIndex = Generators.randomInt(size);
135: final OWLClassA a = em.find(OWLClassA.class, entityC.getSimpleList().get(randIndex).getUri());
136: assertNotNull(a);
137: final OWLClassC c = em.find(OWLClassC.class, entityC.getUri());
138: assertNotNull(c);
139: em.getTransaction().begin();
140: // We have to remove A from the simple list as well because otherwise we would break the chain in instances
141: assertTrue(c.getSimpleList().remove(a));
142: em.remove(a);
143: em.getTransaction().commit();
144:
145: final OWLClassA resA = em.find(OWLClassA.class, a.getUri());
146: assertNull(resA);
147: final OWLClassC resC = em.find(OWLClassC.class, entityC.getUri());
148: boolean found = false;
149:• for (OWLClassA aa : resC.getSimpleList()) {
150:• if (aa.getUri().equals(a.getUri())) {
151: found = true;
152: break;
153: }
154: }
155: assertFalse(found);
156: }
157:
158: @Test
159: public void testRemoveFromReferencedList() {
160: this.em = getEntityManager("RemoveFromReferencedList", false);
161: final int size = 10;
162: entityC.setReferencedList(Generators.createReferencedList(size));
163: em.getTransaction().begin();
164: em.persist(entityC);
165: entityC.getReferencedList().forEach(em::persist);
166: em.getTransaction().commit();
167:
168: final int randIndex = Generators.randomInt(size);
169: final OWLClassA a = em.find(OWLClassA.class, entityC.getReferencedList().get(randIndex).getUri());
170: assertNotNull(a);
171: final OWLClassC c = em.find(OWLClassC.class, entityC.getUri());
172: assertNotNull(c);
173: em.getTransaction().begin();
174: // We have to remove A from the referenced list as well because otherwise we would break the chain in instances
175: assertTrue(c.getReferencedList().remove(a));
176: em.remove(a);
177: em.getTransaction().commit();
178:
179: final OWLClassA resA = em.find(OWLClassA.class, a.getUri());
180: assertNull(resA);
181: final OWLClassC resC = em.find(OWLClassC.class, entityC.getUri());
182: boolean found = false;
183:• for (OWLClassA aa : resC.getReferencedList()) {
184:• if (aa.getUri().equals(a.getUri())) {
185: found = true;
186: break;
187: }
188: }
189: assertFalse(found);
190: }
191:
192: @Test
193: public void testRemoveListOwner() {
194: this.em = getEntityManager("RemoveListOwner", false);
195: entityC.setSimpleList(Generators.createSimpleList());
196: entityC.setReferencedList(Generators.createReferencedList());
197: em.getTransaction().begin();
198: em.persist(entityC);
199: entityC.getSimpleList().forEach(em::persist);
200: entityC.getReferencedList().forEach(em::persist);
201: em.getTransaction().commit();
202:
203: final OWLClassC c = em.find(OWLClassC.class, entityC.getUri());
204: assertNotNull(c);
205: em.getTransaction().begin();
206: em.remove(c);
207: em.getTransaction().commit();
208:
209: em.getEntityManagerFactory().getCache().evictAll();
210:• for (OWLClassA a : entityC.getSimpleList()) {
211: assertNotNull(em.find(OWLClassA.class, a.getUri()));
212: }
213:• for (OWLClassA a : entityC.getReferencedList()) {
214: assertNotNull(em.find(OWLClassA.class, a.getUri()));
215: }
216: }
217:
218: @Test
219: public void testRemoveNotYetCommitted() {
220: this.em = getEntityManager("RemoveNotYetCommitted", false);
221: em.getTransaction().begin();
222: em.persist(entityE);
223: assertTrue(em.contains(entityE));
224: em.remove(entityE);
225: assertFalse(em.contains(entityE));
226: em.getTransaction().commit();
227:
228: final OWLClassE res = em.find(OWLClassE.class, entityE.getUri());
229: assertNull(res);
230: }
231:
232: @Test
233: public void testRemoveMergedWithCascading() {
234: this.em = getEntityManager("CascadeMergeAndRemove", false);
235: em.getTransaction().begin();
236: em.persist(entityG);
237: assertTrue(em.contains(entityA));
238: assertTrue(em.contains(entityG));
239: assertTrue(em.contains(entityH));
240: em.getTransaction().commit();
241: em.clear();
242:
243: final OWLClassG toDetach = em.find(OWLClassG.class, entityG.getUri());
244: assertNotNull(toDetach);
245: em.detach(toDetach);
246: assertFalse(em.contains(toDetach));
247: assertFalse(em.contains(toDetach.getOwlClassH()));
248: assertFalse(em.contains(toDetach.getOwlClassH().getOwlClassA()));
249:
250: em.getTransaction().begin();
251: final OWLClassG toRemove = em.merge(toDetach);
252: em.remove(toRemove);
253: em.getTransaction().commit();
254:
255: assertNull(em.find(OWLClassG.class, entityG.getUri()));
256: assertNull(em.find(OWLClassH.class, entityH.getUri()));
257: assertNull(em.find(OWLClassA.class, entityA.getUri()));
258: }
259:
260: @Test
261: public void removeDeletesAllPropertyAssertionsMappedByEntity() throws Exception {
262: this.em = getEntityManager("RemoveDeletesAllMappedAttributes", false);
263: em.getTransaction().begin();
264: entityC.setSimpleList(Generators.createSimpleList(5));
265: em.persist(entityC);
266: entityC.getSimpleList().forEach(em::persist);
267: em.getTransaction().commit();
268:
269: final OWLClassC toRemove = em.find(OWLClassC.class, entityC.getUri());
270: em.getTransaction().begin();
271: em.remove(toRemove);
272: em.getTransaction().commit();
273:
274: final List<String> properties = resolveCProperties();
275:• for (String prop : properties) {
276: assertFalse(
277: em.createNativeQuery("ASK WHERE { ?x ?p ?o .}", Boolean.class).setParameter("x", entityC.getUri())
278: .setParameter("p", URI.create(prop)).getSingleResult());
279: }
280: }
281:
282: private List<String> resolveCProperties() throws Exception {
283: final List<String> lst = new ArrayList<>();
284:• for (Field f : OWLClassC.class.getDeclaredFields()) {
285:• if (f.getAnnotation(Id.class) != null || EntityPropertiesUtils.isFieldTransient(f)) {
286: continue;
287: }
288:• if (f.getAnnotation(OWLDataProperty.class) != null) {
289: lst.add(f.getAnnotation(OWLDataProperty.class).iri());
290:• } else if (f.getAnnotation(OWLObjectProperty.class) != null) {
291: lst.add(f.getAnnotation(OWLObjectProperty.class).iri());
292:• } else if (f.getAnnotation(OWLAnnotationProperty.class) != null) {
293: lst.add(f.getAnnotation(OWLAnnotationProperty.class).iri());
294: }
295: }
296: return lst;
297: }
298:
299: @Test
300: public void testRemoveUnmappedPropertyValue() {
301: entityB.setProperties(Generators.createProperties());
302: this.em = getEntityManager("RemoveUnmappedPropertyValue", false);
303: em.getTransaction().begin();
304: em.persist(entityB);
305: em.getTransaction().commit();
306:
307: final String property = entityB.getProperties().keySet().iterator().next();
308: final Set<String> values = entityB.getProperties().get(property);
309:• assertTrue(values.size() > 0);
310: final String valueToRemove = values.iterator().next();
311: em.getTransaction().begin();
312: final OWLClassB toUpdate = em.find(OWLClassB.class, entityB.getUri());
313: assertNotNull(toUpdate.getProperties());
314: assertTrue(toUpdate.getProperties().containsKey(property));
315: assertTrue(toUpdate.getProperties().get(property).contains(valueToRemove));
316: toUpdate.getProperties().get(property).remove(valueToRemove);
317: em.getTransaction().commit();
318:
319: final OWLClassB result = em.find(OWLClassB.class, entityB.getUri());
320: assertNotNull(result.getProperties());
321: assertTrue(result.getProperties().containsKey(property));
322: assertEquals(values.size() - 1, result.getProperties().get(property).size());
323: assertFalse(result.getProperties().get(property).contains(valueToRemove));
324: }
325:
326: @Test
327: public void testRemoveAllValuesOfUnmappedProperty() {
328: entityB.setProperties(Generators.createProperties());
329: this.em = getEntityManager("RemoveAllValuesOfUnmappedProperty", false);
330: em.getTransaction().begin();
331: em.persist(entityB);
332: em.getTransaction().commit();
333:
334: final String property = entityB.getProperties().keySet().iterator().next();
335: em.getTransaction().begin();
336: final OWLClassB toUpdate = em.find(OWLClassB.class, entityB.getUri());
337: assertNotNull(toUpdate.getProperties());
338: assertTrue(toUpdate.getProperties().containsKey(property));
339: toUpdate.getProperties().remove(property);
340: em.getTransaction().commit();
341:
342: final OWLClassB result = em.find(OWLClassB.class, entityB.getUri());
343: assertNotNull(result.getProperties());
344: assertFalse(result.getProperties().containsKey(property));
345: }
346:
347: @Test
348: public void testRemoveTypedUnmappedPropertyValue() {
349: this.em = getEntityManager("RemoveUnmappedPropertyValueTyped", false);
350: entityP.setProperties(Generators.createTypedProperties(10));
351: persist(entityP);
352:
353: em.getTransaction().begin();
354: final OWLClassP toUpdate = em.find(OWLClassP.class, entityP.getUri());
355:• for (Set<Object> set : toUpdate.getProperties().values()) {
356: final Iterator<Object> it = set.iterator();
357:• while (it.hasNext()) {
358: it.next();
359:• if (Generators.randomBoolean()) {
360: it.remove();
361: }
362: }
363: }
364: em.getTransaction().commit();
365: final Iterator<URI> it = toUpdate.getProperties().keySet().iterator();
366:• while (it.hasNext()) {
367: final URI property = it.next();
368:• if (toUpdate.getProperties().get(property).isEmpty()) {
369: it.remove();
370: }
371: }
372:• if (toUpdate.getProperties().isEmpty()) {
373: toUpdate.setProperties(null);
374: }
375:
376: final OWLClassP res = em.find(OWLClassP.class, entityP.getUri());
377: assertEquals(toUpdate.getProperties(), res.getProperties());
378: }
379:
380: @Test
381: public void testRemoveAllValuesOfTypedUnmappedProperty() {
382: this.em = getEntityManager("RemoveAllValuesOfUnmappedPropertyTyped", false);
383: entityP.setProperties(Generators.createTypedProperties(15));
384: persist(entityP);
385:
386: final OWLClassP toUpdate = em.find(OWLClassP.class, entityP.getUri());
387: em.detach(toUpdate);
388: // Copy the keys to prevent concurrent modification
389: final Set<URI> keys = new HashSet<>(toUpdate.getProperties().keySet());
390: keys.stream().filter(k -> Generators.randomBoolean())
391: .forEach(key -> toUpdate.getProperties().remove(key));
392: em.getTransaction().begin();
393: em.merge(toUpdate);
394: em.getTransaction().commit();
395:
396: final OWLClassP res = em.find(OWLClassP.class, entityP.getUri());
397: assertEquals(toUpdate.getProperties(), res.getProperties());
398: }
399:
400: @Test
401: public void testRemoveAllValuesOfPluralPlainIdentifierObjectProperty() {
402: this.em = getEntityManager("RemoveAllValuesOfPluralPlainIdentifierOP", false);
403: entityP.setIndividuals(Generators.createUrls());
404: persist(entityP);
405:
406: final OWLClassP toUpdate = em.find(OWLClassP.class, entityP.getUri());
407: em.getTransaction().begin();
408: toUpdate.getIndividuals().clear();
409: em.getTransaction().commit();
410:
411: final OWLClassP res = em.find(OWLClassP.class, entityP.getUri());
412: assertNull(res.getIndividuals());
413: }
414:
415: @Test
416: public void testSetAnnotationPropertyValueToNull() {
417: this.em = getEntityManager("SetAnnotationPropertyValueToNull", false);
418: entityN.setAnnotationProperty("annotationPropertyValue");
419: persist(entityN);
420:
421: final OWLClassN update = em.find(OWLClassN.class, entityN.getId());
422: assertNotNull(update.getAnnotationProperty());
423: em.getTransaction().begin();
424: update.setAnnotationProperty(null);
425: em.getTransaction().commit();
426:
427: final OWLClassN res = em.find(OWLClassN.class, entityN.getId());
428: assertNull(res.getAnnotationProperty());
429: }
430:
431: @Test
432: public void testSetAnnotationPropertyValueContainingUriToNull() {
433: this.em = getEntityManager("SetAnnotationPropertyValueContainingUriToNull", false);
434: entityN.setAnnotationUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa#annotationPropertyValue"));
435: persist(entityN);
436:
437: final OWLClassN update = em.find(OWLClassN.class, entityN.getId());
438: assertNotNull(update.getAnnotationUri());
439: em.getTransaction().begin();
440: update.setAnnotationUri(null);
441: em.getTransaction().commit();
442:
443: final OWLClassN res = em.find(OWLClassN.class, entityN.getId());
444: assertNull(res.getAnnotationUri());
445: }
446:
447: @Test
448: public void testClearUriTypes() {
449: this.em = getEntityManager("ClearUriTypes", false);
450: entityP.setTypes(Generators.createUriTypes());
451: persist(entityP);
452:
453: em.getTransaction().begin();
454: final OWLClassP update = em.find(OWLClassP.class, entityP.getUri());
455: update.getTypes().clear();
456: em.getTransaction().commit();
457:
458: final OWLClassP result = em.find(OWLClassP.class, entityP.getUri());
459: assertNull(result.getTypes());
460: }
461:
462: @Test
463: public void testRemoveDetachedWithCascadedReferenceUsingMergeAndRemove() {
464: this.em = getEntityManager("RemoveDetachedEntityWithCascadedReferenceUsingMergeAndRemove", true);
465: persist(entityH);
466: assertNotNull(em.find(OWLClassH.class, entityH.getUri()));
467: assertNotNull(em.find(OWLClassA.class, entityA.getUri()));
468: final OWLClassH h = new OWLClassH();
469: h.setUri(entityH.getUri());
470: final OWLClassA a = new OWLClassA();
471: a.setUri(entityA.getUri());
472: a.setStringAttribute(entityA.getStringAttribute());
473: a.setTypes(new HashSet<>(entityA.getTypes()));
474: h.setOwlClassA(a);
475:
476: em.clear();
477: em.getTransaction().begin();
478: final OWLClassH toRemove = em.merge(h);
479: em.remove(toRemove);
480: em.getTransaction().commit();
481:
482: assertNull(em.find(OWLClassH.class, entityH.getUri()));
483: assertNull(em.find(OWLClassA.class, entityA.getUri()));
484: }
485:
486: @Test
487: public void removeEntityTwiceInOneTransactionRemovesIt() {
488: this.em = getEntityManager("RemoveDetachedEntityWithCascadedReferenceUsingMergeAndRemove", true);
489: persist(entityA);
490:
491: em.getTransaction().begin();
492: final OWLClassA toRemove = em.merge(entityA);
493: em.remove(toRemove);
494: assertFalse(em.contains(toRemove));
495: em.remove(toRemove);
496: assertFalse(em.contains(toRemove));
497: em.getTransaction().commit();
498:
499: assertNull(em.find(OWLClassA.class, entityA.getUri()));
500: }
501:
502: @Test
503: public void settingDatatypeCollectionToNullRemovesAllValues() {
504: this.em = getEntityManager("settingDatatypeCollectionToNullRemovesAllValues", true);
505: persist(entityM);
506:
507: em.getTransaction().begin();
508: final OWLClassM toClear = em.find(OWLClassM.class, entityM.getKey());
509: toClear.setIntegerSet(null);
510: em.getTransaction().commit();
511:
512: final OWLClassM result = em.find(OWLClassM.class, entityM.getKey());
513: assertNull(result.getIntegerSet());
514: verifyDatatypePropertiesRemoved();
515: }
516:
517: private void verifyDatatypePropertiesRemoved() {
518:• for (Integer value : entityM.getIntegerSet()) {
519: assertFalse(em.createNativeQuery("ASK { ?x ?p ?v . }", Boolean.class)
520: .setParameter("x", URI.create(entityM.getKey()))
521: .setParameter("p", URI.create(Vocabulary.p_m_IntegerSet)).setParameter("v", value)
522: .getSingleResult());
523: }
524: }
525:
526: @Test
527: public void clearingDatatypeCollectionRemovesAllValues() {
528: this.em = getEntityManager("clearingDatatypeCollectionRemovesAllValues", true);
529: persist(entityM);
530:
531: em.getTransaction().begin();
532: final OWLClassM toClear = em.find(OWLClassM.class, entityM.getKey());
533: toClear.getIntegerSet().clear();
534: em.getTransaction().commit();
535:
536: final OWLClassM result = em.find(OWLClassM.class, entityM.getKey());
537: // Could be the cached variant, which contains empty collection, or loaded from ontology, which contains null
538:• assertTrue(result.getIntegerSet() == null || result.getIntegerSet().isEmpty());
539: verifyDatatypePropertiesRemoved();
540: }
541: }