public void testGraphSerialization() throws Exception { testCon.add(bob, name, nameBob); testCon.add(alice, name, nameAlice); Graph graph; RepositoryResult<Statement> statements = testCon.getStatements(null, null, null, true); try { graph = new GraphImpl(vf, statements.asList()); } finally { statements.close(); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(graph); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); Graph deserializedGraph = (Graph)in.readObject(); in.close(); assertFalse(deserializedGraph.isEmpty()); for (Statement st : deserializedGraph) { assertTrue(graph.contains(st)); assertTrue(testCon.hasStatement(st, true)); } }
/** * Compare two graphs for equality. * <p> * Note: This is not very efficient if the {@link Graph} implementations are * not indexed. * <p> * Note: This does not handle equality testing with blank nodes (it does not * test for isomorphic graphs). * * @param expected * @param actual */ static protected void assertSameGraph(final Graph expected, final Graph actual) { for (Statement s : expected) { if (!actual.contains(s)) fail("Expecting: " + s); } assertEquals("size", expected.size(), actual.size()); }
/** * Compare two graphs for equality. * <p> * Note: This is not very efficient if the {@link Graph} implementations are * not indexed. * <p> * Note: This does not handle equality testing with blank nodes (it does not * test for isomorphic graphs). * * @param expected * @param actual */ static protected void assertSameGraph(final Graph expected, final Graph actual) { for (Statement s : expected) { if (!actual.contains(s)) fail("Expecting: " + s); } assertEquals("size", expected.size(), actual.size()); }