PropertiesHandler implements Properties { @Override public void addProperties(NamedResource individual, URI context, Map<Assertion, Set<Value<?>>> properties) { new AxiomSaver(connector).saveAxioms(individual, properties, context); } PropertiesHandler(StorageConnector connector); @Override Collection<Axiom<?>> getProperties(NamedResource individual, URI context, boolean includeInferred); @Override void addProperties(NamedResource individual, URI context, Map<Assertion, Set<Value<?>>> properties); @Override void removeProperties(NamedResource individual, URI context, Map<Assertion, Set<Value<?>>> properties);  }
@Test public void addPropertiesAddsStatementsIntoRepository() { final Assertion a = Assertion.createPropertyAssertion(Generator.generateUri(), false); final Integer vOne = 117; final Integer vTwo = 118; final Set<Integer> values = new HashSet<>(Arrays.asList(vOne, vTwo)); handler.addProperties(SUBJECT, null, Collections.singletonMap(a, new HashSet<>(Arrays.asList(new Value<>(vOne), new Value<>(vTwo))))); final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(connectorMock).add(captor.capture(), eq(null)); assertEquals(2, captor.getValue().size()); captor.getValue().forEach(item -> { final Statement s = (Statement) item; assertEquals(SUBJECT_RESOURCE, s.getSubject()); assertEquals(createProperty(a.getIdentifier().toString()), s.getPredicate()); assertTrue(s.getObject().isLiteral()); assertTrue(values.contains(s.getObject().asLiteral().getValue())); }); }
@Test public void addPropertiesAddsStatementsIntoCorrectContext() { final Assertion a = Assertion.createPropertyAssertion(Generator.generateUri(), false); final URI vOne = Generator.generateUri(); final URI vTwo = Generator.generateUri(); final Set<URI> values = new HashSet<>(Arrays.asList(vOne, vTwo)); final URI context = Generator.generateUri(); handler.addProperties(SUBJECT, context, Collections.singletonMap(a, new HashSet<>(Arrays.asList(new Value<>(NamedResource.create(vOne)), new Value<>(NamedResource.create(vTwo)))))); final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(connectorMock).add(captor.capture(), eq(context.toString())); assertEquals(2, captor.getValue().size()); captor.getValue().forEach(item -> { final Statement s = (Statement) item; assertEquals(SUBJECT_RESOURCE, s.getSubject()); assertEquals(createProperty(a.getIdentifier().toString()), s.getPredicate()); assertTrue(s.getObject().isResource()); assertTrue(values.contains(URI.create(s.getObject().asResource().getURI()))); }); }