/** * Check the absense of audit triples. */ @Test @DisplayName("Check the absense of audit triples.") default void testNoAuditTriples() { try (final Response res = target(getResourceLocation()).request().get()) { final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertEquals(2L, g.size(), "Check that the graph has 2 triples"); } }
/** * Check the absense of audit triples. */ @Test @DisplayName("Check the absense of audit triples.") default void testNoAuditTriples() { try (final Response res = target(getResourceLocation()).request().get()) { final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertEquals(2L, g.size(), "Check that the graph has 2 triples"); } }
/** * Check the explicit absense of audit triples. */ @Test @DisplayName("Check the explicit absense of audit triples.") default void testOmitAuditTriples() { try (final Response res = target(getResourceLocation()).request().header("Prefer", "return=representation; omit=\"" + Trellis.PreferAudit.getIRIString() + "\"").get()) { final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertEquals(2L, g.size(), "Check that the graph has only 2 triples"); } }
/** * Check the explicit absense of audit triples. */ @Test @DisplayName("Check the explicit absense of audit triples.") default void testOmitAuditTriples() { try (final Response res = target(getResourceLocation()).request().header("Prefer", "return=representation; omit=\"" + Trellis.PreferAudit.getIRIString() + "\"").get()) { final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertEquals(2L, g.size(), "Check that the graph has only 2 triples"); } }
@Test public void size() throws Exception { assertEquals(1, graph.size()); }
@Test public void testCollectGraph() { final Graph graph = generate(() -> rdf.createTriple(getIRI(), getIRI(), getIRI())) .parallel().limit(size).collect(toGraph()); assertTrue(size >= graph.size(), "Generated graph has too many triples!"); }
@Test public void testCreateGraph() throws Exception { try (final Graph graph = factory.createGraph(); final Graph graph2 = factory.createGraph()) { assertEquals("Graph was not empty", 0, graph.size()); graph.add(factory.createBlankNode(), factory.createIRI("http://example.com/"), factory.createBlankNode()); assertNotSame(graph, graph2); assertEquals("Graph was empty after adding", 1, graph.size()); assertEquals("New graph was not empty", 0, graph2.size()); } }
@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!"); }
@Test public void testAuditUpdate() { final Dataset dataset = rdf.createDataset(); final AuditService svc = new DefaultAuditService() {}; svc.update(subject, mockSession).forEach(dataset::add); assertTrue(dataset.getGraph(Trellis.PreferAudit).filter(graph -> graph.size() == dataset.size()).isPresent()); assertTrue(dataset.contains(null, null, type, AS.Update)); assertAll("Event property check", checkEventProperties(dataset)); }
@Test public void testAuditDeletion() { final Dataset dataset = rdf.createDataset(); final AuditService svc = new DefaultAuditService() {}; svc.deletion(subject, mockSession).forEach(dataset::add); assertTrue(dataset.getGraph(Trellis.PreferAudit).filter(graph -> graph.size() == dataset.size()).isPresent(), "Graph and dataset sizes don't match for deletion event!"); assertTrue(dataset.contains(null, null, type, AS.Delete), "as:Delete type not in delete dataset!"); assertAll("Event property check", checkEventProperties(dataset)); }
@Test public void testAuditCreation() { final Dataset dataset = rdf.createDataset(); final AuditService svc = new DefaultAuditService() {}; svc.creation(subject, mockSession).forEach(dataset::add); assertTrue(dataset.getGraph(Trellis.PreferAudit).filter(graph -> graph.size() == dataset.size()).isPresent(), "Graph and dataset sizes don't match for creation event!"); assertTrue(dataset.contains(null, null, type, AS.Create), "as:Create type not in create dataset!"); assertAll("Event property check", checkEventProperties(dataset)); }
@Test public void getGraphNull() throws Exception { // Default graph should be present try (final Graph defaultGraph = dataset.getGraph(null).get()) { // TODO: Can we assume the default graph was empty before our new triples? assertEquals(2, defaultGraph.size()); assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1)); // NOTE: wildcard as graph2 is a (potentially mapped) BlankNode assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null)); } }
@Test public void getGraph2() throws Exception { // graph2 should be present, even if is named by a BlankNode // We'll look up the potentially mapped graph2 blanknode final BlankNodeOrIRI graph2Name = (BlankNodeOrIRI) dataset.stream(Optional.empty(), bob, isPrimaryTopicOf, null) .map(Quad::getObject).findAny().get(); try (final Graph g2 = dataset.getGraph(graph2Name).get()) { assertEquals(4, g2.size()); final Triple bobNameTriple = bobNameQuad.asTriple(); assertTrue(g2.contains(bobNameTriple)); assertTrue(g2.contains(bob, member, bnode1)); assertTrue(g2.contains(bob, member, bnode2)); assertFalse(g2.contains(bnode1, name, secretClubName)); assertTrue(g2.contains(bnode2, name, companyName)); } }
@Test public void parseTurtle() throws Exception { try (final Graph g = new JenaRDF().createGraph()) { final Future<ParseResult> gFuture = new JenaRDFParser().contentType(RDFSyntax.TURTLE).source(turtleFile) .target(g).parse(); gFuture.get(5, TimeUnit.SECONDS); assertEquals(3, g.size()); } } }
@Test public void getGraph() throws Exception { try (final Graph defaultGraph = dataset.getGraph()) { // TODO: Can we assume the default graph was empty before our new triples? assertEquals(2, defaultGraph.size()); assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1)); // NOTE: graph2 is a BlankNode assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null)); } }
@Test public void getGraph1() throws Exception { // graph1 should be present try (final Graph g1 = dataset.getGraph(graph1).get()) { assertEquals(4, g1.size()); assertTrue(g1.contains(alice, name, aliceName)); assertTrue(g1.contains(alice, knows, bob)); assertTrue(g1.contains(alice, member, null)); assertTrue(g1.contains(null, name, secretClubName)); } }