Search in sources :

Example 21 with NodeComparison

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

the class ImportNodeCommandTest method created_nodes_with_id_and_timestamp_should_be_equal.

@Test
public void created_nodes_with_id_and_timestamp_should_be_equal() throws Exception {
    ctxDefault().callWith(() -> importNode(Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).timestamp(Instant.parse("2014-01-01T10:00:00Z")).build()));
    ctxOther().callWith(() -> importNode(Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).timestamp(Instant.parse("2014-01-01T10:00:00Z")).build()));
    final NodeComparison comparison = CompareNodeCommand.create().nodeId(NodeId.from("abc")).target(WS_OTHER).storageService(this.storageService).build().execute();
    assertEquals(CompareStatus.EQUAL, comparison.getCompareStatus());
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 22 with NodeComparison

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

the class UndoPendingDeleteContentCommand method ensureValidParent.

private void ensureValidParent(final NodeComparison nodeComparison) {
    final NodePath parentPath = nodeComparison.getSourcePath().getParentPath();
    if (ContentNodeHelper.translateNodePathToContentPath(parentPath).isRoot()) {
        return;
    }
    final Node parentNode = this.nodeService.getByPath(parentPath);
    if (parentNode == null) {
        throw new IllegalArgumentException("Parent with path [" + parentPath + "] does not exists");
    }
    final NodeComparison parentState = this.nodeService.compare(parentNode.id(), this.params.getTarget());
    if (CompareStatus.PENDING_DELETE == parentState.getCompareStatus()) {
        removePendingDeleteState(parentState);
    }
    ensureValidParent(parentState);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 23 with NodeComparison

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

the class PushNodeHandlerTest method testExample2.

@Test
public void testExample2() {
    Mockito.when(nodeService.resolveSyncWork(Mockito.isA(SyncWorkResolverParams.class))).thenReturn(ResolveSyncWorkResult.create().add(new NodeComparison(createEntry("a"), createEntry("a"), CompareStatus.NEW)).add(new NodeComparison(createEntry("b"), createEntry("b"), CompareStatus.NEW)).add(new NodeComparison(createEntry("c"), createEntry("c"), CompareStatus.NEW)).build());
    Mockito.when(nodeService.push(Mockito.isA(NodeIds.class), Mockito.eq(Branch.from("otherBranch")))).thenReturn(PushNodesResult.create().addSuccess(createEntry("a")).addSuccess(createEntry("b")).addSuccess(createEntry("c")).addFailed(createEntry("d"), PushNodesResult.Reason.ACCESS_DENIED).build());
    runScript("/lib/xp/examples/node/push-2.js");
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) NodeIds(com.enonic.xp.node.NodeIds) SyncWorkResolverParams(com.enonic.xp.node.SyncWorkResolverParams) Test(org.junit.jupiter.api.Test)

Example 24 with NodeComparison

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

the class ResolveSyncWorkResultMapperTest method full.

@Test
public void full() throws Exception {
    final ResolveSyncWorkResult result = ResolveSyncWorkResult.create().add(new NodeComparison(createEntry("a"), createEntry("a"), CompareStatus.NEW)).add(new NodeComparison(createEntry("b"), createEntry("b"), CompareStatus.MOVED)).add(new NodeComparison(createEntry("c"), createEntry("c"), CompareStatus.NEWER)).build();
    final JsonMapGenerator jsonGenerator = new JsonMapGenerator();
    new ResolveSyncWorkResultMapper(result).serialize(jsonGenerator);
    assertJson("resolveSyncWork/full.json", jsonGenerator);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) JsonMapGenerator(com.enonic.xp.script.serializer.JsonMapGenerator) ResolveSyncWorkResult(com.enonic.xp.node.ResolveSyncWorkResult) Test(org.junit.jupiter.api.Test)

Example 25 with NodeComparison

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

the class DiffBranchesHandlerTest method testExample1.

@Test
public void testExample1() {
    Mockito.when(nodeService.resolveSyncWork(Mockito.isA(SyncWorkResolverParams.class))).thenReturn(ResolveSyncWorkResult.create().add(new NodeComparison(createEntry("a"), createEntry("a"), CompareStatus.NEW)).add(new NodeComparison(createEntry("b"), createEntry("b"), CompareStatus.MOVED)).add(new NodeComparison(createEntry("c"), createEntry("c"), CompareStatus.OLDER)).build());
    runScript("/lib/xp/examples/node/diff-1.js");
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) SyncWorkResolverParams(com.enonic.xp.node.SyncWorkResolverParams) Test(org.junit.jupiter.api.Test)

Aggregations

NodeComparison (com.enonic.xp.node.NodeComparison)27 Test (org.junit.jupiter.api.Test)14 Node (com.enonic.xp.node.Node)9 NodeId (com.enonic.xp.node.NodeId)4 NodeIds (com.enonic.xp.node.NodeIds)4 SyncWorkResolverParams (com.enonic.xp.node.SyncWorkResolverParams)4 Context (com.enonic.xp.context.Context)3 NodeComparisons (com.enonic.xp.node.NodeComparisons)3 InternalContext (com.enonic.xp.repo.impl.InternalContext)3 CompareStatus (com.enonic.xp.content.CompareStatus)2 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)2 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)2 NodePaths (com.enonic.xp.node.NodePaths)2 Branch (com.enonic.xp.branch.Branch)1 ContentId (com.enonic.xp.content.ContentId)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 NodePath (com.enonic.xp.node.NodePath)1 PushNodeEntries (com.enonic.xp.node.PushNodeEntries)1 ResolveSyncWorkResult (com.enonic.xp.node.ResolveSyncWorkResult)1