Search in sources :

Example 11 with NodeComparison

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

the class CompareNodeCommandTest method status_moved_source.

@Test
public void status_moved_source() throws Exception {
    ctxDefault().callWith(this::createDefaultRootNode);
    final Node createdNode = ctxDefault().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build()));
    final Node mySecondNode = ctxDefault().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-second-node").build()));
    ctxDefault().runWith(() -> doPushNode(WS_OTHER, createdNode));
    refresh();
    ctxDefault().runWith(() -> MoveNodeCommand.create().id(createdNode.id()).newParent(mySecondNode.path()).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute());
    final NodeComparison comparison = ctxDefault().callWith(() -> doCompare(WS_OTHER, createdNode));
    assertEquals(CompareStatus.MOVED, comparison.getCompareStatus());
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 12 with NodeComparison

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

the class CompareNodeCommandTest method status_capital_node_id.

@Test
public void status_capital_node_id() throws Exception {
    ctxOther().callWith(this::createDefaultRootNode);
    final Node createdNode = ctxOther().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").setNodeId(NodeId.from("MyNodeId")).build()));
    final NodeComparison comparison = ctxDefault().callWith(() -> doCompare(WS_OTHER, createdNode));
    assertEquals(CompareStatus.NEW_TARGET, comparison.getCompareStatus());
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 13 with NodeComparison

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

the class CompareNodeCommandTest method status_older.

@Test
public void status_older() throws Exception {
    ctxDefault().callWith(this::createDefaultRootNode);
    final Node createdNode = ctxDefault().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build()));
    ctxDefault().runWith(() -> doPushNode(WS_OTHER, createdNode));
    refresh();
    ctxOther().runWith(() -> doUpdateNode(createdNode));
    refresh();
    final NodeComparison comparison = ctxDefault().callWith(() -> doCompare(WS_OTHER, createdNode));
    assertEquals(CompareStatus.OLDER, comparison.getCompareStatus());
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 14 with NodeComparison

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

the class CompareNodeCommandTest method status_equal.

@Test
public void status_equal() throws Exception {
    ctxDefault().callWith(this::createDefaultRootNode);
    final Node createdNode = ctxDefault().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build()));
    ctxDefault().runWith(() -> doPushNode(WS_OTHER, createdNode));
    final NodeComparison comparison = ctxDefault().callWith(() -> doCompare(WS_OTHER, createdNode));
    assertEquals(CompareStatus.EQUAL, comparison.getCompareStatus());
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 15 with NodeComparison

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

the class CompareNodesCommand method execute.

public NodeComparisons execute() {
    Set<NodeId> allNodeIds = new HashSet<>();
    final Context context = ContextAccessor.current();
    final NodeComparisons.Builder builder = NodeComparisons.create();
    final NodeBranchEntries sourceVersions = nodeStorageService.getBranchNodeVersions(nodeIds, false, InternalContext.from(context));
    final NodeBranchEntries targetVersions = nodeStorageService.getBranchNodeVersions(nodeIds, false, InternalContext.create(context).branch(this.target).build());
    allNodeIds.addAll(sourceVersions.getKeys());
    allNodeIds.addAll(targetVersions.getKeys());
    for (final NodeId id : allNodeIds) {
        final CompareStatus compareStatus = CompareStatusResolver.create().source(sourceVersions.get(id)).target(targetVersions.get(id)).storageService(this.nodeStorageService).build().resolve();
        builder.add(new NodeComparison(sourceVersions.get(id), targetVersions.get(id), compareStatus));
    }
    return builder.build();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId) CompareStatus(com.enonic.xp.content.CompareStatus) NodeComparisons(com.enonic.xp.node.NodeComparisons) HashSet(java.util.HashSet)

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