PruningDataTreeModification extends ForwardingObject implements DataTreeModification { @Override public final Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier yangInstanceIdentifier) { return delegate.readNode(yangInstanceIdentifier); } PruningDataTreeModification(final DataTreeModification delegate, final DataTree dataTree,
            final ReusableNormalizedNodePruner pruner); @Override final EffectiveModelContext getEffectiveModelContext(); @Override final void delete(final YangInstanceIdentifier path); @Override final void ready(); @Override final void applyToCursor(final DataTreeModificationCursor dataTreeModificationCursor); @Override final Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier yangInstanceIdentifier); @Override final DataTreeModification newModification();  }
@Test public void testMergeWithInvalidChildNodeNames() throws DataValidationFailedException { ContainerNode augContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild( ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build(); DataContainerChild<?, ?> outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) .withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")).build(); YangInstanceIdentifier path = TestModel.TEST_PATH; pruningDataTreeModification.merge(path, normalizedNode); dataTree.commit(getCandidate()); ContainerNode prunedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).build(); Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(path); assertTrue("After pruning present", actual.isPresent()); assertEquals("After pruning", prunedNode, actual.get()); }
@Test public void testWriteRootNodeWithInvalidChild() throws Exception { final Shard mockShard = Mockito.mock(Shard.class); ShardDataTree shardDataTree = new ShardDataTree(mockShard, SCHEMA_CONTEXT, TreeType.CONFIGURATION); NormalizedNode<?, ?> root = shardDataTree.readNode(YangInstanceIdentifier.empty()).get(); NormalizedNode<?, ?> normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(root.getNodeType())).withChild( ImmutableNodes.containerNode(AUG_CONTAINER)).build(); pruningDataTreeModification.write(YangInstanceIdentifier.empty(), normalizedNode); dataTree.commit(getCandidate()); Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()); assertEquals("Root present", true, actual.isPresent()); assertEquals("Root node", root, actual.get()); }
@Test public void testWriteWithInvalidChildNodeNames() throws DataValidationFailedException { ContainerNode augContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild( ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build(); DataContainerChild<?, ?> outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) .withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")) .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build(); YangInstanceIdentifier path = TestModel.TEST_PATH; pruningDataTreeModification.write(path, normalizedNode); dataTree.commit(getCandidate()); ContainerNode prunedNode = ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build(); Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(path); assertTrue("After pruning present", actual.isPresent()); assertEquals("After pruning", prunedNode, actual.get()); }
@Test public void testReadNode() { pruningDataTreeModification.readNode(CarsModel.BASE_PATH); verify(mockModification).readNode(CarsModel.BASE_PATH); }