Search in sources :

Example 1 with LDP

use of org.trellisldp.vocabulary.LDP in project trellis by trellis-ldp.

the class TriplestoreResourceServiceTest method testPutLdpDc.

@Test
void testPutLdpDc() {
    final TriplestoreResourceService svc = new TriplestoreResourceService();
    svc.rdfConnection = connect(wrap(toJena(rdf.createDataset())));
    svc.idService = idService;
    svc.initialize();
    final Dataset dataset = rdf.createDataset();
    dataset.add(Trellis.PreferUserManaged, resource, DC.title, rdf.createLiteral("direct container"));
    dataset.add(Trellis.PreferUserManaged, resource, DC.description, rdf.createLiteral("LDP-DC test"));
    dataset.add(Trellis.PreferUserManaged, resource, LDP.membershipResource, members);
    dataset.add(Trellis.PreferUserManaged, resource, LDP.hasMemberRelation, DC.relation);
    final Instant later = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(resource).interactionModel(LDP.DirectContainer).container(root).memberRelation(DC.relation).membershipResource(members).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(resource).thenAccept(checkResource(later, LDP.DirectContainer, 4L, 0L, 0L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture()).join();
    // Now add a membership resource
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, members, DC.title, rdf.createLiteral("member resource"));
    final Instant evenLater = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(members).interactionModel(LDP.RDFSource).container(root).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(members).thenAccept(checkMember(evenLater, 1L, 0L, 0L)).toCompletableFuture(), svc.get(members).thenAccept(res -> assertFalse(res.getBinaryMetadata().isPresent(), "Unexpected binary metadata!")).toCompletableFuture(), svc.get(resource).thenAccept(checkResource(later, LDP.DirectContainer, 4L, 0L, 0L)).toCompletableFuture(), svc.get(resource).thenAccept(checkPredates(evenLater)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(evenLater, 2L)).toCompletableFuture()).join();
    // Now add the child resources to the ldp-dc
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, child, DC.title, rdf.createLiteral("ldp-dc child resource"));
    final Instant evenLater2 = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(child).interactionModel(LDP.RDFSource).container(resource).build(), dataset).toCompletableFuture(), svc.touch(members).toCompletableFuture(), svc.touch(resource).toCompletableFuture()).join(), "Unsuccessful create operation!");
    final IRI container = rdf.createIRI(resource.getIRIString() + "/");
    allOf(svc.get(child).thenAccept(checkChild(evenLater2, 1L, 0L)).toCompletableFuture(), svc.get(resource).thenAccept(checkResource(evenLater2, LDP.DirectContainer, 4L, 0L, 1L)).toCompletableFuture(), svc.get(resource).thenAccept(res -> assertTrue(res.stream(LDP.PreferContainment).anyMatch(isEqual(rdf.createQuad(LDP.PreferContainment, container, LDP.contains, child))), "Missing contains triple!")).toCompletableFuture(), svc.get(members).thenAccept(checkMember(evenLater2, 1L, 0L, 1L)).toCompletableFuture(), svc.get(members).thenAccept(res -> assertTrue(res.stream(LDP.PreferMembership).anyMatch(isEqual(rdf.createQuad(LDP.PreferMembership, members, DC.relation, child))), "Missing membership triple!")).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(evenLater, 2L)).toCompletableFuture(), svc.get(root).thenAccept(checkPredates(evenLater2)).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) IRI(org.apache.commons.rdf.api.IRI) RDFLinkDataset(org.apache.jena.rdflink.RDFLinkDataset) Dataset(org.apache.commons.rdf.api.Dataset) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 2 with LDP

use of org.trellisldp.vocabulary.LDP in project trellis by trellis-ldp.

the class TriplestoreResourceServiceTest method testPutLdpDcMultipleInverse.

@Test
void testPutLdpDcMultipleInverse() {
    final TriplestoreResourceService svc = new TriplestoreResourceService();
    svc.rdfConnection = connect(wrap(toJena(rdf.createDataset())));
    svc.idService = idService;
    svc.initialize();
    final IRI container = rdf.createIRI(resource.getIRIString() + "/");
    final IRI container2 = rdf.createIRI(resource2.getIRIString() + "/");
    final Dataset dataset = rdf.createDataset();
    dataset.add(Trellis.PreferUserManaged, resource, DC.title, rdf.createLiteral("direct container inverse"));
    dataset.add(Trellis.PreferUserManaged, resource, RDFS.label, rdf.createLiteral("LDP-DC test"));
    dataset.add(Trellis.PreferUserManaged, resource, DC.description, rdf.createLiteral("LDP-DC inverse test"));
    dataset.add(Trellis.PreferUserManaged, resource, LDP.membershipResource, members);
    dataset.add(Trellis.PreferUserManaged, resource, LDP.isMemberOfRelation, DC.relation);
    dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
    final Instant later = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(resource).interactionModel(LDP.DirectContainer).container(root).membershipResource(members).memberOfRelation(DC.relation).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(resource).thenAccept(checkResource(later, LDP.DirectContainer, 5L, 1L, 0L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture()).join();
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, resource2, DC.title, rdf.createLiteral("Second LDP-DC"));
    dataset.add(Trellis.PreferUserManaged, resource2, LDP.membershipResource, members);
    dataset.add(Trellis.PreferUserManaged, resource2, LDP.isMemberOfRelation, DC.subject);
    dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
    final Instant evenLater = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(resource2).interactionModel(LDP.DirectContainer).container(root).membershipResource(members).memberOfRelation(DC.subject).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(resource2).thenAccept(res -> assertAll("Check resource", () -> checkResource(res, resource2, LDP.DirectContainer, evenLater), () -> checkResourceStream(res, 3L, 0L, 1L, 0L, 0L))).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(evenLater, 2L)).toCompletableFuture()).join();
    // Now add a membership resource
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, members, DC.title, rdf.createLiteral("Membership resource"));
    dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
    final Instant evenLater2 = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(members).interactionModel(LDP.RDFSource).container(root).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful membership resource create operation!");
    allOf(svc.get(members).thenAccept(checkMember(evenLater2, 1L, 1L, 0L)).toCompletableFuture(), svc.get(resource).thenAccept(res -> assertAll("Check resource", () -> checkResource(later, LDP.DirectContainer, 5L, 1L, 0L).accept(res), () -> checkPredates(evenLater2).accept(res))).toCompletableFuture(), svc.get(resource2).thenAccept(res -> assertAll("Check second resource", () -> checkPredates(evenLater2).accept(res), () -> checkResourceStream(res, 3L, 0L, 1L, 0L, 0L))).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(evenLater2, 3L)).toCompletableFuture()).join();
    // Now add the child resources to the ldp-dc
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, child, DC.title, rdf.createLiteral("Child resource"));
    dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
    final Instant evenLater3 = 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(res -> assertAll("Check resource", () -> checkResource(res, child, LDP.RDFSource, evenLater3), () -> checkResourceStream(res, 1L, 0L, 1L, 1L, 0L))).toCompletableFuture(), svc.get(resource).thenAccept(res -> assertAll("Check resource", () -> checkResource(evenLater3, LDP.DirectContainer, 5L, 1L, 1L).accept(res), () -> assertTrue(res.stream(LDP.PreferContainment).anyMatch(isEqual(rdf.createQuad(LDP.PreferContainment, container, LDP.contains, child))), "Missing contains triple!"))).toCompletableFuture(), svc.get(members).thenAccept(res -> assertAll("Check member resource", () -> checkMember(evenLater2, 1L, 1L, 0L).accept(res), () -> checkPredates(evenLater3).accept(res))).toCompletableFuture(), svc.get(root).thenAccept(res -> assertAll("Check root resource", () -> checkRoot(evenLater2, 3L).accept(res), () -> checkPredates(evenLater3).accept(res))).toCompletableFuture()).join();
    // Now add a child resources to the other ldp-dc
    dataset.clear();
    dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
    dataset.add(Trellis.PreferUserManaged, child2, DC.title, rdf.createLiteral("Second child resource"));
    final Instant evenLater4 = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(child2).interactionModel(LDP.RDFSource).container(resource2).build(), dataset).toCompletableFuture(), svc.touch(resource2).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(child2).thenAccept(res -> assertAll("Check child resource", () -> checkResource(res, child2, LDP.RDFSource, evenLater4), () -> checkResourceStream(res, 1L, 0L, 1L, 1L, 0L))).toCompletableFuture(), svc.get(resource2).thenAccept(res -> assertAll("Check resource", () -> checkResource(res, resource2, LDP.DirectContainer, evenLater4), () -> checkResourceStream(res, 3L, 0L, 1L, 0L, 1L), () -> assertTrue(res.stream(LDP.PreferContainment).anyMatch(isEqual(rdf.createQuad(LDP.PreferContainment, container2, LDP.contains, child2))), "Missing contains triple!"))).toCompletableFuture(), svc.get(members).thenAccept(res -> assertAll("Check member resource", () -> checkMember(evenLater2, 1L, 1L, 0L).accept(res), () -> checkPredates(evenLater4).accept(res))).toCompletableFuture(), svc.get(root).thenAccept(res -> assertAll("Check root resource", () -> checkRoot(evenLater2, 3L).accept(res), () -> checkPredates(evenLater4).accept(res))).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) IRI(org.apache.commons.rdf.api.IRI) RDFLinkDataset(org.apache.jena.rdflink.RDFLinkDataset) Dataset(org.apache.commons.rdf.api.Dataset) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 3 with LDP

use of org.trellisldp.vocabulary.LDP in project trellis by trellis-ldp.

the class TriplestoreResourceServiceTest method testPutLdpIcDefaultContent.

@Test
void testPutLdpIcDefaultContent() {
    final TriplestoreResourceService svc = new TriplestoreResourceService();
    svc.rdfConnection = connect(wrap(toJena(rdf.createDataset())));
    svc.idService = idService;
    svc.initialize();
    final IRI container = rdf.createIRI(resource.getIRIString() + "/");
    final Dataset dataset = rdf.createDataset();
    dataset.add(Trellis.PreferUserManaged, resource, DC.title, rdf.createLiteral("Indirect Container"));
    dataset.add(Trellis.PreferUserManaged, resource, DC.description, rdf.createLiteral("LDP-IC with default content"));
    dataset.add(Trellis.PreferUserManaged, resource, LDP.membershipResource, members);
    dataset.add(Trellis.PreferUserManaged, resource, LDP.hasMemberRelation, RDFS.label);
    dataset.add(Trellis.PreferUserManaged, resource, LDP.insertedContentRelation, LDP.MemberSubject);
    dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
    final Instant later = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(resource).interactionModel(LDP.IndirectContainer).container(root).membershipResource(members).memberRelation(RDFS.label).insertedContentRelation(LDP.MemberSubject).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(resource).thenAccept(checkResource(later, LDP.IndirectContainer, 5L, 1L, 0L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture()).join();
    // Now add a membership resource
    final BlankNode bnode = rdf.createBlankNode();
    dataset.clear();
    dataset.add(Trellis.PreferAudit, bnode, type, AS.Create);
    dataset.add(Trellis.PreferAudit, bnode, type, PROV.Activity);
    dataset.add(Trellis.PreferUserManaged, members, DC.title, rdf.createLiteral("Member resource"));
    final Instant evenLater = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(members).interactionModel(LDP.RDFSource).container(root).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(resource).thenAccept(checkResource(later, LDP.IndirectContainer, 5L, 1L, 0L)).toCompletableFuture(), svc.get(resource).thenAccept(checkPredates(evenLater)).toCompletableFuture(), svc.get(members).thenAccept(checkMember(evenLater, 1L, 2L, 0L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(evenLater, 2L)).toCompletableFuture()).join();
    // Now add the child resources to the ldp-dc
    final Literal label = rdf.createLiteral("label1");
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, child, SKOS.prefLabel, label);
    dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
    final Instant evenLater2 = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(child).interactionModel(LDP.RDFSource).container(resource).build(), dataset).toCompletableFuture(), svc.touch(members).toCompletableFuture(), svc.touch(resource).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(child).thenAccept(checkChild(evenLater2, 1L, 1L)).toCompletableFuture(), svc.get(resource).thenAccept(checkResource(evenLater2, LDP.IndirectContainer, 5L, 1L, 1L)).toCompletableFuture(), svc.get(resource).thenAccept(res -> assertTrue(res.stream(LDP.PreferContainment).anyMatch(isEqual(rdf.createQuad(LDP.PreferContainment, container, LDP.contains, child))), "Missing contains triple!")).toCompletableFuture(), svc.get(members).thenAccept(checkMember(evenLater2, 1L, 2L, 1L)).toCompletableFuture(), svc.get(members).thenAccept(res -> assertTrue(res.stream(LDP.PreferMembership).anyMatch(isEqual(rdf.createQuad(LDP.PreferMembership, members, RDFS.label, child))), "Missing membership triple!")).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(evenLater, 2L)).toCompletableFuture(), svc.get(root).thenAccept(checkPredates(evenLater2)).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) IRI(org.apache.commons.rdf.api.IRI) RDFLinkDataset(org.apache.jena.rdflink.RDFLinkDataset) Dataset(org.apache.commons.rdf.api.Dataset) Instant(java.time.Instant) Literal(org.apache.commons.rdf.api.Literal) BlankNode(org.apache.commons.rdf.api.BlankNode) Test(org.junit.jupiter.api.Test)

Example 4 with LDP

use of org.trellisldp.vocabulary.LDP in project trellis by trellis-ldp.

the class TriplestoreResourceServiceTest method testPutLdpIc.

@Test
void testPutLdpIc() {
    final TriplestoreResourceService svc = new TriplestoreResourceService();
    svc.rdfConnection = connect(wrap(toJena(rdf.createDataset())));
    svc.idService = idService;
    svc.initialize();
    final Dataset dataset = rdf.createDataset();
    final BlankNode bnode0 = rdf.createBlankNode();
    final IRI container = rdf.createIRI(resource.getIRIString() + "/");
    dataset.add(Trellis.PreferUserManaged, resource, DC.title, rdf.createLiteral("Indirect Container"));
    dataset.add(Trellis.PreferUserManaged, resource, DC.description, rdf.createLiteral("Test LDP-IC"));
    dataset.add(Trellis.PreferUserManaged, resource, DC.subject, rdf.createIRI("http://example.com/subject"));
    dataset.add(Trellis.PreferUserManaged, resource, type, SKOS.Concept);
    dataset.add(Trellis.PreferUserManaged, resource, LDP.membershipResource, members);
    dataset.add(Trellis.PreferUserManaged, resource, LDP.hasMemberRelation, RDFS.label);
    dataset.add(Trellis.PreferUserManaged, resource, LDP.insertedContentRelation, SKOS.prefLabel);
    dataset.add(Trellis.PreferAudit, resource, PROV.wasGeneratedBy, bnode0);
    dataset.add(Trellis.PreferAudit, bnode0, PROV.atTime, rdf.createLiteral(now().toString(), XSD.dateTime));
    dataset.add(Trellis.PreferAudit, bnode0, type, PROV.Activity);
    dataset.add(Trellis.PreferAudit, bnode0, type, AS.Create);
    final Instant later = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(resource).interactionModel(LDP.IndirectContainer).container(root).memberRelation(RDFS.label).membershipResource(members).insertedContentRelation(SKOS.prefLabel).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation (indirect containment)!");
    allOf(svc.get(resource).thenAccept(checkResource(later, LDP.IndirectContainer, 7L, 4L, 0L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture()).join();
    // Now add a membership resource
    final BlankNode bnode1 = rdf.createBlankNode();
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, members, DC.title, rdf.createLiteral("Membership resource"));
    dataset.add(Trellis.PreferAudit, members, PROV.wasGeneratedBy, bnode1);
    dataset.add(Trellis.PreferAudit, bnode1, PROV.atTime, rdf.createLiteral(now().toString(), XSD.dateTime));
    dataset.add(Trellis.PreferAudit, bnode1, type, PROV.Activity);
    dataset.add(Trellis.PreferAudit, bnode1, type, AS.Create);
    final Instant evenLater = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(members).interactionModel(LDP.RDFSource).container(root).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation (indirect containment)!");
    allOf(svc.get(members).thenAccept(checkMember(evenLater, 1L, 4L, 0L)).toCompletableFuture(), svc.get(resource).thenAccept(res -> assertAll("Check resource", () -> checkResource(later, LDP.IndirectContainer, 7L, 4L, 0L).accept(res), () -> checkPredates(evenLater).accept(res))).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(evenLater, 2L)).toCompletableFuture()).join();
    // Now add the child resources to the ldp-dc
    final BlankNode bnode2 = rdf.createBlankNode();
    final Literal label = rdf.createLiteral("label-1");
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, child, SKOS.prefLabel, label);
    dataset.add(Trellis.PreferAudit, child, PROV.wasGeneratedBy, bnode2);
    dataset.add(Trellis.PreferAudit, bnode2, type, AS.Create);
    dataset.add(Trellis.PreferAudit, bnode2, type, PROV.Activity);
    final Instant evenLater2 = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(child).interactionModel(LDP.RDFSource).container(resource).build(), dataset).toCompletableFuture(), svc.touch(members).toCompletableFuture(), svc.touch(resource).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(child).thenAccept(checkChild(evenLater2, 1L, 3L)).toCompletableFuture(), svc.get(resource).thenAccept(res -> assertAll("Check resource", () -> checkResource(evenLater2, LDP.IndirectContainer, 7L, 4L, 1L).accept(res), () -> assertTrue(res.stream(LDP.PreferContainment).anyMatch(isEqual(rdf.createQuad(LDP.PreferContainment, container, LDP.contains, child))), "Missing contains triple!"))).toCompletableFuture(), svc.get(members).thenAccept(res -> assertAll("Check member resource", () -> checkMember(evenLater2, 1L, 4L, 1L).accept(res), () -> assertTrue(res.stream(LDP.PreferMembership).anyMatch(isEqual(rdf.createQuad(LDP.PreferMembership, members, RDFS.label, label))), "Missing member triple!"))).toCompletableFuture(), svc.get(root).thenAccept(res -> assertAll("Check root resource", () -> checkRoot(evenLater, 2L).accept(res), () -> checkPredates(evenLater2).accept(res))).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) IRI(org.apache.commons.rdf.api.IRI) RDFLinkDataset(org.apache.jena.rdflink.RDFLinkDataset) Dataset(org.apache.commons.rdf.api.Dataset) Instant(java.time.Instant) Literal(org.apache.commons.rdf.api.Literal) BlankNode(org.apache.commons.rdf.api.BlankNode) Test(org.junit.jupiter.api.Test)

Example 5 with LDP

use of org.trellisldp.vocabulary.LDP in project trellis by trellis-ldp.

the class TriplestoreResourceServiceTest method testPutLdpDcSelf.

@Test
void testPutLdpDcSelf() {
    final TriplestoreResourceService svc = new TriplestoreResourceService();
    svc.idService = idService;
    svc.rdfConnection = connect(wrap(toJena(rdf.createDataset())));
    svc.initialize();
    final IRI container = rdf.createIRI(resource.getIRIString() + "/");
    final Dataset dataset = rdf.createDataset();
    dataset.add(Trellis.PreferUserManaged, resource, DC.title, rdf.createLiteral("direct container"));
    dataset.add(Trellis.PreferUserManaged, resource, DC.alternative, rdf.createLiteral("alt title"));
    dataset.add(Trellis.PreferUserManaged, resource, DC.description, rdf.createLiteral("LDP-DC pointing to self"));
    dataset.add(Trellis.PreferUserManaged, resource, LDP.membershipResource, container);
    dataset.add(Trellis.PreferUserManaged, resource, LDP.hasMemberRelation, DC.relation);
    final Instant later = meanwhile();
    assertDoesNotThrow(() -> allOf(svc.create(builder(resource).interactionModel(LDP.DirectContainer).membershipResource(container).memberRelation(DC.relation).container(root).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
    allOf(svc.get(resource).thenAccept(checkResource(later, LDP.DirectContainer, 5L, 0L, 0L)).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture()).join();
    // Now add the child resources to the ldp-dc
    dataset.clear();
    dataset.add(Trellis.PreferUserManaged, child, DC.title, rdf.createLiteral("ldp-dc (self) child 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, 1L, 0L)).toCompletableFuture(), svc.get(resource).thenAccept(res -> {
        assertAll("Check resource", checkResource(res, resource, LDP.DirectContainer, evenLater));
        assertAll("Check resource stream", checkResourceStream(res, 5L, 0L, 0L, 1L, 1L));
        assertTrue(res.stream(LDP.PreferContainment).anyMatch(isEqual(rdf.createQuad(LDP.PreferContainment, container, LDP.contains, child))), "Missing contains triple!");
        assertTrue(res.stream(LDP.PreferMembership).anyMatch(isEqual(rdf.createQuad(LDP.PreferMembership, container, DC.relation, child))), "Missing membership triple!");
    }).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture(), svc.get(root).thenAccept(checkPredates(evenLater)).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) IRI(org.apache.commons.rdf.api.IRI) RDFLinkDataset(org.apache.jena.rdflink.RDFLinkDataset) Dataset(org.apache.commons.rdf.api.Dataset) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Aggregations

Stream (java.util.stream.Stream)15 IRI (org.apache.commons.rdf.api.IRI)15 LDP (org.trellisldp.vocabulary.LDP)15 Resource (org.trellisldp.api.Resource)14 Instant (java.time.Instant)13 Dataset (org.apache.commons.rdf.api.Dataset)13 BinaryMetadata (org.trellisldp.api.BinaryMetadata)13 DELETED_RESOURCE (org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE)13 MISSING_RESOURCE (org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE)13 AS (org.trellisldp.vocabulary.AS)13 Map (java.util.Map)12 Predicate.isEqual (java.util.function.Predicate.isEqual)12 RDF (org.apache.commons.rdf.api.RDF)12 Assertions (org.junit.jupiter.api.Assertions)12 Executable (org.junit.jupiter.api.function.Executable)12 RDFFactory (org.trellisldp.api.RDFFactory)12 DC (org.trellisldp.vocabulary.DC)12 RDF.type (org.trellisldp.vocabulary.RDF.type)12 SKOS (org.trellisldp.vocabulary.SKOS)12 Trellis (org.trellisldp.vocabulary.Trellis)12