Search in sources :

Example 16 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class FindNodesByQueryCommandTest_compare method compare_eq_numeric.

@Test
public void compare_eq_numeric() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addDouble("myDouble", 2.0);
    final Node node1 = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data).build());
    final PropertyTree data2 = new PropertyTree();
    data2.addString("myDouble", "2.0");
    createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
    final NodeQuery query = NodeQuery.create().query(QueryExpr.from(CompareExpr.eq(FieldExpr.from("myDouble"), ValueExpr.number(2.0)))).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getNodeIds().getSize());
    assertTrue(result.getNodeIds().contains(node1.id()));
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Example 17 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class FindNodesByQueryCommandTest_compare method compare_gt.

@Test
public void compare_gt() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.setDouble("my-value", 5.5);
    createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data).build());
    final PropertyTree data2 = new PropertyTree();
    data2.setDouble("my-value", 10.0);
    final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
    final NodeQuery query = NodeQuery.create().query(QueryExpr.from(CompareExpr.gt(FieldExpr.from(IndexPath.from("my-value")), ValueExpr.number(7)))).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getNodeIds().getSize());
    assertTrue(result.getNodeIds().contains(node2.id()));
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Example 18 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class FindNodesByQueryCommandTest_func_range method instant_values.

@Test
public void instant_values() throws Exception {
    final PropertyTree node1 = new PropertyTree();
    node1.addInstant("publishFrom", Instant.parse("2015-08-01T10:00:00Z"));
    final PropertyTree node2 = new PropertyTree();
    node2.addInstant("publishFrom", Instant.parse("2015-08-01T11:00:00Z"));
    createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("node-1").data(node1).build());
    createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("node-2").data(node2).build());
    queryAndAssert(1, "range('publishfrom', instant('2015-08-01T09:00:00Z'), instant('2015-08-01T11:00:00Z') )");
    queryAndAssert(2, "range('publishfrom', instant('2015-08-01T09:00:00Z'), instant('2015-08-01T11:00:00Z'), 'false', 'true' )");
    queryAndAssert(2, "range('publishfrom', instant('2015-08-01T09:00:00Z'), instant('2015-08-01T12:00:00Z') )");
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 19 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class FindNodesByQueryCommandTest_func_range method empty_to_instant.

@Test
public void empty_to_instant() throws Exception {
    final PropertyTree node1 = new PropertyTree();
    node1.addInstant("publishFrom", Instant.parse("2015-08-01T10:00:00Z"));
    final PropertyTree node2 = new PropertyTree();
    node2.addInstant("publishFrom", Instant.parse("2015-08-01T11:00:00Z"));
    createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("node-1").data(node1).build());
    createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("node-2").data(node2).build());
    queryAndAssert(2, "range('publishfrom', instant('2015-08-01T09:00:00Z'), '')");
    queryAndAssert(2, "range('publishfrom', '', instant('2017-08-01T09:00:00Z'))");
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 20 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class FindNodesByQueryCommandTest_func_range method empty_to_string.

@Test
public void empty_to_string() throws Exception {
    final PropertyTree node1 = new PropertyTree();
    node1.addString("myValue", "a");
    final PropertyTree node2 = new PropertyTree();
    node2.addString("myValue", "b");
    final PropertyTree node3 = new PropertyTree();
    node3.addString("myValue", "c");
    createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("node-1").data(node1).build());
    createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("node-2").data(node2).build());
    createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("node-3").data(node3).build());
    queryAndAssert(3, "range('myValue', 'a', '', 'true', 'false')");
    queryAndAssert(2, "range('myValue', 'b', '', 'true', 'false')");
    queryAndAssert(1, "range('myValue', 'c', '', 'true', 'false')");
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)660 Test (org.junit.jupiter.api.Test)405 PropertySet (com.enonic.xp.data.PropertySet)150 Content (com.enonic.xp.content.Content)126 Node (com.enonic.xp.node.Node)112 CreateContentParams (com.enonic.xp.content.CreateContentParams)64 Form (com.enonic.xp.form.Form)37 Page (com.enonic.xp.page.Page)32 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)31 DescriptorKey (com.enonic.xp.page.DescriptorKey)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)30 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)28 PrincipalKey (com.enonic.xp.security.PrincipalKey)28 BinaryReference (com.enonic.xp.util.BinaryReference)28 Property (com.enonic.xp.data.Property)26 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)24 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)23 ByteSource (com.google.common.io.ByteSource)22 ExtraData (com.enonic.xp.content.ExtraData)21 Instant (java.time.Instant)21