Search in sources :

Example 6 with ImportNodeResult

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

the class ImportNodeCommandTest method import_existing_node.

@Test
public void import_existing_node() {
    PropertyTree data = new PropertyTree();
    data.addString("name", "value");
    final Node importNode = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(data).build();
    importNode(importNode);
    final Node abc = getNodeById(NodeId.from("abc"));
    assertNotNull(abc);
    assertEquals(data, abc.data());
    PropertyTree data2 = new PropertyTree();
    data2.addString("name", "valueUpdated");
    final Node importNode2 = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(data2).build();
    final ImportNodeResult importNodeResult = importNode(importNode2);
    final Node abc2 = getNodeById(NodeId.from("abc"));
    assertNotNull(abc2);
    assertEquals(data2, abc2.data());
    assertEquals(importNodeResult.getNode().data(), abc2.data());
    assertTrue(importNodeResult.isPreExisting());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) Test(org.junit.jupiter.api.Test)

Example 7 with ImportNodeResult

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

the class ImportNodeCommandTest method permissions_on_root_create.

@Test
public void permissions_on_root_create() throws Exception {
    final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allowAll().deny(Permission.DELETE).build()).add(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.DELETE).build()).build();
    final Node rootNode = Node.create().id(Node.ROOT_UUID).name("rootNode").parentPath(NodePath.ROOT).data(new PropertyTree()).permissions(aclList).build();
    this.nodeRepositoryService.create(CreateRepositoryParams.create().repositoryId(RepositoryId.from("test")).build());
    final ImportNodeResult importNodeResult = ContextBuilder.from(ContextAccessor.current()).repositoryId("test").build().callWith(() -> importNode(rootNode, false, true));
    assertEquals(aclList, importNodeResult.getNode().getPermissions());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) Test(org.junit.jupiter.api.Test)

Example 8 with ImportNodeResult

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

the class ImportNodeCommandTest method keep_permissions_on_create.

@Test
public void keep_permissions_on_create() throws Exception {
    final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allowAll().deny(Permission.DELETE).build()).add(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.DELETE).build()).build();
    final Node importNode = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).permissions(aclList).build();
    final ImportNodeResult importNodeResult = importNode(importNode);
    final Node abc = getNodeById(NodeId.from("abc"));
    assertNotNull(abc);
    assertEquals(aclList, abc.getPermissions());
    assertEquals(importNodeResult.getNode().getPermissions(), abc.getPermissions());
    assertFalse(importNodeResult.isPreExisting());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) Test(org.junit.jupiter.api.Test)

Aggregations

ImportNodeResult (com.enonic.xp.node.ImportNodeResult)8 Node (com.enonic.xp.node.Node)7 PropertyTree (com.enonic.xp.data.PropertyTree)5 Test (org.junit.jupiter.api.Test)5 AccessControlList (com.enonic.xp.security.acl.AccessControlList)3 XmlNodeParser (com.enonic.xp.core.impl.export.xml.XmlNodeParser)1 ImportNodeException (com.enonic.xp.export.ImportNodeException)1 ImportNodeParams (com.enonic.xp.node.ImportNodeParams)1 NodePath (com.enonic.xp.node.NodePath)1 VirtualFile (com.enonic.xp.vfs.VirtualFile)1 XmlException (com.enonic.xp.xml.XmlException)1 CharSource (com.google.common.io.CharSource)1