Remove req f1.createBlankNode("a") differ f2.createBlankNode("b")
.. but still test we can add blank nodes from two fresh graphs/factories into a third graph. Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/6fa2b48c Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/6fa2b48c Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/6fa2b48c Branch: refs/heads/quad Commit: 6fa2b48c92aea04ac41b3136f9f3a162293139e1 Parents: c8099bc Author: Stian Soiland-Reyes <st...@apache.org> Authored: Mon Apr 11 15:33:26 2016 +0100 Committer: Stian Soiland-Reyes <st...@apache.org> Committed: Mon Apr 11 15:33:26 2016 +0100 ---------------------------------------------------------------------- .../commons/rdf/api/AbstractGraphTest.java | 31 ++++++++++++-------- .../rdf/api/AbstractRDFTermFactoryTest.java | 17 ++++++++--- 2 files changed, 31 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6fa2b48c/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java ---------------------------------------------------------------------- diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java index 8b1d2f9..a6c4397 100644 --- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java +++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java @@ -273,21 +273,30 @@ public abstract class AbstractGraphTest { public void addBlankNodesFromMultipleGraphs() { try { + // Create two separate Graph instances Graph g1 = createGraph1(); Graph g2 = createGraph2(); - Graph g3 = factory.createGraph(); + // and add them to a new Graph g3 + Graph g3 = factory.createGraph(); addAllTriples(g1, g3); addAllTriples(g2, g3); - IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name"); + + // Let's make a map to find all those blank nodes after insertion + // (The Graph implementation is not currently required to + // keep supporting those BlankNodes with contains() - see COMMONSRDF-15) final Map<String, BlankNodeOrIRI> whoIsWho = new ConcurrentHashMap<>(); // ConcurrentHashMap as we will try parallel forEach below, // which should not give inconsistent results (it does with a // HashMap!) + + // look up BlankNodes by name + IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name"); g3.getTriples(null, name, null).parallel().forEach( t -> whoIsWho.put( t.getObject().ntriplesString(), t.getSubject())); + assertEquals(4, whoIsWho.size()); // and contains 4 unique values assertEquals(4, new HashSet<BlankNodeOrIRI>(whoIsWho.values()).size()); @@ -301,6 +310,7 @@ public abstract class AbstractGraphTest { BlankNodeOrIRI b2Dave = whoIsWho.get("\"Dave\""); assertNotNull(b2Dave); + // All blank nodes should differ notEquals(b1Alice, b2Bob); notEquals(b1Alice, b1Charlie); notEquals(b1Alice, b2Dave); @@ -308,6 +318,8 @@ public abstract class AbstractGraphTest { notEquals(b2Bob, b2Dave); notEquals(b1Charlie, b2Dave); + // And we should be able to query with them again + // as we got them back from g3 IRI hasChild = factory.createIRI("http://example.com/hasChild"); assertTrue(g3.contains(b1Alice, hasChild, b2Bob)); assertTrue(g3.contains(b2Dave, hasChild, b1Charlie)); @@ -352,16 +364,13 @@ public abstract class AbstractGraphTest { private Graph createGraph1() { RDFTermFactory factory1 = createFactory(); - // Let's assume this is parsed from - // a Turtle file <g1.ttl>, and faithfully keeps its - // internal blank node identifiers _:b1 and _:b2 IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name"); Graph g1 = factory1.createGraph(); - BlankNode b1 = factory1.createBlankNode("b1"); + BlankNode b1 = factory1.createBlankNode(); g1.add(b1, name, factory1.createLiteral("Alice")); - BlankNode b2 = factory1.createBlankNode("b2"); + BlankNode b2 = factory1.createBlankNode(); g1.add(b2, name, factory1.createLiteral("Bob")); IRI hasChild = factory1.createIRI("http://example.com/hasChild"); @@ -371,19 +380,15 @@ public abstract class AbstractGraphTest { } private Graph createGraph2() { - // Let's assume this is parsed from - // a Turtle file <g2.ttl>, which also uses the - // internal blank node identifiers _:b1 and _:b2, - // but is describing someone else. RDFTermFactory factory2 = createFactory(); IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name"); Graph g2 = factory2.createGraph(); - BlankNode b1 = factory2.createBlankNode("b1"); + BlankNode b1 = factory2.createBlankNode(); g2.add(b1, name, factory2.createLiteral("Charlie")); - BlankNode b2 = factory2.createBlankNode("b2"); + BlankNode b2 = factory2.createBlankNode(); g2.add(b2, name, factory2.createLiteral("Dave")); IRI hasChild = factory2.createIRI("http://example.com/hasChild"); http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6fa2b48c/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java ---------------------------------------------------------------------- diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java index 5056c9d..17dd05f 100644 --- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java +++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java @@ -117,9 +117,18 @@ public abstract class AbstractRDFTermFactoryTest { public void testCreateBlankNodeIdentifierTwiceDifferentFactories() throws Exception { BlankNode bnode1, differentFactory; try { - bnode1 = factory.createBlankNode("example1"); - // it should differ from a second factory - differentFactory = createFactory().createBlankNode("example1"); + bnode1 = factory.createBlankNode(); + // it MUST differ from a second factory + differentFactory = createFactory().createBlankNode(); + + // NOTE: We can't make similar assumption if we provide a + // name to createBlankNode(String) as its documentation + // only says: + // + // * BlankNodes created using this method with the same parameter, for + // * different instances of RDFTermFactory, SHOULD NOT be equivalent. + // + // https://github.com/apache/incubator-commonsrdf/pull/7#issuecomment-92312779 } catch (UnsupportedOperationException ex) { Assume.assumeNoException(ex); return; @@ -128,7 +137,7 @@ public abstract class AbstractRDFTermFactoryTest { assertNotEquals(bnode1, differentFactory); assertNotEquals(bnode1.uniqueReference(), differentFactory.uniqueReference()); - // but not + // but we can't require: //assertNotEquals(bnode1.ntriplesString(), differentFactory.ntriplesString()); }