-
Notifications
You must be signed in to change notification settings - Fork 14
/
GraphDBInferenceContextsTest.java
83 lines (72 loc) · 3.7 KB
/
GraphDBInferenceContextsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package cz.cvut.kbss.jopa.test.integration.graphdb;
import cz.cvut.kbss.jopa.Persistence;
import cz.cvut.kbss.jopa.model.EntityManager;
import cz.cvut.kbss.jopa.model.EntityManagerFactory;
import cz.cvut.kbss.jopa.model.JOPAPersistenceProperties;
import cz.cvut.kbss.jopa.model.JOPAPersistenceProvider;
import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
import cz.cvut.kbss.ontodriver.config.OntoDriverProperties;
import cz.cvut.kbss.ontodriver.sesame.SesameDataSource;
import cz.cvut.kbss.ontodriver.sesame.config.SesameOntoDriverProperties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class GraphDBInferenceContextsTest {
private static final String VOCABULARY = "http://onto.fel.cvut.cz/ontologies/slovnik/ml-test";
private Map<String, String> properties;
private EntityManagerFactory emf;
@BeforeEach
void setUp() {
this.properties = new HashMap<>();
properties.put(OntoDriverProperties.USE_TRANSACTIONAL_ONTOLOGY, Boolean.TRUE.toString());
properties.put(JOPAPersistenceProperties.SCAN_PACKAGE, "cz.cvut.kbss.jopa.test.integration.graphdb");
properties.put(JOPAPersistenceProperties.DATA_SOURCE_CLASS, SesameDataSource.class.getName());
properties.put(JOPAPersistenceProperties.ONTOLOGY_PHYSICAL_URI_KEY, System.getProperty("jopa.graphdb.url"));
properties.put(JOPAPersistenceProperties.JPA_PERSISTENCE_PROVIDER, JOPAPersistenceProvider.class.getName());
}
@AfterEach
void tearDown() {
emf.close();
}
/**
* Enhancement #106
*/
@Test
@EnabledIfSystemProperty(named = "jopa.graphdb.url", matches = "http(s)?://")
void inferredStatementsAreLoadedOneByOneEvenWhenDescriptorWithContextIsSpecified() {
this.emf = Persistence.createEntityManagerFactory("graphdbTestPU", properties);
final EntityManager em = emf.createEntityManager();
final URI vocabularyUri = URI.create(VOCABULARY);
final Descriptor descriptor = new EntityDescriptor(vocabularyUri);
final List<Term> result = em.createQuery("SELECT t FROM " + Term.class.getSimpleName() + " t WHERE t.vocabulary = :vocabulary", Term.class)
.setParameter("vocabulary", vocabularyUri)
.setDescriptor(descriptor).getResultList();
assertFalse(result.isEmpty());
result.forEach(t -> assertEquals(vocabularyUri, t.getVocabulary()));
}
/**
* Enhancement #106
*/
@Test
@EnabledIfSystemProperty(named = "jopa.graphdb.url", matches = "http(s)?://")
void inferredStatementsAreLoadedAllEvenWhenDescriptorWithContextIsSpecified() {
properties.put(SesameOntoDriverProperties.SESAME_LOAD_ALL_THRESHOLD, "1");
this.emf = Persistence.createEntityManagerFactory("graphdbTestPU", properties);
final EntityManager em = emf.createEntityManager();
final URI vocabularyUri = URI.create(VOCABULARY);
final Descriptor descriptor = new EntityDescriptor(vocabularyUri);
final List<Term> result = em.createQuery("SELECT t FROM " + Term.class.getSimpleName() + " t WHERE t.vocabulary = :vocabulary", Term.class)
.setParameter("vocabulary", vocabularyUri)
.setDescriptor(descriptor).getResultList();
assertFalse(result.isEmpty());
result.forEach(t -> assertEquals(vocabularyUri, t.getVocabulary()));
}
}