private Graph createGraph2() { final RDF factory2 = createFactory(); final IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name"); final Graph g2 = factory2.createGraph(); final BlankNode b1 = createOwnBlankNode("b1", "bc8d3e45-a08f-421d-85b3-c25b373abf87"); g2.add(b1, name, factory2.createLiteral("Charlie")); final BlankNode b2 = createOwnBlankNode("b2", "2209097a-5078-4b03-801a-6a2d2f50d739"); g2.add(b2, name, factory2.createLiteral("Dave")); final IRI hasChild = factory2.createIRI("http://example.com/hasChild"); // NOTE: Opposite direction of loadGraph1 g2.add(b2, hasChild, b1); return g2; }
try (final Graph g1 = createGraph1(); final Graph g2 = createGraph2(); final Graph g3 = factory.createGraph()) { addAllTriples(g1, g3); addAllTriples(g2, g3); notEquals(b1Alice, b2Bob); notEquals(b1Alice, b1Charlie); notEquals(b1Alice, b2Dave); notEquals(b2Bob, b1Charlie); notEquals(b2Bob, b2Dave); notEquals(b1Charlie, b2Dave);
@Test public void streamLanguageTagsCaseInsensitive() throws Exception { // COMMONSRDF-51: Ensure we can add/contains/remove with any casing // of literal language tag final Literal lower = factory.createLiteral("Hello", "en-gb"); final Literal upper = factory.createLiteral("Hello", "EN-GB"); final Literal mixed = factory.createLiteral("Hello", "en-GB"); final IRI example1 = factory.createIRI("http://example.com/s1"); final IRI greeting = factory.createIRI("http://example.com/greeting"); try (final Graph graph = factory.createGraph()) { graph.add(example1, greeting, upper); // or as patterns assertTrue(closableFindAny(graph.stream(null, null, upper)).isPresent()); assertTrue(closableFindAny(graph.stream(null, null, lower)).isPresent()); assertTrue(closableFindAny(graph.stream(null, null, mixed)).isPresent()); // Check the triples returned equal a new triple final Triple t = closableFindAny(graph.stream(null, null, lower)).get(); assertEquals(t, factory.createTriple(example1, greeting, mixed)); } }
@Before public void createGraphAndAdd() { factory = createFactory(); graph = factory.createGraph(); assertEquals(0, graph.size());
@Test public void iterate() throws Exception { Assume.assumeTrue(graph.size() > 0); final List<Triple> triples = new ArrayList<>(); for (final Triple t : graph.iterate()) { triples.add(t); } assertEquals(graph.size(), triples.size()); if (bobNameTriple != null) { assertTrue(triples.contains(bobNameTriple)); } // aborted iteration final Iterable<Triple> iterate = graph.iterate(); final Iterator<Triple> it = iterate.iterator(); assertTrue(it.hasNext()); it.next(); closeIterable(iterate); // second iteration - should start from fresh and // get the same count long count = 0; final Iterable<Triple> iterable = graph.iterate(); for (@SuppressWarnings("unused") final Triple t : iterable) { count++; } assertEquals(graph.size(), count); }
@Before public void createGraphAndAdd() { factory = createFactory(); graph = factory.createGraph(); assertEquals(0, graph.size());
/** * Make a new graph with two BlankNodes - each with a different * uniqueReference */ private Graph createGraph1() { final RDF factory1 = createFactory(); final IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name"); final Graph g1 = factory1.createGraph(); final BlankNode b1 = createOwnBlankNode("b1", "0240eaaa-d33e-4fc0-a4f1-169d6ced3680"); g1.add(b1, name, factory1.createLiteral("Alice")); final BlankNode b2 = createOwnBlankNode("b2", "9de7db45-0ce7-4b0f-a1ce-c9680ffcfd9f"); g1.add(b2, name, factory1.createLiteral("Bob")); final IRI hasChild = factory1.createIRI("http://example.com/hasChild"); g1.add(b1, hasChild, b2); return g1; }