CatalogProvUtilsImpl implements CatalogProvUtils { @Override public DeleteActivity startDeleteActivity(User user, Resource recordIri) { Entity recordEntity = entityFactory.getExisting(recordIri, asModel(provenanceService.getConnection() .getStatements(recordIri, null, null), modelFactory)) .orElseGet(() -> { LOG.warn("No Entity found for record " + recordIri + "."); Entity entity = entityFactory.createNew(recordIri); entity.addProperty(vf.createLiteral(config.getRepositoryId()), vf.createIRI(atLocation)); return entity; }); ActivityConfig config = new ActivityConfig.Builder(Collections.singleton(DeleteActivity.class), user) .invalidatedEntity(recordEntity) .build(); Activity activity = initializeActivity(config); provenanceService.addActivity(activity); return deleteActivityFactory.getExisting(activity.getResource(), activity.getModel()).orElseThrow(() -> new IllegalStateException("DeleteActivity not made correctly")); }  @Override CreateActivity startCreateActivity(User user); @Override void endCreateActivity(CreateActivity createActivity, Resource recordIRI); @Override DeleteActivity startDeleteActivity(User user, Resource recordIri); @Override void endDeleteActivity(DeleteActivity deleteActivity, Record record); @Override void removeActivity(Activity activity);  }
@Test public void startDeleteActivityTest() throws Exception { when(provenanceService.createActivity(any(ActivityConfig.class))).thenReturn(deleteActivity); entity.addProperty(VALUE_FACTORY.createLiteral("system"), VALUE_FACTORY.createIRI(predAtLocation)); deleteActivity.addInvalidated(entity); deleteActivity.getModel().addAll(entity.getModel()); DeleteActivity result = utils.startDeleteActivity(user, VALUE_FACTORY.createIRI(recordIri)); verify(provenanceService).createActivity(any(ActivityConfig.class)); verify(provenanceService).addActivity(any(DeleteActivity.class)); verify(mobi).getServerIdentifier(); assertTrue(result.getModel().contains(deleteActivity.getResource(), VALUE_FACTORY.createIRI(Activity.startedAtTime_IRI), null)); assertTrue(result.getModel().contains(deleteActivity.getResource(), VALUE_FACTORY.createIRI(predAtLocation), VALUE_FACTORY.createLiteral(mobi.getServerIdentifier().toString()))); assertEquals(1, deleteActivity.getInvalidated().size()); Entity resultEntity = deleteActivity.getInvalidated().iterator().next(); assertEquals(entity.getResource(), resultEntity.getResource()); assertTrue(resultEntity.getModel().contains(resultEntity.getResource(), VALUE_FACTORY.createIRI(Entity.generatedAtTime_IRI), null)); assertTrue(resultEntity.getModel().contains(resultEntity.getResource(), VALUE_FACTORY.createIRI(predAtLocation), VALUE_FACTORY.createLiteral("system"))); }
@Test(expected = IllegalStateException.class) public void startDeleteActivityWithNoDeleteActivityTest() { Activity activity1 = activityFactory.createNew(VALUE_FACTORY.createIRI("http: when(provenanceService.createActivity(any(ActivityConfig.class))).thenReturn(activity1); utils.startDeleteActivity(user, VALUE_FACTORY.createIRI(recordIri)); }
@Test public void startDeleteActivityWithNoEntityTest() { when(provenanceService.createActivity(any(ActivityConfig.class))).thenReturn(deleteActivity); Entity newEntity = entityFactory.createNew(VALUE_FACTORY.createIRI(recordIri)); newEntity.addProperty(VALUE_FACTORY.createLiteral("system"), VALUE_FACTORY.createIRI(predAtLocation)); deleteActivity.addInvalidated(newEntity); deleteActivity.getModel().addAll(newEntity.getModel()); when(RepositoryResults.asModel(resultEntity, MODEL_FACTORY)).thenReturn(MODEL_FACTORY.createModel()); DeleteActivity result = utils.startDeleteActivity(user, VALUE_FACTORY.createIRI(recordIri)); verify(provenanceService).createActivity(any(ActivityConfig.class)); verify(provenanceService).addActivity(any(DeleteActivity.class)); verify(mobi).getServerIdentifier(); assertTrue(result.getModel().contains(deleteActivity.getResource(), VALUE_FACTORY.createIRI(Activity.startedAtTime_IRI), null)); assertTrue(result.getModel().contains(deleteActivity.getResource(), VALUE_FACTORY.createIRI(predAtLocation), VALUE_FACTORY.createLiteral(mobi.getServerIdentifier().toString()))); assertEquals(1, deleteActivity.getInvalidated().size()); Entity resultEntity = deleteActivity.getInvalidated().iterator().next(); assertEquals(newEntity.getResource(), resultEntity.getResource()); assertFalse(resultEntity.getModel().contains(resultEntity.getResource(), VALUE_FACTORY.createIRI(Entity.generatedAtTime_IRI), null)); assertTrue(resultEntity.getModel().contains(resultEntity.getResource(), VALUE_FACTORY.createIRI(predAtLocation), VALUE_FACTORY.createLiteral("system"))); }