Search in sources :

Example 1 with DELETED_RESOURCE

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();
}
Also used : IdentifierService(org.trellisldp.api.IdentifierService) XSD(org.trellisldp.vocabulary.XSD) Optional.of(java.util.Optional.of) RDF.type(org.trellisldp.vocabulary.RDF.type) Resource(org.trellisldp.api.Resource) SKOS(org.trellisldp.vocabulary.SKOS) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JenaCommonsRDF.toJena(org.apache.jena.commonsrdf.JenaCommonsRDF.toJena) Map(java.util.Map) RDFLinkDataset(org.apache.jena.rdflink.RDFLinkDataset) DELETED_RESOURCE(org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE) Awaitility.await(org.awaitility.Awaitility.await) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DC(org.trellisldp.vocabulary.DC) Literal(org.apache.commons.rdf.api.Literal) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Instant(java.time.Instant) Awaitility.setDefaultPollInterval(org.awaitility.Awaitility.setDefaultPollInterval) Test(org.junit.jupiter.api.Test) Stream(java.util.stream.Stream) TRELLIS_DATA_PREFIX(org.trellisldp.api.TrellisUtils.TRELLIS_DATA_PREFIX) RDFConnection(org.apache.jena.rdfconnection.RDFConnection) RDFConnectionAdapter(org.apache.jena.rdflink.RDFConnectionAdapter) RDFLinkHTTP(org.apache.jena.rdflink.RDFLinkHTTP) RDFS(org.trellisldp.vocabulary.RDFS) Instant.now(java.time.Instant.now) Mock(org.mockito.Mock) Metadata.builder(org.trellisldp.api.Metadata.builder) RDF(org.apache.commons.rdf.api.RDF) AS(org.trellisldp.vocabulary.AS) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) LDP(org.trellisldp.vocabulary.LDP) DatasetFactory.wrap(org.apache.jena.query.DatasetFactory.wrap) Dataset(org.apache.commons.rdf.api.Dataset) Trellis(org.trellisldp.vocabulary.Trellis) BinaryMetadata(org.trellisldp.api.BinaryMetadata) DefaultIdentifierService(org.trellisldp.api.DefaultIdentifierService) RDFFactory(org.trellisldp.api.RDFFactory) RDFConnectionFactory.connect(org.apache.jena.rdfconnection.RDFConnectionFactory.connect) BlankNode(org.apache.commons.rdf.api.BlankNode) Predicate.isEqual(java.util.function.Predicate.isEqual) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) IRI(org.apache.commons.rdf.api.IRI) PROV(org.trellisldp.vocabulary.PROV) Executable(org.junit.jupiter.api.function.Executable) Assertions(org.junit.jupiter.api.Assertions) UpdateRequest(org.apache.jena.update.UpdateRequest) MISSING_RESOURCE(org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE) RDFLinkDataset(org.apache.jena.rdflink.RDFLinkDataset) Dataset(org.apache.commons.rdf.api.Dataset) Instant(java.time.Instant) BlankNode(org.apache.commons.rdf.api.BlankNode) Test(org.junit.jupiter.api.Test)

Aggregations

File (java.io.File)1 Instant (java.time.Instant)1 Instant.now (java.time.Instant.now)1 Map (java.util.Map)1 Optional.of (java.util.Optional.of)1 CompletableFuture.allOf (java.util.concurrent.CompletableFuture.allOf)1 ExecutionException (java.util.concurrent.ExecutionException)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 Consumer (java.util.function.Consumer)1 Predicate.isEqual (java.util.function.Predicate.isEqual)1 Stream (java.util.stream.Stream)1 BlankNode (org.apache.commons.rdf.api.BlankNode)1 Dataset (org.apache.commons.rdf.api.Dataset)1 IRI (org.apache.commons.rdf.api.IRI)1 Literal (org.apache.commons.rdf.api.Literal)1 RDF (org.apache.commons.rdf.api.RDF)1 JenaCommonsRDF.toJena (org.apache.jena.commonsrdf.JenaCommonsRDF.toJena)1 DatasetFactory.wrap (org.apache.jena.query.DatasetFactory.wrap)1 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)1 RDFConnectionFactory.connect (org.apache.jena.rdfconnection.RDFConnectionFactory.connect)1