Skip to content

Method: testRemoveFromReferencedList()

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