Search in sources :

Example 21 with Dataset

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));
}
Also used : Dataset(org.apache.commons.rdf.api.Dataset) Test(org.junit.jupiter.api.Test)

Example 22 with Dataset

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");
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) Dataset(org.apache.commons.rdf.api.Dataset) Test(org.junit.jupiter.api.Test)

Example 23 with Dataset

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;
}
Also used : Dataset(org.apache.commons.rdf.api.Dataset)

Example 24 with 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));
}
Also used : Dataset(org.apache.commons.rdf.api.Dataset) Test(org.junit.jupiter.api.Test)

Example 25 with Dataset

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");
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) Dataset(org.apache.commons.rdf.api.Dataset) Test(org.junit.jupiter.api.Test)

Aggregations

Dataset (org.apache.commons.rdf.api.Dataset)104 IRI (org.apache.commons.rdf.api.IRI)70 Test (org.junit.jupiter.api.Test)59 Resource (org.trellisldp.api.Resource)47 Instant (java.time.Instant)45 RDF (org.apache.commons.rdf.api.RDF)38 LDP (org.trellisldp.vocabulary.LDP)33 Stream (java.util.stream.Stream)30 Map (java.util.Map)28 BinaryMetadata (org.trellisldp.api.BinaryMetadata)28 RDFFactory (org.trellisldp.api.RDFFactory)28 Quad (org.apache.commons.rdf.api.Quad)27 Metadata (org.trellisldp.api.Metadata)27 TRELLIS_DATA_PREFIX (org.trellisldp.api.TrellisUtils.TRELLIS_DATA_PREFIX)27 MISSING_RESOURCE (org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE)25 AS (org.trellisldp.vocabulary.AS)25 Trellis (org.trellisldp.vocabulary.Trellis)22 Logger (org.slf4j.Logger)21 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)21 DELETED_RESOURCE (org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE)21