SesameAdapter implements Closeable, Wrapper { void update(AxiomValueDescriptor axiomDescriptor) throws SesameDriverException { startTransactionIfNotActive(); new EpistemicAxiomRemover(connector, valueFactory).remove(axiomDescriptor); new AxiomSaver(connector, valueFactory).persistAxioms(axiomDescriptor); } SesameAdapter(Connector connector, DriverConfiguration configuration); @Override void close(); @Override boolean isOpen(); @Override T unwrap(Class<T> cls);  }
@Test void updatesDataPropertyToNewValue() throws Exception { final AxiomValueDescriptor desc = new AxiomValueDescriptor(SUBJECT); final URI property = URI.create("http: final org.eclipse.rdf4j.model.IRI sesameProperty = vf.createIRI(property.toString()); final boolean inferred = false; final Assertion assertion = Assertion.createDataPropertyAssertion(property, "en", inferred); final String oldValue = "oldValue"; final String newValue = "newValue"; desc.addAssertion(assertion); desc.addAssertionValue(assertion, new Value<>(newValue)); final Collection<Statement> statements = Collections.singleton(vf.createStatement( subjectIri, sesameProperty, vf.createLiteral(oldValue, "en"))); when(connectorMock.findStatements(eq(subjectIri), eq(sesameProperty), any(), eq(inferred), eq(null))) .thenReturn(statements); adapter.update(desc); verify(connectorMock).findStatements(subjectIri, sesameProperty, null, inferred, null); verify(connectorMock).removeStatements(statements); final Collection<Statement> inserted = Collections.singletonList(vf.createStatement( subjectIri, sesameProperty, vf.createLiteral(newValue, "en"))); verify(connectorMock).addStatements(inserted); }
@Test void updatesObjectPropertyToNewValue() throws Exception { final AxiomValueDescriptor desc = new AxiomValueDescriptor(SUBJECT); final URI property = URI.create("http: final org.eclipse.rdf4j.model.IRI sesameProperty = vf.createIRI(property.toString()); final boolean inferred = false; final Assertion assertion = Assertion.createObjectPropertyAssertion(property, inferred); final org.eclipse.rdf4j.model.IRI oldValue = vf.createIRI("http: final org.eclipse.rdf4j.model.IRI newValue = vf.createIRI("http: desc.addAssertion(assertion); desc.addAssertionValue(assertion, new Value<>(URI.create(newValue.stringValue()))); final Collection<Statement> statements = Collections.singleton(vf.createStatement( subjectIri, sesameProperty, oldValue)); when(connectorMock.findStatements(eq(subjectIri), eq(sesameProperty), any(), eq(inferred), eq(null))) .thenReturn(statements); adapter.update(desc); verify(connectorMock).findStatements(subjectIri, sesameProperty, null, inferred, null); verify(connectorMock).removeStatements(statements); final Collection<Statement> inserted = Collections.singletonList(vf.createStatement( subjectIri, sesameProperty, newValue)); verify(connectorMock).addStatements(inserted); }
@Test void updatesObjectPropertyToEmptyValue() throws Exception { final AxiomValueDescriptor desc = new AxiomValueDescriptor(SUBJECT); final URI property = URI.create("http: final org.eclipse.rdf4j.model.IRI sesameProperty = vf.createIRI(property.toString()); final boolean inferred = false; final Assertion assertion = Assertion.createObjectPropertyAssertion(property, inferred); final org.eclipse.rdf4j.model.IRI oldValue = vf.createIRI("http: desc.addAssertion(assertion); desc.addAssertionValue(assertion, Value.nullValue()); final Collection<Statement> statements = Collections.singleton(vf.createStatement( subjectIri, sesameProperty, oldValue)); when(connectorMock.findStatements(eq(subjectIri), eq(sesameProperty), any(), eq(inferred), eq(null))) .thenReturn(statements); adapter.update(desc); verify(connectorMock).findStatements(subjectIri, sesameProperty, null, inferred, null); verify(connectorMock).removeStatements(statements); verify(connectorMock, never()).addStatements(anyCollectionOf(Statement.class)); }
@Test void updatesTypesInContext() throws Exception { final AxiomValueDescriptor desc = new AxiomValueDescriptor(SUBJECT); final boolean inferred = false; final Assertion assertion = Assertion.createClassAssertion(inferred); final String[] newTypes = {"http: "http: "http: "http: desc.addAssertion(assertion); final URI context = Generator.generateUri(); final IRI iriContext = vf.createIRI(context.toString()); desc.setAssertionContext(assertion, context); for (String t : newTypes) { desc.addAssertionValue(assertion, new Value<>(URI.create(t))); } final Collection<Statement> statements = initOldTypes(); when(connectorMock.findStatements(eq(subjectIri), eq(RDF.TYPE), any(), eq(inferred), eq(iriContext))) .thenReturn(statements); adapter.update(desc); verify(connectorMock).findStatements(subjectIri, RDF.TYPE, null, inferred, iriContext); verify(connectorMock).removeStatements(statements); final Collection<Statement> inserted = initNewTypes(newTypes, iriContext); verify(connectorMock).addStatements(inserted); }