SesameAdapter implements Closeable, Wrapper { void persist(AxiomValueDescriptor axiomDescriptor) throws SesameDriverException { startTransactionIfNotActive(); 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 testPersistDataPropertiesNoContext() throws Exception { final AxiomValueDescriptor ad = new AxiomValueDescriptor(SUBJECT); ad.addAssertionValue( Assertion.createClassAssertion(false), new Value<>(URI .create("http: ad.addAssertionValue(Assertion.createDataPropertyAssertion(URI .create("http: false), new Value<>("StringValue")); adapter.persist(ad); final ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class); verify(connectorMock).addStatements(captor.capture()); final Collection<?> res = captor.getValue(); assertEquals(2, res.size()); assertTrue(statementsCorrespondToAxiomDescriptor(ad, (Collection<Statement>) res)); }
@Test void testPersistEntityWithTypesDataPropertyInContext() throws Exception { final AxiomValueDescriptor ad = new AxiomValueDescriptor(SUBJECT); ad.addAssertionValue( Assertion.createClassAssertion(false), new Value<>(URI .create("http: ad.addAssertionValue( Assertion.createClassAssertion(false), new Value<>(URI .create("http: ad.addAssertionValue( Assertion.createClassAssertion(false), new Value<>(URI .create("http: final Assertion dataAssertion = Assertion.createDataPropertyAssertion(URI .create("http: false); ad.addAssertionValue(dataAssertion, new Value<>("StringValue")); ad.setAssertionContext(dataAssertion, URI.create("http: adapter.persist(ad); final ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class); verify(connectorMock).addStatements(captor.capture()); final Collection<?> res = captor.getValue(); assertEquals(4, res.size()); assertTrue(statementsCorrespondToAxiomDescriptor(ad, (Collection<Statement>) res)); }
@Test void testPersistEntityWithObjectPropertyMultipleValues() throws Exception { final AxiomValueDescriptor ad = new AxiomValueDescriptor(SUBJECT); ad.addAssertionValue( Assertion.createClassAssertion(false), new Value<>(URI .create("http: final Assertion objectAssertion = Assertion.createObjectPropertyAssertion( URI.create("http: false); ad.addAssertionValue(objectAssertion, new Value<>(URI.create("http: ad.addAssertionValue(objectAssertion, new Value<>(URI.create("http: ad.addAssertionValue(objectAssertion, new Value<>(URI.create("http: ad.setSubjectContext(URI.create("http: adapter.persist(ad); final ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class); verify(connectorMock).addStatements(captor.capture()); final Collection<?> res = captor.getValue(); assertEquals(4, res.size()); assertTrue(statementsCorrespondToAxiomDescriptor(ad, (Collection<Statement>) res)); }
@Test void testPersistEntityWithProperties() throws Exception { final AxiomValueDescriptor ad = new AxiomValueDescriptor(SUBJECT); ad.addAssertionValue( Assertion.createClassAssertion(false), new Value<>(URI .create("http: final Assertion objectAssertion = Assertion.createPropertyAssertion( URI.create("http: false); ad.addAssertionValue(objectAssertion, new Value<>(URI.create("http: final Assertion dataAssertion = Assertion.createPropertyAssertion(URI .create("http: false); ad.addAssertionValue(dataAssertion, new Value<>("stringValue")); adapter.persist(ad); final ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class); verify(connectorMock).addStatements(captor.capture()); final Collection<?> res = captor.getValue(); assertEquals(3, res.size()); assertTrue(statementsCorrespondToAxiomDescriptor(ad, (Collection<Statement>) res)); }
@Test void testPersistEntityWithAnnotationPropertyAndDifferentSubjectAndPropertyContexts() throws Exception { final URI subjectCtx = URI.create("http: final URI propertyCtx = URI.create("http: final AxiomValueDescriptor ad = new AxiomValueDescriptor(SUBJECT); ad.setSubjectContext(subjectCtx); ad.addAssertionValue( Assertion.createClassAssertion(false), new Value<>(URI .create("http: final Assertion dataAssertion = Assertion.createAnnotationPropertyAssertion( URI.create("http: false); ad.addAssertionValue(dataAssertion, new Value<>("StringValue")); ad.setAssertionContext(dataAssertion, propertyCtx); adapter.persist(ad); final ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class); verify(connectorMock).addStatements(captor.capture()); final Collection<?> res = captor.getValue(); assertEquals(2, res.size()); assertTrue(statementsCorrespondToAxiomDescriptor(ad, (Collection<Statement>) res)); for (Object s : res) { final Statement stmt = (Statement) s; if (stmt.getPredicate().stringValue().equals(dataAssertion.getIdentifier().toString())) { assertEquals(propertyCtx.toString(), stmt.getContext().stringValue()); } else { assertEquals(subjectCtx.toString(), stmt.getContext().stringValue()); } } }