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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations