@Test public void getTriplesQuery() throws Exception { long aliceCount = graph.getTriples(alice, null, null).count(); assertTrue(aliceCount > 0); Assume.assumeNotNull(aliceName); assertEquals(3, aliceCount); Assume.assumeNotNull(org1, org2, bobName, companyName, secretClubName); assertEquals(4, graph.getTriples(null, name, null).count()); Assume.assumeNotNull(org1); assertEquals(2, graph.getTriples(null, member, org1).count()); }
@Test public void getTriples() throws Exception { long tripleCount = graph.getTriples().count(); assertTrue(tripleCount > 0); assertTrue(graph.getTriples().allMatch(t -> graph.contains(t))); // Check exact count Assume.assumeNotNull(org1, org2, aliceName, bobName, secretClubName, companyName, bobNameTriple); assertEquals(8, tripleCount); }
graph.getTriples(null, knows, null) .map(knowsTriple -> graph .getTriples( (BlankNodeOrIRI) knowsTriple .getObject(), member, null) .getTriples((BlankNodeOrIRI) org, name, null) .findFirst().get().getObject().ntriplesString()) .findFirst().get());
@Test public void contains() throws Exception { assertFalse(graph.contains(bob, knows, alice)); // or so he claims.. assertTrue(graph.contains(alice, knows, bob)); Optional<? extends Triple> first = graph.getTriples().skip(4) .findFirst(); Assume.assumeTrue(first.isPresent()); Triple existingTriple = first.get(); assertTrue(graph.contains(existingTriple)); Triple nonExistingTriple = factory.createTriple(bob, knows, alice); assertFalse(graph.contains(nonExistingTriple)); Triple triple = null; try { triple = factory.createTriple(alice, knows, bob); } catch (UnsupportedOperationException ex) { } if (triple != null) { // FIXME: Should not this always be true? // assertTrue(graph.contains(triple)); } }
@Test public void remove() throws Exception { long fullSize = graph.size(); graph.remove(alice, knows, bob); long shrunkSize = graph.size(); assertEquals(1, fullSize - shrunkSize); graph.remove(alice, knows, bob); assertEquals(shrunkSize, graph.size()); // unchanged graph.add(alice, knows, bob); graph.add(alice, knows, bob); graph.add(alice, knows, bob); // Undetermined size at this point -- but at least it // should be bigger assertTrue(graph.size() > shrunkSize); // and after a single remove they should all be gone graph.remove(alice, knows, bob); assertEquals(shrunkSize, graph.size()); Optional<? extends Triple> anyTriple = graph.getTriples().findAny(); Assume.assumeTrue(anyTriple.isPresent()); Triple otherTriple = anyTriple.get(); graph.remove(otherTriple); assertEquals(shrunkSize - 1, graph.size()); graph.remove(otherTriple); assertEquals(shrunkSize - 1, graph.size()); // no change graph.add(otherTriple); assertEquals(shrunkSize, graph.size()); }