UriRef property2 = new UriRef("http://example.org/property2");
UriRef newUriRef = new UriRef("http://example.org/newName");
Literal literal1 = new PlainLiteralImpl("literal");
Literal literal2 = new PlainLiteralImpl("bla bla");
Triple triple1 = new TripleImpl(bNode1, property1, literal1);
Triple triple2 = new TripleImpl(bNode1, property2, property1);
Triple triple3 = new TripleImpl(bNode2, property2, bNode1);
Triple triple4 = new TripleImpl(property1, property1, bNode2);
Triple triple5 = new TripleImpl(property1, property1, literal2);
initialGraph.add(triple1);
initialGraph.add(triple2);
initialGraph.add(triple3);
initialGraph.add(triple4);
initialGraph.add(triple5);
GraphNode node = new GraphNode(property1,
new SimpleMGraph(initialGraph.iterator()));
node.replaceWith(newUriRef, true);
Assert.assertEquals(5, node.getGraph().size());
Triple expectedTriple1 = new TripleImpl(bNode1, newUriRef, literal1);
Triple expectedTriple2 = new TripleImpl(bNode1, property2, newUriRef);
Triple expectedTriple3 = new TripleImpl(newUriRef, newUriRef, bNode2);
Triple expectedTriple4 = new TripleImpl(newUriRef, newUriRef, literal2);
Assert.assertTrue(node.getGraph().contains(expectedTriple1));
Assert.assertTrue(node.getGraph().contains(expectedTriple2));
Assert.assertTrue(node.getGraph().contains(expectedTriple3));
Assert.assertTrue(node.getGraph().contains(expectedTriple4));
Assert.assertFalse(node.getGraph().contains(triple1));
Assert.assertFalse(node.getGraph().contains(triple2));
Assert.assertFalse(node.getGraph().contains(triple4));
Assert.assertFalse(node.getGraph().contains(triple5));
node = new GraphNode(property1, new SimpleMGraph(initialGraph.iterator()));
node.replaceWith(newBnode);
Triple expectedTriple5 = new TripleImpl(bNode1, property2, newBnode);
Triple expectedTriple6 = new TripleImpl(newBnode, property1, bNode2);
Triple expectedTriple7 = new TripleImpl(newBnode, property1, literal2);
Assert.assertTrue(node.getGraph().contains(triple1));
Assert.assertTrue(node.getGraph().contains(expectedTriple5));
Assert.assertTrue(node.getGraph().contains(expectedTriple6));
Assert.assertTrue(node.getGraph().contains(expectedTriple7));
node = new GraphNode(literal1, new SimpleMGraph(initialGraph.iterator()));
node.replaceWith(newBnode);
Triple expectedTriple8 = new TripleImpl(bNode1, property1, newBnode);
Assert.assertTrue(node.getGraph().contains(expectedTriple8));
node = new GraphNode(property1, new SimpleMGraph(initialGraph.iterator()));
node.replaceWith(newUriRef);
Triple expectedTriple9 = new TripleImpl(bNode1, property2, newUriRef);
Triple expectedTriple10 = new TripleImpl(newUriRef, property1, bNode2);
Triple expectedTriple11 = new TripleImpl(newUriRef, property1, literal2);
Assert.assertTrue(node.getGraph().contains(triple1));
Assert.assertTrue(node.getGraph().contains(expectedTriple9));
Assert.assertTrue(node.getGraph().contains(expectedTriple10));
Assert.assertTrue(node.getGraph().contains(expectedTriple11));
}