SimpleProvenanceService implements ProvenanceService { @Override public Optional<Activity> getActivity(Resource activityIRI) { try (RepositoryConnection conn = repo.getConnection()) { Model activityModel = RepositoryResults.asModel(conn.getStatements(activityIRI, null, null), mf); return activityFactory.getExisting(activityIRI, activityModel).flatMap(activity -> { addEntitiesToModel(activity.getGenerated_resource(), activityModel, conn); addEntitiesToModel(activity.getInvalidated_resource(), activityModel, conn); addEntitiesToModel(activity.getUsed_resource(), activityModel, conn); return Optional.of(activity); }); } }  @Override RepositoryConnection getConnection(); @Override Activity createActivity(ActivityConfig config); @Override void addActivity(Activity activity); @Override Optional<Activity> getActivity(Resource activityIRI); @Override void updateActivity(Activity newActivity); @Override void deleteActivity(Resource activityIRI);  }
@Test public void getActivityTest() throws Exception { Activity activity = activityFactory.createNew(activityIRI); Entity generated = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity invalidated = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity used = entityFactory.createNew(VALUE_FACTORY.createIRI("http: activity.setGenerated(Collections.singleton(generated)); activity.setInvalidated(Collections.singleton(invalidated)); activity.setUsed(Collections.singleton(used)); try (RepositoryConnection conn = repo.getConnection()) { conn.add(activity.getModel()); } Optional<Activity> result = service.getActivity(activity.getResource()); assertTrue(result.isPresent()); result.get().getModel().forEach(statement -> assertTrue(activity.getModel().contains(statement))); }
@Test public void getActivityThatDoesNotExistTest() throws Exception { Optional<Activity> result = service.getActivity(activityIRI); assertFalse(result.isPresent()); }