Search in sources :

Example 6 with PushNodesResult

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

the class PushNodesCommandTest method push_rename_push_test.

@Test
public void push_rename_push_test() throws Exception {
    PushNodesResult result;
    // Creates and pushes a content
    final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build());
    result = pushNodes(NodeIds.from(node.id()), WS_OTHER);
    assertEquals(1, result.getSuccessful().getSize());
    assertNotNull(getNodeByPath(NodePath.create("/my-node").build()));
    assertNotNull(getNodeByPathInOther(NodePath.create("/my-node").build()));
    // Renames the content
    renameNode(node, "my-node-renamed");
    assertNull(getNodeByPath(NodePath.create("/my-node").build()));
    assertNotNull(getNodeByPath(NodePath.create("/my-node-renamed").build()));
    assertNotNull(getNodeByPathInOther(NodePath.create("/my-node").build()));
    // Pushed the renames content
    result = pushNodes(NodeIds.from(node.id()), WS_OTHER);
    assertEquals(1, result.getSuccessful().getSize());
    assertNull(getNodeByPathInOther(NodePath.create("/my-node").build()));
    assertNotNull(getNodeByPathInOther(NodePath.create("/my-node-renamed").build()));
}
Also used : Node(com.enonic.xp.node.Node) PushNodesResult(com.enonic.xp.node.PushNodesResult) Test(org.junit.jupiter.api.Test)

Example 7 with PushNodesResult

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

the class PushNodesCommandTest method push_child_fail_if_parent_does_not_exists.

@Test
public void push_child_fail_if_parent_does_not_exists() throws Exception {
    final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build());
    final Node child = createNode(CreateNodeParams.create().parent(node.path()).name("my-child").build());
    final PushNodesResult result = pushNodes(NodeIds.from(child.id()), WS_OTHER);
    assertEquals(1, result.getFailed().size());
    assertEquals(PushNodesResult.Reason.PARENT_NOT_FOUND, result.getFailed().iterator().next().getReason());
}
Also used : Node(com.enonic.xp.node.Node) PushNodesResult(com.enonic.xp.node.PushNodesResult) Test(org.junit.jupiter.api.Test)

Example 8 with PushNodesResult

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

the class PushNodesCommandPerformanceTest method testReferencePerformance.

@Disabled
@Test
public void testReferencePerformance() throws Exception {
    final Node rootNode = createNode(CreateNodeParams.create().name("rootNode").parent(NodePath.ROOT).build(), false);
    createNodes(rootNode, 20, 3, 1);
    refresh();
    final ResolveSyncWorkResult syncWork = ResolveSyncWorkCommand.create().nodeId(rootNode.id()).target(WS_OTHER).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    final Stopwatch started = Stopwatch.createStarted();
    final PushNodesResult result = PushNodesCommand.create().ids(syncWork.getNodeComparisons().getNodeIds()).target(WS_OTHER).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    started.stop();
    final long elapsed = started.elapsed(TimeUnit.SECONDS);
    final int number = result.getSuccessful().getSize();
    System.out.println("Pushed : " + number + " in " + started + ", " + (elapsed == 0 ? "n/a" : (number / elapsed) + "/s"));
}
Also used : Node(com.enonic.xp.node.Node) Stopwatch(com.google.common.base.Stopwatch) PushNodesResult(com.enonic.xp.node.PushNodesResult) ResolveSyncWorkResult(com.enonic.xp.node.ResolveSyncWorkResult) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 9 with PushNodesResult

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

the class PushNodesCommandTest method push_child_missing_permission.

@Test
public void push_child_missing_permission() throws Exception {
    final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build());
    final Node child = createNode(CreateNodeParams.create().parent(node.path()).name("my-child").permissions(AccessControlList.create().add(AccessControlEntry.create().allowAll().deny(Permission.PUBLISH).principal(TEST_DEFAULT_USER.getKey()).build()).build()).build());
    final PushNodesResult result = pushNodes(NodeIds.from(node.id(), child.id()), WS_OTHER);
    assertEquals(1, result.getSuccessful().getSize());
    assertEquals(1, result.getFailed().size());
    assertEquals(PushNodesResult.Reason.ACCESS_DENIED, result.getFailed().iterator().next().getReason());
}
Also used : Node(com.enonic.xp.node.Node) PushNodesResult(com.enonic.xp.node.PushNodesResult) Test(org.junit.jupiter.api.Test)

Example 10 with PushNodesResult

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

the class PushNodesCommandTest method push_fail_if_node_already_exists.

@Test
public void push_fail_if_node_already_exists() throws Exception {
    final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build());
    ctxOther().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build()));
    final PushNodesResult result = pushNodes(NodeIds.from(node.id()), WS_OTHER);
    assertEquals(1, result.getFailed().size());
    assertEquals(0, result.getSuccessful().getSize());
    assertEquals(PushNodesResult.Reason.ALREADY_EXIST, result.getFailed().iterator().next().getReason());
}
Also used : Node(com.enonic.xp.node.Node) PushNodesResult(com.enonic.xp.node.PushNodesResult) Test(org.junit.jupiter.api.Test)

Aggregations

PushNodesResult (com.enonic.xp.node.PushNodesResult)17 Test (org.junit.jupiter.api.Test)15 Node (com.enonic.xp.node.Node)11 JsonMapGenerator (com.enonic.xp.script.serializer.JsonMapGenerator)4 PushNodesResultMapper (com.enonic.xp.lib.node.mapper.PushNodesResultMapper)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 NodeIds (com.enonic.xp.node.NodeIds)1 ResolveSyncWorkResult (com.enonic.xp.node.ResolveSyncWorkResult)1 Stopwatch (com.google.common.base.Stopwatch)1 Disabled (org.junit.jupiter.api.Disabled)1