Skip to content

Method: lambda$2(Descriptor)

1: /**
2: * Copyright (C) 2020 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.model.descriptors.Descriptor;
18: import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
19: import cz.cvut.kbss.jopa.test.*;
20: import cz.cvut.kbss.jopa.test.environment.DataAccessor;
21: import cz.cvut.kbss.jopa.test.environment.PersistenceFactory;
22: import org.junit.jupiter.api.Test;
23: import org.slf4j.Logger;
24:
25: import java.net.URI;
26:
27: import static org.junit.jupiter.api.Assertions.*;
28:
29: public abstract class DeleteOperationsMultiContextRunner extends BaseRunner {
30:
31: public DeleteOperationsMultiContextRunner(Logger logger, PersistenceFactory persistenceFactory,
32: DataAccessor dataAccessor) {
33: super(logger, persistenceFactory, dataAccessor);
34: }
35:
36: @Test
37: void testRemoveFromContext() {
38: this.em = getEntityManager("MultiRemoveFromContext", false);
39: final Descriptor aDescriptor = new EntityDescriptor(CONTEXT_ONE);
40: transactional(() -> em.persist(entityA, aDescriptor));
41:
42: final OWLClassA a = findRequired(OWLClassA.class, entityA.getUri(), aDescriptor);
43: transactional(() -> {
44: em.remove(a);
45: assertFalse(em.contains(a));
46: });
47:
48: final OWLClassA res = em.find(OWLClassA.class, entityA.getUri(), aDescriptor);
49: assertNull(res);
50: }
51:
52: @Test
53: void testRemoveFromOneKeepInTheOther() {
54: this.em = getEntityManager("MultiRemoveFromOneContextAndKeepInTheOther", false);
55: final Descriptor aDescriptorOne = new EntityDescriptor(CONTEXT_ONE);
56: final Descriptor aDescriptorTwo = new EntityDescriptor(CONTEXT_TWO);
57: transactional(() -> em.persist(entityA, aDescriptorOne));
58: transactional(() -> em.persist(entityA, aDescriptorTwo));
59:
60: findRequired(OWLClassA.class, entityA.getUri(), aDescriptorOne);
61: final OWLClassA aTwo = findRequired(OWLClassA.class, entityA.getUri(), aDescriptorTwo);
62: transactional(() -> em.remove(aTwo));
63:
64: findRequired(OWLClassA.class, entityA.getUri(), aDescriptorOne);
65: final OWLClassA resTwo = em.find(OWLClassA.class, entityA.getUri(), aDescriptorTwo);
66: assertNull(resTwo);
67: }
68:
69: @Test
70: void testRemoveObjectPropertyFromContext() {
71: this.em = getEntityManager("MultiRemoveObjectPropertyFromContext", false);
72: final Descriptor dDescriptor = new EntityDescriptor(CONTEXT_ONE);
73: final Descriptor aDescriptor = new EntityDescriptor(CONTEXT_TWO);
74: dDescriptor.addAttributeDescriptor(fieldSpecification(OWLClassD.class, "owlClassA"), aDescriptor);
75: transactional(() -> {
76: em.persist(entityD, dDescriptor);
77: em.persist(entityA, aDescriptor);
78: });
79:
80: final OWLClassD d = findRequired(OWLClassD.class, entityD.getUri(), dDescriptor);
81: final OWLClassA a = d.getOwlClassA();
82: assertNotNull(a);
83: d.setOwlClassA(null);
84: transactional(() -> em.remove(a));
85:
86: final OWLClassD resD = findRequired(OWLClassD.class, entityD.getUri(), dDescriptor);
87: assertNull(resD.getOwlClassA());
88: final OWLClassA resA = em.find(OWLClassA.class, entityA.getUri(), aDescriptor);
89: assertNull(resA);
90: }
91:
92: @Test
93: void testRemoveCascadeOverContexts() {
94: this.em = getEntityManager("MultiRemoveCascadeOverContexts", false);
95: final Descriptor gDescriptor = new EntityDescriptor();
96: final Descriptor hDescriptor = new EntityDescriptor(CONTEXT_ONE);
97: final Descriptor aDescriptor = new EntityDescriptor(CONTEXT_TWO);
98: hDescriptor.addAttributeDescriptor(fieldSpecification(OWLClassH.class, "owlClassA"), aDescriptor);
99: gDescriptor.addAttributeDescriptor(fieldSpecification(OWLClassG.class, "owlClassH"), hDescriptor);
100: transactional(() -> em.persist(entityG, gDescriptor));
101:
102: final OWLClassA a = findRequired(OWLClassA.class, entityA.getUri(), aDescriptor);
103: final OWLClassH h = findRequired(OWLClassH.class, entityH.getUri(), hDescriptor);
104: assertSame(a, h.getOwlClassA());
105: final OWLClassG g = findRequired(OWLClassG.class, entityG.getUri(), gDescriptor);
106: assertSame(h, g.getOwlClassH());
107: transactional(() -> em.remove(g));
108:
109: assertNull(em.find(OWLClassA.class, entityA.getUri(), aDescriptor));
110: assertNull(em.find(OWLClassH.class, entityH.getUri(), hDescriptor));
111: assertNull(em.find(OWLClassG.class, entityG.getUri(), gDescriptor));
112: }
113:
114: @Test
115: void removeRemovesObjectPropertyAssertionFromTargetContext() {
116: this.em = getEntityManager("removeRemovesObjectPropertyAssertionFromTargetContext", false);
117: final Descriptor dDescriptor = new EntityDescriptor(CONTEXT_ONE, false);
118: final Descriptor aDescriptor = new EntityDescriptor(CONTEXT_TWO);
119: dDescriptor.addAttributeDescriptor(fieldSpecification(OWLClassD.class, "owlClassA"), aDescriptor);
120: transactional(() -> {
121: em.persist(entityD, dDescriptor);
122: em.persist(entityA, aDescriptor);
123: });
124:
125: transactional(() -> {
126: final OWLClassD d = findRequired(OWLClassD.class, entityD.getUri(), dDescriptor);
127: d.setOwlClassA(null);
128: });
129:
130: assertFalse(em.createNativeQuery("ASK { ?s ?p ?o . }", Boolean.class)
131: .setParameter("p", entityD.getUri())
132: .setParameter("p", URI.create(Vocabulary.P_HAS_OWL_CLASS_A))
133: .setParameter("o", entityA.getUri())
134: .getSingleResult());
135: assertNotNull(em.find(OWLClassA.class, entityA.getUri(), aDescriptor));
136: }
137: }