Search in sources :

Example 1 with Triple

use of org.apache.commons.rdf.api.Triple in project trellis by trellis-ldp.

the class DefaultRdfaWriterServiceTest method testWriteError.

@Test
void testWriteError() throws IOException {
    doThrow(new IOException()).when(mockOutputStream).write(any(byte[].class), anyInt(), anyInt());
    final Stream<Triple> triples = getTriples();
    assertThrows(UncheckedIOException.class, () -> service.write(triples, mockOutputStream, ""), "IOException in write operation doesn't cause failure!");
}
Also used : Triple(org.apache.commons.rdf.api.Triple) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test)

Example 2 with Triple

use of org.apache.commons.rdf.api.Triple in project trellis by trellis-ldp.

the class LabelledTripleTest method testOrdinaryLabelledTriple3.

@Test
void testOrdinaryLabelledTriple3() {
    final Triple triple = rdf.createTriple(rdf.createIRI("test:value"), DC.title, rdf.createLiteral("A title"));
    final LabelledTriple t = new LabelledTriple(triple, null, null);
    assertEquals("test:value", t.getSubject(), "Subject value doesn't match!");
    assertEquals(DC.title.getIRIString(), t.getPredicateLabel(), "Predicate label doesn't match!");
    assertEquals(DC.title.getIRIString(), t.getPredicate(), "Predicate value doesn't match!");
    assertEquals("A title", t.getObjectLabel(), "Object label doesn't match!");
    assertEquals("A title", t.getObject(), "Object value doesn't match!");
}
Also used : Triple(org.apache.commons.rdf.api.Triple) Test(org.junit.jupiter.api.Test)

Example 3 with Triple

use of org.apache.commons.rdf.api.Triple in project trellis by trellis-ldp.

the class LabelledTripleTest method testOrdinaryLabelledTriple.

@Test
void testOrdinaryLabelledTriple() {
    final Triple triple = rdf.createTriple(rdf.createIRI("test:value"), DC.title, rdf.createLiteral("A title"));
    final LabelledTriple t = new LabelledTriple(triple, "title", null);
    assertEquals("title", t.getPredicateLabel(), "Predicate label doesn't match!");
    assertEquals(DC.title.getIRIString(), t.getPredicate(), "Predicate value doesn't match!");
    assertEquals("A title", t.getObjectLabel(), "Object label doesn't match!");
    assertEquals("A title", t.getObject(), "Object value doesn't match!");
}
Also used : Triple(org.apache.commons.rdf.api.Triple) Test(org.junit.jupiter.api.Test)

Example 4 with Triple

use of org.apache.commons.rdf.api.Triple in project trellis by trellis-ldp.

the class AuditTests method testAuditTriples.

/**
 * Check the presence of audit triples.
 * @throws Exception if the RDF resource didn't close cleanly
 */
default void testAuditTriples() throws Exception {
    final RDF rdf = RDFFactory.getInstance();
    try (final Response res = target(getResourceLocation()).request().header("Prefer", "return=representation; include=\"" + Trellis.PreferAudit.getIRIString() + "\"").get();
        final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE)) {
        assertEquals(3L, g.stream(rdf.createIRI(getResourceLocation()), PROV.wasGeneratedBy, null).count(), "Check for the presence of audit triples in the graph");
        assertAll("Check the graph triples", g.stream(rdf.createIRI(getResourceLocation()), PROV.wasGeneratedBy, null).flatMap(triple -> of(() -> assertTrue(g.contains((BlankNodeOrIRI) triple.getObject(), type, PROV.Activity), "Verify that the prov:activity type is present for the resource"), () -> assertTrue(g.contains((BlankNodeOrIRI) triple.getObject(), PROV.atTime, null), "Verify that the prov:atTime property is present for the resource"), () -> assertEquals(4L, g.stream((BlankNodeOrIRI) triple.getObject(), null, null).count(), "Verify that we have the right number of triples for the resource"))));
        assertTrue(g.contains(null, PROV.wasAssociatedWith, Trellis.AdministratorAgent), "Verify agent 1");
        assertTrue(g.contains(null, PROV.wasAssociatedWith, rdf.createIRI("https://madison.example.com/profile#me")), "Verify agent 2");
        assertTrue(g.contains(null, PROV.wasAssociatedWith, rdf.createIRI("https://people.apache.org/~acoburn/#i")), "Verify agent 3");
        assertEquals(2L, g.stream(null, type, AS.Update).count(), "Count the number of update events");
        assertEquals(1L, g.stream(null, type, AS.Create).count(), "Count the number of create events");
        assertEquals(11L, g.stream().map(Triple::getPredicate).filter(isEqual(type).negate()).count(), "Get the total graph size, absent any type triples");
    }
}
Also used : Response(javax.ws.rs.core.Response) LINK(javax.ws.rs.core.HttpHeaders.LINK) SUCCESSFUL(javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) Entity.entity(javax.ws.rs.client.Entity.entity) RDF.type(org.trellisldp.vocabulary.RDF.type) Link.fromUri(javax.ws.rs.core.Link.fromUri) RDF(org.apache.commons.rdf.api.RDF) TestUtils.getResourceAsString(org.trellisldp.test.TestUtils.getResourceAsString) Triple(org.apache.commons.rdf.api.Triple) SLUG(org.trellisldp.common.HttpConstants.SLUG) APPLICATION_SPARQL_UPDATE(org.trellisldp.common.RdfMediaType.APPLICATION_SPARQL_UPDATE) AS(org.trellisldp.vocabulary.AS) TURTLE(org.apache.commons.rdf.api.RDFSyntax.TURTLE) TEXT_TURTLE(org.trellisldp.common.RdfMediaType.TEXT_TURTLE) Graph(org.apache.commons.rdf.api.Graph) LDP(org.trellisldp.vocabulary.LDP) AUTHORIZATION(javax.ws.rs.core.HttpHeaders.AUTHORIZATION) Trellis(org.trellisldp.vocabulary.Trellis) Jwt(io.smallrye.jwt.build.Jwt) RDFFactory(org.trellisldp.api.RDFFactory) Stream.of(java.util.stream.Stream.of) Predicate.isEqual(java.util.function.Predicate.isEqual) BlankNodeOrIRI(org.apache.commons.rdf.api.BlankNodeOrIRI) Stream(java.util.stream.Stream) PROV(org.trellisldp.vocabulary.PROV) Response(javax.ws.rs.core.Response) Executable(org.junit.jupiter.api.function.Executable) Assertions(org.junit.jupiter.api.Assertions) TestUtils.readEntityAsGraph(org.trellisldp.test.TestUtils.readEntityAsGraph) Graph(org.apache.commons.rdf.api.Graph) TestUtils.readEntityAsGraph(org.trellisldp.test.TestUtils.readEntityAsGraph) RDF(org.apache.commons.rdf.api.RDF) BlankNodeOrIRI(org.apache.commons.rdf.api.BlankNodeOrIRI)

Example 5 with Triple

use of org.apache.commons.rdf.api.Triple in project trellis by trellis-ldp.

the class JenaIOServiceTest method testWriteInvalidSyntax.

@Test
void testWriteInvalidSyntax() {
    when(mockSyntax.mediaType()).thenReturn("fake/mediatype");
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final Stream<Triple> triples = getTriples();
    assertThrows(TrellisRuntimeException.class, () -> service.write(triples, out, mockSyntax, identifier), "No exception thrown with invalid write syntax!");
}
Also used : Triple(org.apache.commons.rdf.api.Triple) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

Triple (org.apache.commons.rdf.api.Triple)28 IRI (org.apache.commons.rdf.api.IRI)13 Test (org.junit.jupiter.api.Test)11 BlankNode (org.apache.commons.rdf.api.BlankNode)8 Graph (org.apache.commons.rdf.api.Graph)8 Literal (org.apache.commons.rdf.api.Literal)7 Test (org.junit.Test)7 Stream (java.util.stream.Stream)6 RDF (org.apache.commons.rdf.api.RDF)6 List (java.util.List)5 BlankNodeOrIRI (org.apache.commons.rdf.api.BlankNodeOrIRI)5 Quad (org.apache.commons.rdf.api.Quad)5 RDFTerm (org.apache.commons.rdf.api.RDFTerm)5 RDFFactory (org.trellisldp.api.RDFFactory)5 TrellisRuntimeException (org.trellisldp.api.TrellisRuntimeException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Collectors.toList (java.util.stream.Collectors.toList)4 Dataset (org.apache.commons.rdf.api.Dataset)4 InputStream (java.io.InputStream)3