use of org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE in project trellis by trellis-ldp.
the class TriplestoreResourceServiceTest method testPutDeleteLdpC.
@Test
void testPutDeleteLdpC() {
final TriplestoreResourceService svc = new TriplestoreResourceService();
svc.idService = idService;
svc.rdfConnection = connect(wrap(toJena(rdf.createDataset())));
svc.initialize();
final Dataset dataset = rdf.createDataset();
dataset.add(Trellis.PreferUserManaged, resource, DC.title, rdf.createLiteral("resource title"));
dataset.add(Trellis.PreferUserManaged, resource, DC.description, rdf.createLiteral("resource description"));
dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
final Instant later = meanwhile();
assertDoesNotThrow(() -> allOf(svc.create(builder(resource).interactionModel(LDP.Container).container(root).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
allOf(svc.get(resource).thenAccept(checkResource(later, LDP.Container, 2L, 1L, 0L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture()).join();
// Now add a child resource
dataset.clear();
dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
dataset.add(Trellis.PreferUserManaged, child, DC.title, rdf.createLiteral("child"));
dataset.add(Trellis.PreferUserManaged, child, DC.description, rdf.createLiteral("nested resource"));
final Instant evenLater = meanwhile();
assertDoesNotThrow(() -> allOf(svc.create(builder(child).interactionModel(LDP.RDFSource).container(resource).build(), dataset).toCompletableFuture(), svc.touch(resource).toCompletableFuture()).join(), "Unsuccessful create operation!");
allOf(svc.get(child).thenAccept(checkChild(evenLater, 2L, 1L)).toCompletableFuture(), svc.get(resource).thenAccept(checkResource(evenLater, LDP.Container, 2L, 1L, 1L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture(), svc.get(root).thenAccept(checkPredates(evenLater)).toCompletableFuture()).join();
// Now delete the child resource
final BlankNode bnode = rdf.createBlankNode();
dataset.clear();
dataset.add(Trellis.PreferAudit, bnode, type, AS.Delete);
dataset.add(Trellis.PreferAudit, bnode, type, PROV.Activity);
dataset.add(Trellis.PreferServerManaged, child, type, LDP.Resource);
final Instant preDelete = meanwhile();
assertDoesNotThrow(() -> allOf(svc.delete(builder(child).interactionModel(LDP.RDFSource).container(resource).build()).toCompletableFuture(), svc.touch(resource).toCompletableFuture()).join(), "Unsuccessful delete operation!");
allOf(svc.get(child).thenAccept(res -> assertEquals(DELETED_RESOURCE, res, "Incorrect resource object!")).toCompletableFuture(), svc.get(resource).thenAccept(checkResource(preDelete, LDP.Container, 2L, 1L, 0L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture(), svc.get(root).thenAccept(checkPredates(preDelete)).toCompletableFuture()).join();
}
Aggregations