use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TriplestoreResourceTest method testResourceWithAuditQuads2.
@Test
void testResourceWithAuditQuads2() {
when(mockSession.getAgent()).thenReturn(Trellis.AnonymousAgent);
when(mockSession.getCreated()).thenReturn(created);
when(mockSession.getDelegatedBy()).thenReturn(empty());
final Dataset dataset = buildLdpDataset(LDP.RDFSource);
auditService.creation(identifier, mockSession).forEach(q -> dataset.add(auditId, q.getSubject(), q.getPredicate(), q.getObject()));
final TriplestoreResource res = new TriplestoreResource(connect(wrap(toJena(dataset))), identifier, extensions, true);
res.fetchData();
assertTrue(res.exists(), "Missing resource!");
assertAll("Check resource", checkResource(res, identifier, LDP.RDFSource, false, false, false));
assertAll("Check LDP properties", checkLdpProperties(res, null, null, null, null));
assertAll("Check RDF stream", checkRdfStream(res, 2L, 1L, 0L, 5L, 0L, 0L));
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TriplestoreResourceTest method testDirectContainer.
@Test
void testDirectContainer() {
final Dataset dataset = buildLdpDataset(LDP.DirectContainer);
dataset.add(Trellis.PreferServerManaged, identifier, DC.isPartOf, root);
dataset.add(Trellis.PreferServerManaged, identifier, LDP.member, member);
dataset.add(Trellis.PreferServerManaged, identifier, LDP.membershipResource, member);
dataset.add(Trellis.PreferServerManaged, identifier, LDP.hasMemberRelation, DC.subject);
dataset.add(Trellis.PreferServerManaged, identifier, LDP.insertedContentRelation, LDP.MemberSubject);
dataset.add(Trellis.PreferServerManaged, identifier, DC.modified, rdf.createLiteral(time, XSD.dateTime));
dataset.add(Trellis.PreferServerManaged, member, DC.isPartOf, root);
getChildIRIs().forEach(c -> {
dataset.add(Trellis.PreferServerManaged, c, DC.isPartOf, identifier);
dataset.add(Trellis.PreferServerManaged, c, type, LDP.RDFSource);
});
final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
final TriplestoreResource res = new TriplestoreResource(rdfConnection, identifier, extensions, true);
res.fetchData();
assertTrue(res.exists(), "Missing resource!");
assertAll("Check resource", checkResource(res, identifier, LDP.DirectContainer, false, false, true));
assertAll("Check LDP properties", checkLdpProperties(res, member, DC.subject, null, LDP.MemberSubject));
assertAll("Check RDF stream", checkRdfStream(res, 2L, 1L, 0L, 0L, 0L, 4L));
final TriplestoreResource memberRes = new TriplestoreResource(rdfConnection, member, extensions, false);
memberRes.fetchData();
assertTrue(memberRes.exists(), "Missing resource!");
assertAll("Check resource", checkResource(memberRes, member, LDP.RDFSource, false, false, true));
assertAll("Check LDP properties", checkLdpProperties(memberRes, null, null, null, null));
assertAll("Check RDF stream", checkRdfStream(memberRes, 1L, 0L, 0L, 0L, 4L, 0L));
assertEquals(4L, memberRes.stream(singleton(LDP.PreferMembership)).map(Quad::getPredicate).filter(isEqual(DC.subject)).count(), "Incorrect triple count!");
assertNotEquals(res.getRevision(), memberRes.getRevision(), "Revisions not unequal");
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TriplestoreResourceTest method buildLdpDataset.
static Dataset buildLdpDataset(final IRI ldpType) {
final Dataset dataset = rdf.createDataset();
dataset.add(identifier, identifier, type, SKOS.Concept);
dataset.add(identifier, identifier, SKOS.prefLabel, rdf.createLiteral("resource"));
dataset.add(member, member, SKOS.prefLabel, rdf.createLiteral("member resource"));
dataset.add(Trellis.PreferServerManaged, identifier, type, ldpType);
dataset.add(Trellis.PreferServerManaged, identifier, DC.modified, rdf.createLiteral(time, XSD.dateTime));
dataset.add(Trellis.PreferServerManaged, member, type, LDP.RDFSource);
dataset.add(Trellis.PreferServerManaged, member, DC.modified, rdf.createLiteral(time, XSD.dateTime));
return dataset;
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TriplestoreResourceTest method testResourceWithAclQuads.
@Test
void testResourceWithAclQuads() {
when(mockSession.getAgent()).thenReturn(Trellis.AnonymousAgent);
when(mockSession.getCreated()).thenReturn(created);
when(mockSession.getDelegatedBy()).thenReturn(empty());
final Dataset dataset = buildLdpDataset(LDP.RDFSource);
dataset.add(aclId, aclSubject, ACL.mode, ACL.Read);
dataset.add(aclId, aclSubject, ACL.agentClass, FOAF.Agent);
dataset.add(aclId, aclSubject, ACL.accessTo, identifier);
auditService.creation(identifier, mockSession).forEach(q -> dataset.add(auditId, q.getSubject(), q.getPredicate(), q.getObject()));
final TriplestoreResource res = new TriplestoreResource(connect(wrap(toJena(dataset))), identifier, extensions, false);
res.fetchData();
assertTrue(res.exists(), "Missing resource!");
assertAll("Check resource", checkResource(res, identifier, LDP.RDFSource, false, true, false));
assertAll("Check LDP properties", checkLdpProperties(res, null, null, null, null));
assertAll("Check RDF stream", checkRdfStream(res, 2L, 0L, 3L, 5L, 0L, 0L));
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TriplestoreResourceTest method testIndirectContainer.
@Test
void testIndirectContainer() {
final Dataset dataset = buildLdpDataset(LDP.IndirectContainer);
dataset.add(Trellis.PreferServerManaged, identifier, DC.isPartOf, root);
dataset.add(Trellis.PreferServerManaged, identifier, LDP.member, member);
dataset.add(Trellis.PreferServerManaged, identifier, LDP.membershipResource, member);
dataset.add(Trellis.PreferServerManaged, identifier, LDP.hasMemberRelation, DC.relation);
dataset.add(Trellis.PreferServerManaged, identifier, LDP.insertedContentRelation, DC.subject);
dataset.add(Trellis.PreferServerManaged, member, DC.isPartOf, root);
dataset.add(identifier, identifier, DC.alternative, rdf.createLiteral("An LDP-IC resource"));
dataset.add(member, member, DC.alternative, rdf.createLiteral("A membership resource"));
getChildIRIs().forEach(c -> {
dataset.add(Trellis.PreferServerManaged, c, DC.isPartOf, identifier);
dataset.add(Trellis.PreferServerManaged, c, type, LDP.RDFSource);
dataset.add(c, c, DC.subject, rdf.createIRI("http://example.org/" + randomUUID()));
});
final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
final TriplestoreResource res = new TriplestoreResource(rdfConnection, identifier, extensions, false);
res.fetchData();
assertTrue(res.exists(), "Missing resource!");
assertAll("Check resource", checkResource(res, identifier, LDP.IndirectContainer, false, false, true));
assertAll("Check LDP properties", checkLdpProperties(res, member, DC.relation, null, DC.subject));
assertAll("Check RDF stream", checkRdfStream(res, 3L, 0L, 0L, 0L, 0L, 4L));
final TriplestoreResource res2 = new TriplestoreResource(rdfConnection, member, extensions, false);
res2.fetchData();
assertTrue(res2.exists(), "Missing resource (2)!");
assertAll("Check resource", checkResource(res2, member, LDP.RDFSource, false, false, true));
assertAll("Check LDP properties", checkLdpProperties(res2, null, null, null, null));
assertAll("Check RDF stream", checkRdfStream(res2, 2L, 0L, 0L, 0L, 4L, 0L));
assertEquals(4L, res2.stream(singleton(LDP.PreferMembership)).map(Quad::getPredicate).filter(isEqual(DC.relation)).count(), "Incorrect triple count!");
assertNotEquals(res.getRevision(), res2.getRevision(), "Revisions not unequal");
}
Aggregations