SesameAdapter implements Closeable, Wrapper { Collection<Axiom<?>> find(AxiomDescriptor axiomDescriptor) throws SesameDriverException { startTransactionIfNotActive(); return new AxiomLoader(connector, valueFactory, config).loadAxioms(axiomDescriptor); } SesameAdapter(Connector connector, DriverConfiguration configuration); @Override void close(); @Override boolean isOpen(); @Override T unwrap(Class<T> cls);  }
@Test void testFindEntityWithDataProperty() throws Exception { final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); desc.addAssertion(Assertion.createClassAssertion(false)); final String property = "http: desc.addAssertion(Assertion.createDataPropertyAssertion(URI.create(property), false)); final Map<Assertion, Statement> statements = initStatementsForDescriptor(desc); for (Assertion as : statements.keySet()) { final org.eclipse.rdf4j.model.IRI predicate = vf.createIRI(as.getIdentifier().toString()); when( connectorMock.findStatements(subjectIri, predicate, null, as.isInferred(), null)).thenReturn( Collections.singletonList(statements.get(as))); } final Collection<Axiom<?>> res = adapter.find(desc); verify(connectorMock, times(2)).findStatements(any(Resource.class), any(org.eclipse.rdf4j.model.IRI.class), any(), anyBoolean(), eq(null)); assertEquals(statements.size(), res.size()); for (Axiom<?> ax : res) { assertTrue(statements.containsKey(ax.getAssertion())); assertEquals(statements.get(ax.getAssertion()).getObject().stringValue(), ax.getValue() .getValue().toString()); } }
@Test void testFindEntityWithObjectPropertyAndInferredAnnotationProperty() throws Exception { final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); desc.addAssertion(Assertion.createClassAssertion(false)); final String anProperty = "http: desc.addAssertion(Assertion.createAnnotationPropertyAssertion(URI.create(anProperty), true)); final String obProperty = "http: desc.addAssertion(Assertion.createObjectPropertyAssertion(URI.create(obProperty), false)); final Map<Assertion, Statement> statements = initStatementsForDescriptor(desc); for (Assertion as : statements.keySet()) { final org.eclipse.rdf4j.model.IRI predicate = vf.createIRI(as.getIdentifier().toString()); when( connectorMock.findStatements(subjectIri, predicate, null, as.isInferred(), null)).thenReturn( Collections.singletonList(statements.get(as))); } final Collection<Axiom<?>> res = adapter.find(desc); verify(connectorMock, times(3)).findStatements(any(Resource.class), any(org.eclipse.rdf4j.model.IRI.class), any(), anyBoolean(), eq(null)); verify(connectorMock, times(1)).findStatements(eq(subjectIri), eq(vf.createIRI(anProperty)), eq(null), eq(true), eq(null)); assertEquals(statements.size(), res.size()); for (Axiom<?> ax : res) { assertTrue(statements.containsKey(ax.getAssertion())); assertEquals(statements.get(ax.getAssertion()).getObject().stringValue(), ax.getValue() .getValue().toString()); } }
@Test void testFindEntityWithProperties() throws Exception { final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); desc.addAssertion(Assertion.createUnspecifiedPropertyAssertion(false)); final String propertyOne = "http: final String propertyTwo = "http: desc.addAssertion(Assertion.createDataPropertyAssertion(URI.create(propertyTwo), false)); final Map<Assertion, List<Statement>> statements = new HashMap<>(); final Collection<Statement> stmts = new ArrayList<>(); final Assertion asOne = Assertion.createPropertyAssertion(URI.create(propertyOne), false); statements.put(asOne, createStatementsForProperty(propertyOne, true)); final Assertion asTwo = Assertion.createPropertyAssertion(URI.create(propertyTwo), false); statements.put(asTwo, createStatementsForProperty(propertyTwo, false)); for (Assertion a : statements.keySet()) { stmts.addAll(statements.get(a)); } when( connectorMock.findStatements(subjectIri, null, null, false)).thenReturn(stmts); when(connectorMock.findStatements(subjectIri, vf.createIRI(propertyOne), null, false)) .thenReturn(statements.get(asOne)); when(connectorMock.findStatements(subjectIri, vf.createIRI(propertyTwo), null, false)) .thenReturn(statements.get(asTwo)); final Collection<Axiom<?>> res = adapter.find(desc); verify(connectorMock).findStatements(subjectIri, null, null, false); verify(connectorMock, never()).findStatements(eq(subjectIri), eq(vf.createIRI(propertyOne)), any(org.eclipse.rdf4j.model.Value.class), anyBoolean()); verifyReturnedAxioms(stmts, res); }
@Test void testFindEntityWithPropertiesAndInferredDataProperty() throws Exception { final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); desc.addAssertion(Assertion.createUnspecifiedPropertyAssertion(false)); final String propertyOne = "http: final String propertyTwo = "http: desc.addAssertion(Assertion.createDataPropertyAssertion(URI.create(propertyTwo), true)); final Map<Assertion, List<Statement>> statements = new HashMap<>(); final Collection<Statement> stmts = new ArrayList<>(); final Assertion asOne = Assertion.createPropertyAssertion(URI.create(propertyOne), false); statements.put(asOne, createStatementsForProperty(propertyOne, true)); final Assertion asTwo = Assertion.createDataPropertyAssertion(URI.create(propertyTwo), false); statements.put(asTwo, createStatementsForProperty(propertyTwo, false)); for (Assertion a : statements.keySet()) { stmts.addAll(statements.get(a)); } final Collection<Statement> inferred = new ArrayList<>(); inferred.add(vf.createStatement(subjectIri, vf.createIRI(propertyTwo), vf.createLiteral(true))); statements.get(asTwo).addAll(inferred); when( connectorMock.findStatements(subjectIri, null, null, false)).thenReturn(stmts); when(connectorMock.findStatements(subjectIri, vf.createIRI(propertyOne), null, false, null)) .thenReturn(statements.get(asOne)); when(connectorMock.findStatements(subjectIri, vf.createIRI(propertyTwo), null, true, null)) .thenReturn(statements.get(asTwo)); final Collection<Axiom<?>> res = adapter.find(desc); verify(connectorMock).findStatements(subjectIri, vf.createIRI(propertyTwo), null, true, null); verify(connectorMock).findStatements(subjectIri, null, null, false); verify(connectorMock, never()).findStatements(eq(subjectIri), eq(vf.createIRI(propertyOne)), any(org.eclipse.rdf4j.model.Value.class), anyBoolean(), eq(null)); final Collection<Statement> allStatements = new ArrayList<>(stmts); allStatements.addAll(inferred); verifyReturnedAxioms(allStatements, res); }
@Test void testFindEntityReturnDataPropertyValueForObjectProperty() throws Exception { final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); final String propertyOne = "http: final List<Statement> statements = new ArrayList<>(); final Assertion asOne = Assertion.createObjectPropertyAssertion(URI.create(propertyOne), false); desc.addAssertion(asOne); final String expected = "http: statements.add(vf.createStatement(subjectIri, vf.createIRI(propertyOne), vf.createIRI(expected))); statements.add(vf.createStatement(subjectIri, vf.createIRI(propertyOne), vf.createLiteral("someNonUriValue"))); when( connectorMock.findStatements(subjectIri, vf.createIRI(propertyOne), null, false, null)) .thenReturn(statements); final Collection<Axiom<?>> res = adapter.find(desc); assertEquals(1, res.size()); assertEquals(expected, res.iterator().next().getValue().toString()); }
@Test void testFindEntityReturnObjectPropertyValueForDataProperty() throws Exception { final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); final String propertyOne = "http: final List<Statement> statements = new ArrayList<>(); final Assertion asOne = Assertion.createDataPropertyAssertion(URI.create(propertyOne), false); desc.addAssertion(asOne); statements.add(vf.createStatement(subjectIri, vf.createIRI(propertyOne), vf.createIRI("http: when( connectorMock.findStatements(subjectIri, vf.createIRI(propertyOne), null, false, null)).thenReturn(statements); final Collection<Axiom<?>> res = adapter.find(desc); assertTrue(res.isEmpty()); }
@Test void findWithObjectPropertyAndPropertiesReturnsAxiomForObjectProperty() throws Exception { final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); final String propertyOne = "http: final List<Statement> statements = new ArrayList<>(); statements.add(vf.createStatement(subjectIri, vf.createIRI(propertyOne), vf.createIRI("http: final Assertion asOne = Assertion.createObjectPropertyAssertion(URI.create(propertyOne), false); final Set<Assertion> assertions = new LinkedHashSet<>(); assertions.add(Assertion.createUnspecifiedPropertyAssertion(false)); assertions.add(asOne); setAssertions(desc, assertions); when(connectorMock .findStatements(subjectIri, vf.createIRI(propertyOne), null, false)) .thenReturn(statements); when(connectorMock.findStatements(subjectIri, null, null, false)) .thenReturn(statements); final Collection<Axiom<?>> axioms = adapter.find(desc); assertEquals(1, axioms.size()); final Assertion a = axioms.iterator().next().getAssertion(); assertEquals(asOne, a); }
@Test void testFindEntityWithBlankNodeInTypes() throws Exception { final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); final List<Statement> statements = new ArrayList<>(); final Assertion clsAssertion = Assertion.createClassAssertion(false); desc.addAssertion(clsAssertion); statements.add(vf.createStatement(subjectIri, RDF.TYPE, vf.createBNode())); final String type = "http: statements.add(vf.createStatement(subjectIri, RDF.TYPE, vf.createIRI(type))); when(connectorMock.findStatements(subjectIri, RDF.TYPE, null, false, null)).thenReturn(statements); final Collection<Axiom<?>> res = adapter.find(desc); assertEquals(1, res.size()); final Axiom<?> ax = res.iterator().next(); assertEquals(type, ax.getValue().stringValue()); }