@Override public Validator childNodeChanged(String name, NodeState before, NodeState after) throws CommitFailedException { MoveValidator childDiff = moveValidator.childNodeChanged(name, before, after); return childDiff == null ? null : new MoveDetector(childDiff); }
@Override public Validator childNodeChanged(String name, NodeState before, NodeState after) throws CommitFailedException { MoveValidator childDiff = moveValidator.childNodeChanged(name, before, after); return childDiff == null ? null : new MoveDetector(childDiff); }
@Override public Validator childNodeDeleted(String name, NodeState before) throws CommitFailedException { MoveValidator childDiff = moveValidator.childNodeDeleted(name, before); return childDiff == null ? null : new MoveDetector(childDiff); } }
@Override public Validator childNodeDeleted(String name, NodeState before) throws CommitFailedException { MoveValidator childDiff = moveValidator.childNodeDeleted(name, before); return childDiff == null ? null : new MoveDetector(childDiff); } }
@Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { PropertyState sourceProperty = after.getProperty(SOURCE_PATH); if (sourceProperty != null) { String sourcePath = sourceProperty.getValue(STRING); moveValidator.move(name, sourcePath, after); } MoveValidator childDiff = moveValidator.childNodeAdded(name, after); return childDiff == null ? null : new MoveDetector(childDiff); }
@Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { PropertyState sourceProperty = after.getProperty(SOURCE_PATH); if (sourceProperty != null) { String sourcePath = sourceProperty.getValue(STRING); moveValidator.move(name, sourcePath, after); } MoveValidator childDiff = moveValidator.childNodeAdded(name, after); return childDiff == null ? null : new MoveDetector(childDiff); }
/** * Test whether we can detect a single move * @throws CommitFailedException */ @Test public void simpleMove() throws CommitFailedException { NodeState moved1 = move(root.builder(), "/test/x", "/test/y/xx").getNodeState(); MoveExpectation moveExpectation1 = new MoveExpectation( ImmutableMap.of("/test/x", "/test/y/xx")); MoveDetector moveDetector1 = new MoveDetector(moveExpectation1); CommitFailedException exception1 = EditorDiff.process(moveDetector1, root, moved1); if (exception1 != null) { throw exception1; } moveExpectation1.assertAllFound(); // Test whether we can also detect the move back on top of the previous, persisted move NodeState moved2 = move(moved1.builder(), "/test/y/xx", "/test/x").getNodeState(); MoveExpectation moveExpectation2 = new MoveExpectation( ImmutableMap.of("/test/y/xx", "/test/x")); MoveDetector moveDetector2 = new MoveDetector(moveExpectation2); CommitFailedException exception2 = EditorDiff.process(moveDetector2, moved1, moved2); if (exception2 != null) { throw exception2; } moveExpectation2.assertAllFound(); }
/** * Moving a node forth and back again should not generate a move event. * @throws CommitFailedException */ @Test public void moveForthAndBack() throws CommitFailedException { NodeBuilder rootBuilder = root.builder(); move(rootBuilder, "/test/x", "/test/y/xx"); NodeState moved = move(rootBuilder, "/test/y/xx", "/test/x").getNodeState(); MoveExpectation moveExpectation = new MoveExpectation( ImmutableMap.<String, String>of()); MoveDetector moveDetector = new MoveDetector(moveExpectation); CommitFailedException exception = EditorDiff.process(moveDetector, root, moved); if (exception != null) { throw exception; } moveExpectation.assertAllFound(); }
/** * Moving a node from a moved subtree doesn't generate a move event. * @throws CommitFailedException */ @Test public void moveFromMovedSubtree() throws CommitFailedException { NodeBuilder rootBuilder = root.builder(); move(rootBuilder, "/test/z", "/test/y/z"); NodeState moved = move(rootBuilder, "/test/y/z/zz", "/test/x/zz").getNodeState(); MoveExpectation moveExpectation = new MoveExpectation( ImmutableMap.of("/test/z", "/test/y/z", "/test/z/zz", "/test/x/zz")); MoveDetector moveDetector = new MoveDetector(moveExpectation); CommitFailedException exception = EditorDiff.process(moveDetector, root, moved); if (exception != null) { throw exception; } moveExpectation.assertAllFound(); }
/** * Moving a moved node is reported as a single move from the original source * to the final destination. * @throws CommitFailedException */ @Test public void moveMoved() throws CommitFailedException { NodeBuilder rootBuilder = root.builder(); move(rootBuilder, "/test/x", "/test/y/xx"); NodeState moved = move(rootBuilder, "/test/y/xx", "/test/z/xxx").getNodeState(); MoveExpectation moveExpectation = new MoveExpectation( ImmutableMap.of("/test/x", "/test/z/xxx")); MoveDetector moveDetector = new MoveDetector(moveExpectation); CommitFailedException exception = EditorDiff.process(moveDetector, root, moved); if (exception != null) { throw exception; } moveExpectation.assertAllFound(); }
/** * Moving a transiently added node doesn't generate a move event * @throws CommitFailedException */ @Test public void moveAddedNode() throws CommitFailedException { NodeBuilder rootBuilder = root.builder(); rootBuilder.getChildNode("test").setChildNode("added"); NodeState moved = move(rootBuilder, "/test/added", "/test/y/added").getNodeState(); MoveExpectation moveExpectation = new MoveExpectation( ImmutableMap.<String, String>of()); MoveDetector moveDetector = new MoveDetector(moveExpectation); CommitFailedException exception = EditorDiff.process(moveDetector, root, moved); if (exception != null) { throw exception; } moveExpectation.assertAllFound(); }
/** * Moving a transiently added node from a moved subtree doesn't generate a move event. * @throws CommitFailedException */ @Test public void moveAddedFromMovedSubtree() throws CommitFailedException { NodeBuilder rootBuilder = root.builder(); rootBuilder.getChildNode("test").getChildNode("z").setChildNode("added"); move(rootBuilder, "/test/z", "/test/y/z"); NodeState moved = move(rootBuilder, "/test/y/z/added", "/test/x/added").getNodeState(); MoveExpectation moveExpectation = new MoveExpectation( ImmutableMap.of("/test/z", "/test/y/z")); MoveDetector moveDetector = new MoveDetector(moveExpectation); CommitFailedException exception = EditorDiff.process(moveDetector, root, moved); if (exception != null) { throw exception; } moveExpectation.assertAllFound(); }