@Test public void testWriteError() throws IOException { doThrow(new IOException()).when(mockOutputStream).write(any(byte[].class), anyInt(), anyInt()); assertThrows(RuntimeTrellisException.class, () -> service.write(getTriples(), mockOutputStream, TURTLE), "No write exception on bad input stream!"); }
@Test public void testJsonLdFlattenedSerializer2() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, compacted_flattened); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check flattened serialization", checkFlattenedSerialization(output, graph)); }
@Test public void testJsonLdExpandedSerializer() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, expanded); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check expanded serialization", checkExpandedSerialization(output, graph)); }
@Test public void testJsonLdExpandedFlatSerializer() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, expanded, flattened); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check expanded serialization", checkFlattenedSerialization(output, graph)); }
@Test public void testJsonLdFlattenedSerializer() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, flattened); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check flattened serialization", checkFlattenedSerialization(output, graph)); }
@Test public void testJsonLdFlattenedSerializer3() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, expanded_flattened); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check flattened serialization", checkFlattenedSerialization(output, graph)); }
@Test public void testJsonLdFlattenedSerializer4() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, compacted, flattened); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check flattened serialization", checkFlattenedSerialization(output, graph)); }
@Test public void testJsonLdDefaultSerializer() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service3.write(getTriples(), out, JSONLD); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service3.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check compact serialization", checkCompactSerialization(output, graph)); }
@Test public void testJsonLdCompactedSerializer() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, compacted); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check compact serialization", checkCompactSerialization(output, graph)); }
@Test public void testJsonLdCustomUnrecognizedSerializer3() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.trellisldp.org/ns/nonexistent.jsonld")); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check compact serialization", checkCompactSerialization(output, graph)); }
@Test public void testJsonLdCustomUnrecognizedSerializer() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.example.org/context.jsonld")); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check compact serialization", checkCompactSerialization(output, graph)); }
@Test public void testJsonLdCustomUnrecognizedSerializer2() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service2.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.example.org/context.jsonld")); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service2.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check compact serialization", checkCompactSerialization(output, graph)); }
@Test public void testUpdateInvalidSyntax() { final Graph graph = rdf.createGraph(); getTriples().forEach(graph::add); final String patch = "UpdateList <#> <http://example.org/vocab#preferredLanguages> 1..2 ( \"fr\" ) ."; assertThrows(RuntimeTrellisException.class, () -> service.update(graph, patch, LD_PATCH, null), "No exception thrown with invalid update syntax!"); }
@Test public void testJsonLdNullCache() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final IOService myservice = new JenaIOService(); myservice.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.w3.org/ns/anno.jsonld")); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); myservice.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertAll("Check compact serialization", checkCompactSerialization(output, graph)); }
@Test public void testTurtleSerializer() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, TURTLE); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final org.apache.jena.graph.Graph graph = createDefaultGraph(); RDFDataMgr.read(graph, in, Lang.TURTLE); assertTrue(validateGraph(rdf.asGraph(graph)), "Failed round-trip for Turtle!"); }
@Test public void testNTriplesSerializer() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service3.write(getTriples(), out, NTRIPLES); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final org.apache.jena.graph.Graph graph = createDefaultGraph(); RDFDataMgr.read(graph, in, Lang.NTRIPLES); assertTrue(validateGraph(rdf.asGraph(graph)), "Failed round-trip for N-Triples!"); }
@Test public void testBufferedSerializer() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, RDFXML); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final org.apache.jena.graph.Graph graph = createDefaultGraph(); RDFDataMgr.read(graph, in, Lang.RDFXML); assertTrue(validateGraph(rdf.asGraph(graph)), "Failed round-trip for RDFXML!"); }
@Test public void testNullHtmlSerializer() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, RDFA); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final org.apache.jena.graph.Graph graph = createDefaultGraph(); RDFDataMgr.read(graph, in, Lang.TURTLE); assertTrue(validateGraph(rdf.asGraph(graph)), "null HTML serialization didn't default to Turtle!"); }
@Test public void testJsonLdCustomSerializerNoopCache() throws UnsupportedEncodingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final IOService svc = new JenaIOService(mockNamespaceService, null, new NoopProfileCache(), "http://www.w3.org/ns/anno.jsonld,,,", "http://www.trellisldp.org/ns/"); svc.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.w3.org/ns/anno.jsonld")); final String output = out.toString("UTF-8"); final Graph graph = rdf.createGraph(); service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add); assertTrue(validateGraph(graph), "Not all triples present in output graph!"); }
@Test public void testUpdateError() { final Graph graph = rdf.createGraph(); getTriples().forEach(graph::add); assertEquals(3L, graph.size(), "Incorrect graph size!"); assertThrows(RuntimeTrellisException.class, () -> service.update(graph, "blah blah blah blah blah", SPARQL_UPDATE, null), "no exception on bad update!"); }