Search in sources :

Example 36 with NodePath

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

the class DumpServiceImplTest method loadWithUpgrade.

@Test
public void loadWithUpgrade() throws Exception {
    final String dumpName = "testDump";
    createIncompatibleDump(dumpName);
    NodeHelper.runAsAdmin(() -> {
        this.dumpService.load(SystemLoadParams.create().dumpName(dumpName).upgrade(true).includeVersions(true).build());
        FileDumpReader reader = FileDumpReader.create(null, temporaryFolder, dumpName);
        final DumpMeta updatedMeta = reader.getDumpMeta();
        assertEquals(DumpConstants.MODEL_VERSION, updatedMeta.getModelVersion());
        final NodeId nodeId = NodeId.from("f0fb822c-092d-41f9-a961-f3811d81e55a");
        final NodeId fragmentNodeId = NodeId.from("7ee16649-85c6-4a76-8788-74be03be6c7a");
        final NodeId postNodeId = NodeId.from("1f798176-5868-411b-8093-242820c20620");
        final NodePath nodePath = NodePath.create("/content/mysite").build();
        final NodeVersionId draftNodeVersionId = NodeVersionId.from("f3765655d5f0c7c723887071b517808dae00556c");
        final NodeVersionId masterNodeVersionId = NodeVersionId.from("02e61f29a57309834d96bbf7838207ac456bbf5c");
        ContextBuilder.from(ContextAccessor.current()).repositoryId("com.enonic.cms.default").build().runWith(() -> {
            final Node draftNode = nodeService.getById(nodeId);
            assertNotNull(draftNode);
            assertEquals(draftNodeVersionId, draftNode.getNodeVersionId());
            assertEquals(nodePath, draftNode.path());
            assertEquals("2019-02-20T14:44:06.883Z", draftNode.getTimestamp().toString());
            final Node masterNode = ContextBuilder.from(ContextAccessor.current()).branch(Branch.from("master")).build().callWith(() -> nodeService.getById(nodeId));
            assertNotNull(masterNode);
            assertEquals(masterNodeVersionId, masterNode.getNodeVersionId());
            assertEquals(nodePath, masterNode.path());
            assertEquals("2018-11-23T11:14:21.662Z", masterNode.getTimestamp().toString());
            checkCommitUpgrade(nodeId);
            checkPageFlatteningUpgradePage(draftNode);
            final Node fragmentNode = nodeService.getById(fragmentNodeId);
            checkPageFlatteningUpgradeFragment(fragmentNode);
            checkRepositoryUpgrade(updatedMeta);
            final Node postNode = nodeService.getById(postNodeId);
            checkHtmlAreaUpgrade(draftNode, postNode);
            checkLanguageUpgrade(draftNode);
        });
    });
}
Also used : DumpMeta(com.enonic.xp.repo.impl.dump.model.DumpMeta) NodeVersionId(com.enonic.xp.node.NodeVersionId) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodePath(com.enonic.xp.node.NodePath) FileDumpReader(com.enonic.xp.repo.impl.dump.reader.FileDumpReader) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 37 with NodePath

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

the class MoveNodeCommandTest method move_with_children.

@Test
public void move_with_children() throws Exception {
    final Node parent = createNode(CreateNodeParams.create().name("parent").setNodeId(NodeId.from("parent")).parent(NodePath.ROOT).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build())).build());
    final Node child1 = createNode(CreateNodeParams.create().name("child1").parent(parent.path()).setNodeId(NodeId.from("child1")).inheritPermissions(true).build());
    final Node child1_1 = createNode(CreateNodeParams.create().name("child1_1").parent(child1.path()).setNodeId(NodeId.from("child1_1")).build());
    final Node child1_2 = createNode(CreateNodeParams.create().name("child1_2").parent(child1.path()).setNodeId(NodeId.from("child1_2")).build());
    final Node child1_1_1 = createNode(CreateNodeParams.create().name("child1_1_1").parent(child1_1.path()).setNodeId(NodeId.from("child1_1_1")).build());
    final Node newParent = createNode(CreateNodeParams.create().name("newParent").parent(NodePath.ROOT).setNodeId(NodeId.from("newParent")).build());
    assertEquals(1, getVersions(child1).getHits());
    assertEquals(1, getVersions(child1_1).getHits());
    assertEquals(1, getVersions(child1_2).getHits());
    assertNotNull(getNodeByPath(NodePath.create(child1.path(), child1_1.name().toString()).build()));
    final Node movedNode = MoveNodeCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(child1.id()).newParent(newParent.path()).build().execute().getMovedNodes().get(0).getNode();
    refresh();
    assertEquals(2, getVersions(child1).getHits());
    assertEquals(2, getVersions(child1_1).getHits());
    assertEquals(2, getVersions(child1_2).getHits());
    final NodePath previousChild1Path = child1_1.path();
    assertNull(getNodeByPath(previousChild1Path));
    final NodePath newChild1Path = NodePath.create(movedNode.path(), child1_1.name().toString()).build();
    assertNotNull(getNodeByPath(newChild1Path));
    final Node movedChild1 = getNodeById(child1_1.id());
    final Node movedChild2 = getNodeById(child1_2.id());
    final Node movedChild1_1 = getNodeById(child1_1_1.id());
    assertEquals(newParent.path(), movedNode.parentPath());
    assertEquals(movedNode.path(), movedChild1.parentPath());
    assertEquals(movedNode.path(), movedChild2.parentPath());
    assertEquals(movedChild1.path(), movedChild1_1.parentPath());
    assertEquals(false, movedNode.inheritsPermissions());
    assertEquals(child1.getPermissions(), movedNode.getPermissions());
}
Also used : Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 38 with NodePath

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

the class NodeEventListenerTest method node_renamed_event.

@Test
public void node_renamed_event() throws Exception {
    final NodeId nodeId = NodeId.from("node1");
    final NodePath nodePath = NodePath.create(NodePath.ROOT, "nodeName").build();
    final Node sourceNode = Node.create().id(nodeId).parentPath(nodePath.getParentPath()).name(nodePath.getLastElement().toString()).build();
    final Node movedNode = Node.create(sourceNode).parentPath(NodePath.create("newParent").build()).build();
    final Event localEvent = NodeEvents.renamed(sourceNode.path(), movedNode);
    nodeEventListener.onEvent(Event.create(localEvent).localOrigin(false).build());
    final NodeMovedParams nodeMovedParams = new NodeMovedParams(sourceNode.path(), movedNode.path(), sourceNode.id());
    Mockito.verify(nodeStorageService, Mockito.times(1)).handleNodeMoved(Mockito.eq(nodeMovedParams), Mockito.isA(InternalContext.class));
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) Event(com.enonic.xp.event.Event) NodeMovedParams(com.enonic.xp.repo.impl.storage.NodeMovedParams) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 39 with NodePath

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

the class NodeStorageServiceImplTest method testGetNode_ByPathBranchNotFound.

@Test
public void testGetNode_ByPathBranchNotFound() {
    when(branchService.get(any(NodePath.class), any(InternalContext.class))).thenReturn(null);
    final Node result = instance.getNode(nodePath, nodeVersionId, context);
    assertNull(result);
    verify(branchService, times(1)).get(any(NodePath.class), any(InternalContext.class));
    verifyNoMoreInteractions(branchService);
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 40 with NodePath

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

the class NodeStorageServiceImplTest method testGetNode_ByPath.

@Test
public void testGetNode_ByPath() {
    final NodeBranchEntry nodeBranchEntry = NodeBranchEntry.create().nodeId(nodeId).nodePath(nodePath).nodeState(NodeState.DEFAULT).build();
    final NodeVersionMetadata nodeVersionMetadata = NodeVersionMetadata.create().nodeVersionId(nodeVersionId).nodeVersionKey(versionKey).nodePath(nodePath).build();
    final NodeVersion nodeVersion = NodeVersion.create().permissions(AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()).build();
    when(branchService.get(any(NodePath.class), any(InternalContext.class))).thenReturn(nodeBranchEntry);
    when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(nodeVersionMetadata);
    when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(nodeVersion);
    final Node result = instance.getNode(nodePath, nodeVersionId, context);
    assertNotNull(result);
    verify(branchService, times(1)).get(any(NodePath.class), any(InternalContext.class));
    verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
    verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
    verifyNoMoreInteractions(branchService, versionService, nodeVersionService);
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Aggregations

NodePath (com.enonic.xp.node.NodePath)54 Node (com.enonic.xp.node.Node)27 Test (org.junit.jupiter.api.Test)20 NodeId (com.enonic.xp.node.NodeId)15 InternalContext (com.enonic.xp.repo.impl.InternalContext)12 Content (com.enonic.xp.content.Content)7 Event (com.enonic.xp.event.Event)7 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)4 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 ChildOrder (com.enonic.xp.index.ChildOrder)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 ContentId (com.enonic.xp.content.ContentId)2 ContentPath (com.enonic.xp.content.ContentPath)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 Context (com.enonic.xp.context.Context)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)2 NodeVersion (com.enonic.xp.node.NodeVersion)2