DocumentMerger { public static void merge( final DocumentProperty existing, final Document proposed, final DocumentConstructor constructor) { requireNonNull(existing); requireNonNull(proposed); requireNonNull(constructor); proposed.getData().entrySet() .forEach(entry -> handleEntry(existing, proposed, constructor, entry)); } private  DocumentMerger(); static void merge(
            final DocumentProperty existing,
            final Document proposed,
            final DocumentConstructor constructor);  }
@Test void testMergeSimple() { Project newProject = createFromJson( "{\"config\":{" + "\"name\":\"TestProject\"," + "\"dbmses\":[{" + "\"name\":\"TestDbms\"," + "\"schemas\":[{" + "\"name\":\"TestSchema\"," + "\"alias\":\"NewTestSchema\"," + "\"tables\":[{" + "\"name\":\"TestTable1\"," + "\"columns\":[{" + "\"name\":\"TestTable1Column3\"," + "\"databaseType\":\"double\"" + "}]" + "}]" + "}]" + "}]" + "}}" ); DocumentPropertyComponent docProps = new DocumentPropertyComponentImpl(); project.merge(docProps, newProject); assertEquals("TestProject", project.getName()); assertEquals("TestDbms", dbms.getName()); assertEquals("TestSchema", schema.getName()); assertEquals("NewTestSchema", schema.getAlias().orElse(schema.getName())); assertEquals("TestTable1", table1.getName()); assertEquals("TestTable1Column1", table1Column1.getName()); assertEquals("TestTable1Column2", table1Column2.getName()); assertEquals("TestTable1Column3", table1Column3.getName()); assertEquals("int", table1Column1.getDatabaseType()); assertEquals("java.lang.String", table1Column2.getDatabaseType()); assertEquals("double", table1Column3.getDatabaseType()); }
@Test void testMergeNewColumn() { Project newProject = createFromJson( "{\"config\":{" + "\"name\":\"TestProject\"," + "\"dbmses\":[{" + "\"name\":\"TestDbms\"," + "\"schemas\":[{" + "\"name\":\"TestSchema\"," + "\"alias\":\"NewTestSchema\"," + "\"tables\":[{" + "\"name\":\"TestTable1\"," + "\"columns\":[{" + "\"name\":\"TestTable1Column4\"," + "\"databaseType\":\"double\"" + "}]" + "}]" + "}]" + "}]" + "}}" ); assertEquals(3, table1.columns().count()); DocumentPropertyComponent docProps = new DocumentPropertyComponentImpl(); project.merge(docProps, newProject); assertEquals(4, table1.columns().count()); assertEquals("TestTable1Column1,TestTable1Column2,TestTable1Column3,TestTable1Column4", table1.columns().map(Column::getName).collect(Collectors.joining(","))); }