use of com.enonic.xp.data.PropertyTree 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);
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class HtmlAreaNodeDataUpgraderTest method testUpgrade.
@Test
public void testUpgrade() throws IOException {
final PropertyTree data = new PropertyTree();
data.setString("data.htmlarea", readTestResource("htmlarea-source.xml"));
final NodeVersion nodeVersion = NodeVersion.create().nodeType(ContentConstants.CONTENT_NODE_COLLECTION).data(data).build();
final PatternIndexConfigDocument indexConfigDocument = createIndexConfigDocument();
final DumpUpgradeStepResult.Builder result = DumpUpgradeStepResult.create();
final boolean upgraded = htmlAreaNodeDataUpgrader.upgrade(nodeVersion, indexConfigDocument, result);
assertTrue(upgraded);
final PropertyTree upgradedData = nodeVersion.getData();
final Collection<Reference> upgradedProcessedReferences = (Collection<Reference>) upgradedData.getReferences("processedReferences");
assertEquals(5, upgradedProcessedReferences.size());
final List<Reference> expectedReferences = Arrays.stream(new String[] { "e1f57280-d672-4cd8-b674-98e26e5b69ae", "be1ca151-cf61-4a54-9ea4-c8d01ce83e0e", "81b1e3cd-575f-4565-a618-3c85d56224f6", "43d54e23-d8ce-4058-befb-777abe1a0d9f", "32169e70-49e1-444c-a6ac-d38f22438134" }).map(Reference::from).collect(Collectors.toList());
assertTrue(expectedReferences.containsAll(upgradedProcessedReferences));
assertEquals(readTestResource("htmlarea-expected.xml"), upgradedData.getString("data.htmlarea"));
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class SortBuilderFactoryTest method createDsl.
@Test
public void createDsl() {
final PropertyTree geoExpression = new PropertyTree();
geoExpression.addString("type", "geoDistance");
geoExpression.addString("field", "myGeoPoint");
geoExpression.addString("unit", "ft");
geoExpression.addString("direction", "ASC");
final PropertySet location1 = geoExpression.addSet("location");
location1.addDouble("lat", 2.2);
location1.addDouble("lon", 3.3);
final PropertyTree geoExpressionWithoutOptional = new PropertyTree();
geoExpressionWithoutOptional.addString("type", "geoDistance");
geoExpressionWithoutOptional.addString("field", "myGeoPoint");
final PropertySet location2 = geoExpressionWithoutOptional.addSet("location");
location2.addDouble("lat", 2D);
location2.addDouble("lon", 3D);
final PropertyTree fieldExpressionWithDirection = new PropertyTree();
fieldExpressionWithDirection.addString("field", "myField");
fieldExpressionWithDirection.addString("direction", "DESC");
final PropertyTree fieldExpressionWithoutDirection = new PropertyTree();
fieldExpressionWithoutDirection.addString("field", "_name");
final DslOrderExpr geoOrderExpr = DslOrderExpr.from(geoExpression);
final DslOrderExpr geoOrderWithoutOptionalExpr = DslOrderExpr.from(geoExpressionWithoutOptional);
final DslOrderExpr fieldWithDirectionOrderExpr = DslOrderExpr.from(fieldExpressionWithDirection);
final DslOrderExpr fieldWithoutDirectionOrderExpr = DslOrderExpr.from(fieldExpressionWithoutDirection);
final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(List.of(geoOrderExpr, geoOrderWithoutOptionalExpr, fieldWithDirectionOrderExpr, fieldWithoutDirectionOrderExpr));
assertEquals(4, sortBuilders.size());
assertTrue(sortBuilders.get(0) instanceof GeoDistanceSortBuilder);
assertTrue(sortBuilders.get(1) instanceof GeoDistanceSortBuilder);
assertTrue(sortBuilders.get(2) instanceof FieldSortBuilder);
assertTrue(sortBuilders.get(3) instanceof FieldSortBuilder);
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class SortBuilderFactoryTest method createDslInvalidFunction.
@Test
public void createDslInvalidFunction() {
final PropertyTree geoExpression = new PropertyTree();
geoExpression.addString("type", "unknownFunction");
geoExpression.addString("field", "myGeoPoint");
final DslOrderExpr unknownOrderExpr = DslOrderExpr.from(geoExpression);
assertThrows(IllegalArgumentException.class, () -> new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(List.of(unknownOrderExpr)));
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class NodeStoreDocumentFactoryTest method references.
@Test
public void references() throws Exception {
final PropertyTree data = new PropertyTree();
data.addReference("myRef", new Reference(NodeId.from("otherNode")));
final Node node = Node.create().id(NodeId.from("myNodeId")).parentPath(NodePath.ROOT).name("myNode").data(data).build();
final Collection<IndexDocument> indexDocuments = NodeStoreDocumentFactory.createBuilder().node(node).branch(Branch.from("myBranch")).repositoryId(RepositoryId.from("my-repo")).build().create();
assertEquals(1, indexDocuments.size());
final IndexDocument indexDocument = indexDocuments.iterator().next();
final IndexItems indexItems = indexDocument.getIndexItems();
final Collection<IndexValue> referenceValues = indexItems.get(NodeIndexPath.REFERENCE.getPath());
assertEquals(1, referenceValues.size());
final IndexValue next = referenceValues.iterator().next();
assertTrue(next instanceof IndexValueString);
final IndexValueString referenceValue = (IndexValueString) next;
assertEquals("otherNode", referenceValue.getValue());
}
Aggregations