AttributeRename implements DataMigration { public void migrate(List<DataJsonNode> dataJsonNodes) { dataJsonNodes.stream().filter(dataJsonNode -> dataJsonNode.match(dataClassNameFullQualified)).forEach(dataJsonNode -> { dataJsonNode.renameAttribute(previousAttributeName,newAttributeName); }); } AttributeRename(Class<F> dataClass, String previousAttributeName, Function<F, Attribute<?,?>> attributeNameProvider); boolean canMigrate(DataStorageMetadataDictionary dataStorageMetadataDictionary); void migrate(List<DataJsonNode> dataJsonNodes); void updateDataStorageMetadataDictionary(DataStorageMetadataDictionary dataStorageMetadataDictionary);  }
@Test public void test_rename_order_class_rename_1(){ ExampleDataAPrevious exampleDataAPrevious = new ExampleDataAPrevious(); exampleDataAPrevious.garbage.set("123"); exampleDataAPrevious.internal().finalise(); MigrationManager<ExampleDataA> dataMigrationManager = new MigrationManager<>(ExampleDataA.class, ObjectMapperBuilder.build(),(root, oldDataStorageMetadataDictionary) -> { }); dataMigrationManager.renameClass(ExampleDataAPrevious.class.getName(),ExampleDataA.class); dataMigrationManager.renameAttribute(ExampleDataA.class, "garbage", exampleDataA -> exampleDataA.stringAttribute); ExampleDataA exampleDataA = dataMigrationManager.migrate(ObjectMapperBuilder.build().writeValueAsTree(exampleDataAPrevious),exampleDataAPrevious.internal().createDataStorageMetadataDictionaryFromRoot()); Assertions.assertEquals("123",exampleDataA.stringAttribute.get()); }
@Test public void test_rename_order_class_rename_2(){ ExampleDataAPrevious exampleDataAPrevious = new ExampleDataAPrevious(); exampleDataAPrevious.garbage.set("123"); exampleDataAPrevious.internal().finalise(); MigrationManager<ExampleDataA> dataMigrationManager = new MigrationManager<>(ExampleDataA.class, ObjectMapperBuilder.build(),(root, oldDataStorageMetadataDictionary) -> {}); dataMigrationManager.renameAttribute(ExampleDataA.class, "garbage", exampleDataA -> exampleDataA.stringAttribute); dataMigrationManager.renameClass(ExampleDataAPrevious.class.getName(),ExampleDataA.class); ExampleDataA exampleDataA = dataMigrationManager.migrate(ObjectMapperBuilder.build().writeValueAsTree(exampleDataAPrevious),exampleDataAPrevious.internal().createDataStorageMetadataDictionaryFromRoot()); Assertions.assertEquals("123",exampleDataA.stringAttribute.get()); }