Skip to content

Package: SoqlRunner

SoqlRunner

nameinstructionbranchcomplexitylinemethod
SoqlRunner(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%
lambda$0(OWLClassA, OWLClassA)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$2(OWLClassT, OWLClassT)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
testFindByConjunctionOfAttributes()
M: 0 C: 49
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
testFindByDataNotPropertyAttribute()
M: 0 C: 39
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testFindByDataNotPropertyAttributeAndPropertyAttribute()
M: 1 C: 55
98%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 12
100%
M: 0 C: 1
100%
testFindByDataPropertyAttribute()
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testFindByDisjunctionOfAttributes()
M: 1 C: 58
98%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 12
100%
M: 0 C: 1
100%
testFindByObjectPropertyAttribute()
M: 0 C: 31
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testFindByTransitiveAttributeValue()
M: 0 C: 32
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testOrderBy()
M: 0 C: 37
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testSimpleCount()
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testSimpleFindAll()
M: 0 C: 36
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%

Coverage

1: package cz.cvut.kbss.jopa.test.query.runner;
2:
3: import cz.cvut.kbss.jopa.test.OWLClassA;
4: import cz.cvut.kbss.jopa.test.OWLClassD;
5: import cz.cvut.kbss.jopa.test.OWLClassT;
6: import cz.cvut.kbss.jopa.test.environment.Generators;
7: import cz.cvut.kbss.jopa.test.query.QueryTestEnvironment;
8: import org.junit.jupiter.api.Test;
9: import org.slf4j.Logger;
10:
11: import java.util.Comparator;
12: import java.util.List;
13:
14: import static org.hamcrest.MatcherAssert.assertThat;
15: import static org.hamcrest.Matchers.lessThanOrEqualTo;
16: import static org.junit.jupiter.api.Assertions.*;
17:
18: public abstract class SoqlRunner extends BaseQueryRunner {
19:
20: protected SoqlRunner(Logger logger) {
21: super(logger);
22: }
23:
24: @Test
25: public void testSimpleFindAll() {
26: final List<OWLClassA> expected = QueryTestEnvironment.getData(OWLClassA.class);
27: final List<OWLClassA> result = getEntityManager().createQuery("SELECT a FROM OWLClassA a", OWLClassA.class)
28: .getResultList();
29: assertEquals(expected.size(), result.size());
30:• for (OWLClassA a : result) {
31: assertNotNull(a.getStringAttribute());
32: assertTrue(expected.stream().anyMatch(aa -> aa.getUri().equals(a.getUri())));
33: }
34: }
35:
36: @Test
37: public void testSimpleCount() {
38: final List<OWLClassA> expected = QueryTestEnvironment.getData(OWLClassA.class);
39: final Object result = getEntityManager().createQuery("SELECT DISTINCT COUNT(a) FROM OWLClassA a")
40: .getSingleResult();
41: assertEquals(expected.size(), result);
42: }
43:
44: @Test
45: public void testFindByDataPropertyAttribute() {
46: final OWLClassA expected = Generators.getRandomItem(QueryTestEnvironment.getData(OWLClassA.class));
47: final OWLClassA result = getEntityManager()
48: .createQuery("SELECT a FROM OWLClassA a WHERE a.stringAttribute = :str", OWLClassA.class)
49: .setParameter("str", expected.getStringAttribute(), "en").getSingleResult();
50: assertEquals(expected.getUri(), result.getUri());
51: assertEquals(expected.getStringAttribute(), result.getStringAttribute());
52: assertEquals(expected.getTypes(), result.getTypes());
53: }
54:
55: @Test
56: public void testFindByDataNotPropertyAttribute() {
57: final OWLClassA unexpected = Generators.getRandomItem(QueryTestEnvironment.getData(OWLClassA.class));
58: final List<OWLClassA> result = getEntityManager()
59: .createQuery("SELECT a FROM OWLClassA a WHERE NOT a.stringAttribute = :str", OWLClassA.class)
60: .setParameter("str", unexpected.getStringAttribute(), "en").getResultList();
61:• for (OWLClassA item : result) {
62: assertNotEquals(unexpected.getUri(), item.getUri());
63: assertNotEquals(unexpected.getStringAttribute(), item.getStringAttribute());
64: }
65: }
66:
67: @Test
68: public void testFindByDataNotPropertyAttributeAndPropertyAttribute() {
69: final OWLClassT unexpected = Generators.getRandomItem(QueryTestEnvironment.getData(OWLClassT.class));
70: final int intThreshold = QueryTestEnvironment.getData(OWLClassT.class).size() / 2;
71: final List<OWLClassT> result = getEntityManager()
72: .createQuery("SELECT t FROM OWLClassT t WHERE NOT t.owlClassA = :a AND t.intAttribute < :intAtt",
73: OWLClassT.class)
74: .setParameter("a", unexpected.getOwlClassA().getUri())
75: .setParameter("intAtt", intThreshold).getResultList();
76: assertFalse(result.isEmpty());
77:• for (OWLClassT item : result) {
78: assertNotEquals(unexpected.getUri(), item.getUri());
79:• assertTrue(intThreshold > item.getIntAttribute());
80: }
81: }
82:
83: @Test
84: public void testFindByObjectPropertyAttribute() {
85: final OWLClassD expected = Generators.getRandomItem(QueryTestEnvironment.getData(OWLClassD.class));
86: final OWLClassD result = getEntityManager()
87: .createQuery("SELECT d FROM OWLClassD d WHERE d.owlClassA = :a", OWLClassD.class)
88: .setParameter("a", expected.getOwlClassA().getUri()).getSingleResult();
89: assertEquals(expected.getUri(), result.getUri());
90: assertEquals(expected.getOwlClassA().getUri(), result.getOwlClassA().getUri());
91: }
92:
93: @Test
94: public void testFindByConjunctionOfAttributes() {
95: final OWLClassT sample = Generators.getRandomItem(QueryTestEnvironment.getData(OWLClassT.class));
96: final List<OWLClassT> result = getEntityManager()
97: .createQuery("SELECT t FROM OWLClassT t WHERE t.owlClassA = :a AND t.intAttribute <= :intAtt",
98: OWLClassT.class)
99: .setParameter("a", sample.getOwlClassA().getUri())
100: .setParameter("intAtt", sample.getIntAttribute()).getResultList();
101: assertFalse(result.isEmpty());
102:• for (OWLClassT item : result) {
103: assertEquals(sample.getOwlClassA().getUri(), item.getOwlClassA().getUri());
104: assertThat(item.getIntAttribute(), lessThanOrEqualTo(sample.getIntAttribute()));
105: }
106: }
107:
108: @Test
109: public void testOrderBy() {
110: final List<OWLClassT> expected = QueryTestEnvironment.getData(OWLClassT.class);
111: expected.sort(Comparator.comparing(OWLClassT::getIntAttribute));
112: final List<OWLClassT> result = getEntityManager()
113: .createQuery("SELECT t FROM OWLClassT t ORDER BY t.intAttribute", OWLClassT.class).getResultList();
114: assertEquals(expected.size(), result.size());
115:• for (OWLClassT t : result) {
116: assertTrue(expected.stream().anyMatch(tt -> tt.getUri().equals(t.getUri())));
117: }
118: }
119:
120: @Test
121: public void testFindByDisjunctionOfAttributes() {
122: final OWLClassT sample = Generators.getRandomItem(QueryTestEnvironment.getData(OWLClassT.class));
123: final List<OWLClassT> result = getEntityManager()
124: .createQuery("SELECT t FROM OWLClassT t WHERE t.owlClassA = :a OR t.intAttribute <= :intAtt",
125: OWLClassT.class)
126: .setParameter("a", sample.getOwlClassA().getUri())
127: .setParameter("intAtt", sample.getIntAttribute()).getResultList();
128: assertFalse(result.isEmpty());
129:• for (OWLClassT item : result) {
130: boolean matches = item.getOwlClassA().getUri().equals(sample.getOwlClassA().getUri());
131:• matches |= item.getIntAttribute() <= sample.getIntAttribute();
132: assertTrue(matches);
133: }
134: }
135:
136: @Test
137: public void testFindByTransitiveAttributeValue() {
138: final OWLClassD expected = Generators.getRandomItem(QueryTestEnvironment.getData(OWLClassD.class));
139: final OWLClassD result = getEntityManager()
140: .createQuery("SELECT d FROM OWLClassD d WHERE d.owlClassA.stringAttribute = :stringAtt",
141: OWLClassD.class)
142: .setParameter("stringAtt", expected.getOwlClassA().getStringAttribute(), "en").getSingleResult();
143: assertEquals(expected.getUri(), result.getUri());
144: assertEquals(expected.getOwlClassA().getUri(), result.getOwlClassA().getUri());
145: }
146: }