use of com.enonic.xp.json.JsonToPropertyTreeTranslator in project xp by enonic.
the class FlattenedPageDataUpgraderTest method test.
private void test(final String oldJsonFile, final String newJsonFile) throws Exception {
final JsonNode oldPageComponents = loadJson(oldJsonFile);
final JsonNode newPageComponents = loadJson(newJsonFile);
final PropertyTree oldData = new JsonToPropertyTreeTranslator().translate(oldPageComponents);
final PropertyTree newData = new JsonToPropertyTreeTranslator().translate(newPageComponents);
final HashMap<String, String> templateControllerMap = new HashMap<>();
templateControllerMap.put("templateId", "com.enonic.app.features:main");
FlattenedPageDataUpgrader.create().templateControllerMap(templateControllerMap).build().upgrade(oldData);
// using string comparison because PropertyTree entries are same but might have different value type
assertEquals(newData.toString(), oldData.toString());
}
use of com.enonic.xp.json.JsonToPropertyTreeTranslator in project xp by enonic.
the class FlattenedPageIndexUpgraderTest method test.
private void test(final String dataFile, final String oldIndexDocumentFile, final String newIndexDocumentFile) throws Exception {
final JsonNode pageComponents = loadJson(dataFile);
final PropertyTree data = new JsonToPropertyTreeTranslator().translate(pageComponents);
final List<PropertySet> components = Lists.newArrayList(data.getSets("components"));
if (components.size() == 0) {
throw new RuntimeException("page components is empty");
}
final String descriptorKeyStr = data.getString(PropertyPath.from("components.page.descriptor"));
if (descriptorKeyStr == null) {
throw new RuntimeException("page descriptorKey is null");
}
final DescriptorKey descriptorKey = DescriptorKey.from(descriptorKeyStr);
final PatternIndexConfigDocument oldDocument = getIndexConfigDocument(oldIndexDocumentFile);
final PatternIndexConfigDocument newDocument = new FlattenedPageIndexUpgrader(descriptorKey, components).upgrade(oldDocument);
assertEquals(getIndexConfigDocument(newIndexDocumentFile), newDocument);
}
Aggregations