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