Skip to content

Package: DataTypesRunner

DataTypesRunner

nameinstructionbranchcomplexitylinemethod
DataTypesRunner(Logger, PersistenceFactory, DataAccessor)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
floatingPointAttributesSupportInfinityMapping()
M: 0 C: 42
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
lambda$persistSupportsSavingValueOfAttributeWithExplicitDatatype$0()
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$updatingExplicitDatatypeValuesIsSupported$1()
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%
persistSupportsSavingValueOfAttributeWithExplicitDatatype()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
pluralAttributesWithExplicitDatatypeAreSupported()
M: 0 C: 42
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
readSupportsValuesWithExplicitDatatype()
M: 0 C: 57
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
updatingExplicitDatatypeValuesIsSupported()
M: 0 C: 58
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.test.OWLClassM;
21: import cz.cvut.kbss.jopa.test.OWLClassX;
22: import cz.cvut.kbss.jopa.test.Vocabulary;
23: import cz.cvut.kbss.jopa.test.environment.DataAccessor;
24: import cz.cvut.kbss.jopa.test.environment.PersistenceFactory;
25: import cz.cvut.kbss.jopa.test.environment.Quad;
26: import cz.cvut.kbss.jopa.test.environment.TestEnvironment;
27: import cz.cvut.kbss.jopa.vocabulary.RDF;
28: import cz.cvut.kbss.ontodriver.model.Literal;
29: import org.junit.jupiter.api.Test;
30: import org.slf4j.Logger;
31:
32: import java.net.URI;
33: import java.util.Arrays;
34: import java.util.Set;
35: import java.util.stream.Collectors;
36: import java.util.stream.IntStream;
37:
38: import static org.junit.jupiter.api.Assertions.assertEquals;
39:
40: public abstract class DataTypesRunner extends BaseRunner {
41:
42: private static final String VALUE = "https://example.com/query{?firstName,lastName}";
43:
44: public DataTypesRunner(Logger logger, PersistenceFactory persistenceFactory, DataAccessor dataAccessor) {
45: super(logger, persistenceFactory, dataAccessor);
46: }
47:
48: @Test
49: public void persistSupportsSavingValueOfAttributeWithExplicitDatatype() {
50: this.em = getEntityManager("persistSupportsSavingValueOfAttributeWithExplicitDatatype", false);
51: entityM.setExplicitDatatype(VALUE);
52: transactional(() -> em.persist(entityM));
53:
54: verifyValueDatatype(URI.create(entityM.getKey()), Vocabulary.p_m_explicitDatatype,
55: TestEnvironment.EXPLICIT_DATATYPE);
56: }
57:
58: @Test
59: public void readSupportsValuesWithExplicitDatatype() throws Exception {
60: this.em = getEntityManager("readSupportsValuesWithExplicitDatatype", false);
61: persistTestData(Arrays.asList(
62: new Quad(URI.create(entityM.getKey()), URI.create(RDF.TYPE), URI.create(Vocabulary.C_OWL_CLASS_M)),
63: new Quad(URI.create(entityM.getKey()), URI.create(Vocabulary.p_m_explicitDatatype),
64: new Literal(VALUE, TestEnvironment.EXPLICIT_DATATYPE))
65: ), em);
66:
67: final OWLClassM result = findRequired(OWLClassM.class, entityM.getKey());
68: assertEquals(VALUE, result.getExplicitDatatype());
69: }
70:
71: @Test
72: public void updatingExplicitDatatypeValuesIsSupported() {
73: this.em = getEntityManager("updatingExplicitDatatypeValuesIsSupported", true);
74: entityM.setExplicitDatatype(VALUE);
75: persist(entityM);
76:
77: final String newValue = "https://example.com/query{?givenName,familyName}";
78: transactional(() -> {
79: final OWLClassM toUpdate = findRequired(OWLClassM.class, entityM.getKey());
80: toUpdate.setExplicitDatatype(newValue);
81: });
82:
83: final OWLClassM cachedResult = findRequired(OWLClassM.class, entityM.getKey());
84: assertEquals(newValue, cachedResult.getExplicitDatatype());
85: em.getEntityManagerFactory().getCache().evictAll();
86: em.clear();
87:
88: final OWLClassM result = findRequired(OWLClassM.class, entityM.getKey());
89: assertEquals(newValue, result.getExplicitDatatype());
90: }
91:
92: @Test
93: public void pluralAttributesWithExplicitDatatypeAreSupported() {
94: this.em = getEntityManager("pluralAttributesWithExplicitDatatypeAreSupported", false);
95: final OWLClassX entity = new OWLClassX();
96: final Set<String> values = IntStream.range(0, 5)
97: .mapToObj(Integer::toString)
98: .collect(Collectors.toSet());
99: entity.setExplicitDatatypes(values);
100:
101: persist(entity);
102:
103: final OWLClassX result = findRequired(OWLClassX.class, entity.getUri());
104: assertEquals(values, result.getExplicitDatatypes());
105: }
106:
107: @Test
108: public void floatingPointAttributesSupportInfinityMapping() {
109: this.em = getEntityManager("floatingPointAttributesSupportInfinity", false);
110: entityM.setFloatAttribute(Float.NEGATIVE_INFINITY);
111: entityM.setDoubleAttribute(Double.POSITIVE_INFINITY);
112: persist(entityM);
113:
114: final OWLClassM result = findRequired(OWLClassM.class, entityM.getKey());
115: assertEquals(Float.NEGATIVE_INFINITY, result.getFloatAttribute());
116: assertEquals(Double.POSITIVE_INFINITY, result.getDoubleAttribute());
117: }
118: }