Skip to content

Package: MultipleInheritanceTestRunner

MultipleInheritanceTestRunner

nameinstructionbranchcomplexitylinemethod
MultipleInheritanceTestRunner(Logger, PersistenceFactory, DataAccessor)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
annotatedMethodPassesDownAnnotationValuesFromMultipleParents()
M: 0 C: 89
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
annotatedMethodPassesDownAnnotationValuesFromSingleParent()
M: 0 C: 67
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
annotationInheritedThroughTwoWaysIsHandledProperly()
M: 0 C: 66
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
entityCanBeFoundByBothParentTypes()
M: 0 C: 70
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
mappedSuperClassSupportsAnnotatedMethods()
M: 0 C: 46
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.test.runner;
19:
20: import cz.cvut.kbss.jopa.model.IRI;
21: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
22: import cz.cvut.kbss.jopa.test.ChildOfMappedSuperClass;
23: import cz.cvut.kbss.jopa.test.OWLChildClassA;
24: import cz.cvut.kbss.jopa.test.OWLChildClassB;
25: import cz.cvut.kbss.jopa.test.OWLChildClassC;
26: import cz.cvut.kbss.jopa.test.OWLClassWithUnProperties;
27: import cz.cvut.kbss.jopa.test.OWLInterfaceA;
28: import cz.cvut.kbss.jopa.test.OWLInterfaceAnMethods;
29: import cz.cvut.kbss.jopa.test.OWLInterfaceB;
30: import cz.cvut.kbss.jopa.test.OWLParentA;
31: import cz.cvut.kbss.jopa.test.OWLParentB;
32: import cz.cvut.kbss.jopa.test.Vocabulary;
33: import cz.cvut.kbss.jopa.test.environment.DataAccessor;
34: import cz.cvut.kbss.jopa.test.environment.Generators;
35: import cz.cvut.kbss.jopa.test.environment.PersistenceFactory;
36: import org.junit.jupiter.api.Test;
37: import org.slf4j.Logger;
38:
39: import java.net.URI;
40: import java.util.Collections;
41:
42: import static org.junit.jupiter.api.Assertions.assertEquals;
43: import static org.junit.jupiter.api.Assertions.assertNotNull;
44:
45: public abstract class MultipleInheritanceTestRunner extends BaseRunner {
46: protected OWLClassWithUnProperties classWithUnProperties;
47:
48: public MultipleInheritanceTestRunner(Logger logger, PersistenceFactory persistenceFactory, DataAccessor dataAccessor) {
49: super(logger, persistenceFactory, dataAccessor);
50: classWithUnProperties = new OWLClassWithUnProperties(Generators.generateUri());
51: }
52:
53:
54: @Test
55: void entityCanBeFoundByBothParentTypes() {
56: this.em = getEntityManager("entityCanBeFoundByBothParentTypes", false);
57:
58: URI id = Generators.generateUri();
59: final OWLChildClassA child = new OWLChildClassA();
60: child.setId(id);
61: child.setStringAttribute("AttRVal");
62: child.setPluralAnnotationProperty(Collections.singleton("seeet"));
63: persist(child);
64:
65: final OWLChildClassA found = findRequired(OWLChildClassA.class, id);
66: em.clear();
67: final OWLParentB parentBFound = findRequired(OWLParentB.class, id);
68: em.clear();
69: final OWLParentA parentAFound = findRequired(OWLParentA.class, id);
70:
71: assertEquals(child.getId(), found.getId());
72: assertEquals(child.getStringAttribute(), parentBFound.getStringAttribute());
73: assertEquals(child.getPluralAnnotationProperty(), parentAFound.getPluralAnnotationProperty());
74: }
75:
76: @Test
77: void annotatedMethodPassesDownAnnotationValuesFromSingleParent() {
78: this.em = getEntityManager("annotatedMethodPassesDownAnnotationValues", false);
79:
80: classWithUnProperties.setName("NAME_VALUE");
81: classWithUnProperties.setTitles(Collections.singleton("title"));
82: persist(classWithUnProperties);
83:
84: OWLClassWithUnProperties found = em.find(OWLClassWithUnProperties.class, classWithUnProperties.getId());
85:
86: IRI namePropertyIRI = em.getMetamodel().entity(OWLClassWithUnProperties.class).getDeclaredAttribute("name").getIRI();
87:
88: assertNotNull(found);
89: assertEquals(classWithUnProperties.getName(), found.getName());
90: assertEquals(classWithUnProperties.getId(), found.getId());
91: assertEquals(Vocabulary.p_m_unannotated_name, namePropertyIRI.toString());
92: assertEquals(classWithUnProperties.getTitles(), found.getTitles());
93:
94: }
95:
96: @Test
97: void annotatedMethodPassesDownAnnotationValuesFromMultipleParents() {
98: this.em = getEntityManager("annotatedMethodPassesDownAnnotationValuesFromMultipleParents", false);
99:
100: URI id = Generators.generateUri();
101: final OWLChildClassB child = new OWLChildClassB();
102: child.setId(id);
103: child.setAttributeA("Value");
104: child.setAttributeB(Boolean.FALSE);
105: persist(child);
106:
107: final OWLChildClassB found = findRequired(OWLChildClassB.class, id);
108: em.clear();
109: final OWLInterfaceA parentAFound = findRequired(OWLInterfaceA.class, id);
110: em.clear();
111: final OWLInterfaceB parentBFound = findRequired(OWLInterfaceB.class, id);
112:
113: assertEquals(child.getId(), found.getId());
114: assertEquals(child.getAttributeA(), parentAFound.getAttributeA());
115: assertEquals(child.getAttributeB(), parentBFound.getAttributeB());
116:
117: EntityType<OWLChildClassB> childEt = em.getMetamodel().entity(OWLChildClassB.class);
118:
119: assertEquals(Vocabulary.p_m_attributeA, childEt.getDeclaredAttribute("attributeA").getIRI().toString());
120: assertEquals(Vocabulary.p_m_attributeB, childEt.getDeclaredAttribute("attributeB").getIRI().toString());
121: }
122:
123: @Test
124: void annotationInheritedThroughTwoWaysIsHandledProperly() {
125: this.em = getEntityManager("annotationInheritedThroughTwoWaysIsHandledProperly", false);
126: URI id = Generators.generateUri();
127:
128: final OWLChildClassC child = new OWLChildClassC();
129: child.setId(id);
130: child.setName("Name");
131: child.setAttributeB(Generators.randomBoolean());
132: persist(child);
133:
134: final OWLChildClassC found = findRequired(OWLChildClassC.class, id);
135: em.clear();
136: final OWLInterfaceAnMethods commonParentFound = findRequired(OWLInterfaceAnMethods.class, id);
137:
138: assertEquals(child.getId(), found.getId());
139: assertEquals(child.getName(), found.getName());
140: assertEquals(child.getAttributeB(), found.getAttributeB());
141:
142: assertEquals(child.getName(), commonParentFound.getName());
143: }
144:
145: @Test
146: void mappedSuperClassSupportsAnnotatedMethods() {
147: this.em = getEntityManager("mappedSuperClassSupportsAnnotatedMethods", false);
148:
149: ChildOfMappedSuperClass childOfMappedSuperClass = new ChildOfMappedSuperClass();
150: URI uri = Generators.generateUri();
151:
152: String label = "LABEL_VALUE";
153: childOfMappedSuperClass.setUri(uri);
154: childOfMappedSuperClass.setLabel(label);
155:
156: persist(childOfMappedSuperClass);
157:
158:
159: verifyExists(ChildOfMappedSuperClass.class, uri);
160: em.clear();
161: final ChildOfMappedSuperClass found = findRequired(ChildOfMappedSuperClass.class, uri);
162: assertEquals(label, found.getLabel());
163: }
164: }