CKeyspaceDefinition OldKeyspaceDefinition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, this.getClass().getClassLoader(), "CKeyspaceTestData.js");
CKeyspaceDefinition NewKeyspaceDefinition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, this.getClass().getClassLoader(), "CKeyspaceTestData.js");
CDefinition NewObjectDefinition = JsonUtil.objectFromJsonResource(CDefinition.class, this.getClass().getClassLoader(), "MigrationTestCDefinition.js");
NewKeyspaceDefinition.getDefinitions().put(NewObjectDefinition.getName(),NewObjectDefinition);
CKeyspaceDefinitionMigrator subject = new CKeyspaceDefinitionMigrator(OldKeyspaceDefinition, NewKeyspaceDefinition);
assertTrue(subject.isMigratable());
//now try adding an field (which is now supported)
NewKeyspaceDefinition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, this.getClass().getClassLoader(), "CKeyspaceTestData.js");
CField newField = new CField("newfield", CField.CDataType.VARCHAR);
NewKeyspaceDefinition.getDefinitions().get("testtype").getFields().put(newField.getName(),newField);
subject = new CKeyspaceDefinitionMigrator(OldKeyspaceDefinition, NewKeyspaceDefinition);
assertTrue(subject.isMigratable());
//now try changing the type of a field (which is not supported)
NewKeyspaceDefinition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, this.getClass().getClassLoader(), "CKeyspaceTestData.js");
CField changedField = new CField("filtered", CField.CDataType.VARCHAR);
NewKeyspaceDefinition.getDefinitions().get("testtype").getFields().put(changedField.getName(),changedField);
subject = new CKeyspaceDefinitionMigrator(OldKeyspaceDefinition, NewKeyspaceDefinition);
assertFalse(subject.isMigratable());
//now change it back and it should work
changedField = new CField("filtered", CField.CDataType.INT);
NewKeyspaceDefinition.getDefinitions().get("testtype").getFields().put(changedField.getName(),changedField);
subject = new CKeyspaceDefinitionMigrator(OldKeyspaceDefinition, NewKeyspaceDefinition);
assertTrue(subject.isMigratable());
//now add an ID field which is not supported (because you can never change the type of the id)
//now try adding an field (which is now supported)
NewKeyspaceDefinition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, this.getClass().getClassLoader(), "CKeyspaceTestData.js");
newField = new CField("id", CField.CDataType.VARCHAR);
NewKeyspaceDefinition.getDefinitions().get("testtype").getFields().put(newField.getName(),newField);
subject = new CKeyspaceDefinitionMigrator(OldKeyspaceDefinition, NewKeyspaceDefinition);
assertFalse(subject.isMigratable());
}