GraphReaderWriter { public static DependencyGraph merge(DependencyGraph targetGraph, String filename) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); IOGraph ioGraph; try { ioGraph = mapper.readValue(new File(filename), IOGraph.class); } catch (IOException e) { throw new IllegalStateException("Error reading from file: " + FileNameUtil.getCanonicalPath(filename), e); } return IO_GRAPH_MAPPER.mergeDependencyGraph(targetGraph, ioGraph); } private  GraphReaderWriter(); static void write(DependencyGraph dependencyGraph, String filename); static DependencyGraph read(String filename); static DependencyGraph merge(DependencyGraph targetGraph, String filename);  }
@Test public void testMergeSame() { DependencyGraph graph = DependencyGraphFactory.createGraph(); GraphReaderWriter.merge(graph, "src/test/resources/graphs/testGraph1.json"); assertThat(graph.getAllNodes()).hasSize(5); GraphReaderWriter.merge(graph, "src/test/resources/graphs/testGraph1.json"); assertThat(graph.getAllNodes()).hasSize(5); }
@Test public void testMergeNoOverlap() { DependencyGraph graph = DependencyGraphFactory.createGraph(); GraphReaderWriter.merge(graph, "src/test/resources/graphs/testGraph1.json"); assertThat(graph.getAllNodes()).hasSize(5); GraphReaderWriter.merge(graph, "src/test/resources/graphs/testGraph2.json"); assertThat(graph.getAllNodes()).hasSize(10); }
@Test public void testMergeWithOverlap() { DependencyGraph graph = DependencyGraphFactory.createGraph(); GraphReaderWriter.merge(graph, "src/test/resources/graphs/testGraph1.json"); assertThat(graph.getAllNodes()).hasSize(5); assertThat(graph.getNode("v1").getProperty("list-key-1")).isEqualTo(Lists.newArrayList("a", "b", "c")); assertThat(graph.getNode("v1").getProperty("KEY")).isEqualTo(5); DependencyGraph graph3 = DependencyGraphFactory.createGraph(); GraphReaderWriter.merge(graph3, "src/test/resources/graphs/testGraph3.json"); assertThat(graph3.getAllNodes()).hasSize(2); assertThat(graph3.getNode("v1")).isNotNull(); assertThat(graph3.getNode("v1").getProperty("list-key-1")).isEqualTo(Lists.newArrayList("c", "d")); assertThat(graph3.getNode("v6")).isNotNull(); assertThat(graph3.getNode("v1").getProperty("KEY")).isEqualTo(6); GraphReaderWriter.merge(graph, "src/test/resources/graphs/testGraph3.json"); assertThat(graph.getAllNodes()).hasSize(6); assertThat(graph.getNode("v1").getProperty("list-key-1")).isEqualTo(Lists.newArrayList("a", "b", "c", "d")); assertThat(graph.getNode("v1").getProperty("KEY")).isEqualTo(Lists.newArrayList(5, 6)); }