Search in sources :

Example 6 with EditableNode

use of com.enonic.xp.node.EditableNode in project xp by enonic.

the class ModifyNodeHandlerTest method getEditedNode.

private EditableNode getEditedNode(final Node node) {
    final NodeEditor editor = updateCaptor.getValue().getEditor();
    assertNotNull(editor);
    final EditableNode editableNode = new EditableNode(node);
    editor.edit(editableNode);
    return editableNode;
}
Also used : NodeEditor(com.enonic.xp.node.NodeEditor) EditableNode(com.enonic.xp.node.EditableNode)

Example 7 with EditableNode

use of com.enonic.xp.node.EditableNode in project xp by enonic.

the class ModifyNodeExecutorTest method update_permissions.

@Test
public void update_permissions() throws Exception {
    final Node originalNode = Node.create().name("myNode").parentPath(NodePath.ROOT).permissions(AccessControlList.empty()).build();
    final EditableNode editableNode = new EditableNode(originalNode);
    final PropertyTree updateScript = new PropertyTree();
    final PropertySet propertySet = new PropertySet();
    propertySet.setString("principal", "role:newRole");
    propertySet.addString("allow", "READ");
    propertySet.addString("allow", "MODIFY");
    updateScript.addSet("_permissions", propertySet);
    ModifyNodeExecutor.create().editableNode(editableNode).propertyTree(updateScript).build().execute();
    final AccessControlList newPermissions = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("role:newRole")).allow(Permission.READ, Permission.MODIFY).build()).build();
    assertEquals(newPermissions, editableNode.permissions);
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Example 8 with EditableNode

use of com.enonic.xp.node.EditableNode in project xp by enonic.

the class ModifyNodeExecutorTest method modify_user_properties.

@Test
public void modify_user_properties() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.setString("notChanged", "originalValue");
    data.setString("myString", "originalValue");
    final PropertySet mySet = data.addSet("mySet");
    mySet.setGeoPoint("myGeoPoint", new GeoPoint(30, -30));
    final Node originalNode = Node.create().name("myNode").parentPath(NodePath.ROOT).data(data).build();
    final EditableNode editableNode = new EditableNode(originalNode);
    final PropertyTree updateScript = createUpdateScript();
    ModifyNodeExecutor.create().editableNode(editableNode).propertyTree(updateScript).build().execute();
    assertEquals(new GeoPoint(0, 0), editableNode.data.getGeoPoint("mySet.myGeoPoint"));
    assertEquals("updatedValue", editableNode.data.getString("myString"));
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) PropertySet(com.enonic.xp.data.PropertySet) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Example 9 with EditableNode

use of com.enonic.xp.node.EditableNode in project xp by enonic.

the class ModifyNodeExecutorTest method remove_not_in_new_tree.

@Test
public void remove_not_in_new_tree() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.setString("toBeRemoved", "removeMe");
    final Node originalNode = Node.create().name("myNode").parentPath(NodePath.ROOT).data(data).build();
    final EditableNode editableNode = new EditableNode(originalNode);
    final PropertyTree updateScript = new PropertyTree();
    ModifyNodeExecutor.create().editableNode(editableNode).propertyTree(updateScript).build().execute();
    assertNull(editableNode.data.getString("toBeRemoved"));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Aggregations

EditableNode (com.enonic.xp.node.EditableNode)9 Node (com.enonic.xp.node.Node)8 Test (org.junit.jupiter.api.Test)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 PropertySet (com.enonic.xp.data.PropertySet)3 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 GeoPoint (com.enonic.xp.util.GeoPoint)2 IndexConfigDocument (com.enonic.xp.index.IndexConfigDocument)1 AttachedBinaries (com.enonic.xp.node.AttachedBinaries)1 NodeEditor (com.enonic.xp.node.NodeEditor)1 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)1 TaskId (com.enonic.xp.task.TaskId)1 Instant (java.time.Instant)1