assertNotEquals(testNull.internalIdentifier(), testAutomatic1.internalIdentifier()); assertNotEquals(testAutomatic1.internalIdentifier(), testNull.internalIdentifier()); assertNotEquals(testNull.internalIdentifier(), testManual3a.internalIdentifier()); assertNotEquals(testManual3a.internalIdentifier(), testNull.internalIdentifier()); assertEquals(testAutomatic1.internalIdentifier(), testAutomatic1.internalIdentifier()); assertEquals(testAutomatic2.internalIdentifier(), testAutomatic2.internalIdentifier()); assertNotEquals(testAutomatic1.internalIdentifier(), testAutomatic2.internalIdentifier()); assertNotEquals(testAutomatic2.internalIdentifier(), testAutomatic1.internalIdentifier()); assertNotEquals(testAutomatic1.internalIdentifier(), testManual3a.internalIdentifier()); assertEquals(testManual3b.internalIdentifier(), testManual3a.internalIdentifier()); assertNotEquals(testManual3a.internalIdentifier(), testManual4.internalIdentifier());
@Test public void testCreateBlankNode() throws Exception { BlankNode bnode; try { bnode = factory.createBlankNode(); } catch (UnsupportedOperationException ex) { Assume.assumeNoException(ex); return; } BlankNode bnode2 = factory.createBlankNode(); assertNotEquals( "Second blank node has not got a unique internal identifier", bnode.internalIdentifier(), bnode2.internalIdentifier()); }
private RDFTerm inScope(Optional<Graph> localScope, RDFTerm object) { if (!(object instanceof BlankNode) && !(object instanceof IRI) & !(object instanceof Literal)) { throw new IllegalArgumentException( "RDFTerm must be BlankNode, IRI or Literal"); } if (object instanceof BlankNode) { BlankNode blankNode = (BlankNode) object; return new BlankNodeImpl(Objects.requireNonNull(localScope), blankNode.internalIdentifier()); } else if (object instanceof IRI && !(object instanceof IRIImpl)) { IRI iri = (IRI) object; return new IRIImpl(iri.getIRIString()); } else if (object instanceof Literal && !(object instanceof LiteralImpl)) { Literal literal = (Literal) object; if (literal.getLanguageTag().isPresent()) { return new LiteralImpl(literal.getLexicalForm(), literal .getLanguageTag().get()); } else { IRI dataType = (IRI) inScope(localScope, literal.getDatatype()); return new LiteralImpl(literal.getLexicalForm(), dataType); } } else { return object; } }
@Test public void testCreateBlankNodeIdentifier() throws Exception { BlankNode bnode; try { bnode = factory.createBlankNode("example1"); } catch (UnsupportedOperationException ex) { Assume.assumeNoException(ex); return; } assertEquals("example1", bnode.internalIdentifier()); // .. but we can't assume the internal identifier leaks into // ntriplesString // assertEquals("_:example1", bnode.ntriplesString()); }
@Test public void testCreateBlankNodeIdentifierTwice() throws Exception { BlankNode bnode1, bnode2, bnode3; try { bnode1 = factory.createBlankNode("example1"); bnode2 = factory.createBlankNode("example1"); bnode3 = factory.createBlankNode("differ"); } catch (UnsupportedOperationException ex) { Assume.assumeNoException(ex); return; } assertEquals(bnode1.internalIdentifier(), bnode2.internalIdentifier()); // We don't know what the ntriplesString is, but it MUST be the same assertEquals(bnode1.ntriplesString(), bnode2.ntriplesString()); // and here it MUST differ assertNotEquals(bnode1.ntriplesString(), bnode3.ntriplesString()); }