X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FPruningDataTreeModificationTest.java;h=4c5c06e3fadff4ebd955badd3545bed7874f4347;hb=f40e99a51cd3fc2c9be3ac8aa0772bdb6b6ce479;hp=6ec01cfbbf0ad10909ec36038f45d8a2d59745b3;hpb=d19cf96d390ffcdba8b1f64a6dd3f3749ecc5872;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java index 6ec01cfbbf..4c5c06e3fa 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java @@ -41,30 +41,31 @@ import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelpe import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; +import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; -import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException; +import org.opendaylight.yangtools.yang.data.tree.api.DataTree; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor; +import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException; +import org.opendaylight.yangtools.yang.data.tree.api.ModificationType; +import org.opendaylight.yangtools.yang.data.tree.api.SchemaValidationFailedException; +import org.opendaylight.yangtools.yang.data.tree.api.TreeType; +import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory; import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; @RunWith(MockitoJUnitRunner.class) public class PruningDataTreeModificationTest { static final QName INVALID_TEST_QNAME = QName.create(TestModel.TEST_QNAME, "invalid"); static final YangInstanceIdentifier INVALID_TEST_PATH = YangInstanceIdentifier.of(INVALID_TEST_QNAME); - private static SchemaContext SCHEMA_CONTEXT; + private static EffectiveModelContext SCHEMA_CONTEXT; private static DataSchemaContextTree CONTEXT_TREE; @Mock @@ -123,7 +124,7 @@ public class PruningDataTreeModificationTest { @Test public void testMerge() { - NormalizedNode normalizedNode = CarsModel.create(); + NormalizedNode normalizedNode = CarsModel.create(); YangInstanceIdentifier path = CarsModel.BASE_PATH; pruningDataTreeModification.merge(path, normalizedNode); @@ -132,7 +133,7 @@ public class PruningDataTreeModificationTest { @Test public void testMergeWithInvalidNamespace() throws DataValidationFailedException { - NormalizedNode normalizedNode = PeopleModel.emptyContainer(); + NormalizedNode normalizedNode = PeopleModel.emptyContainer(); YangInstanceIdentifier path = PeopleModel.BASE_PATH; pruningDataTreeModification.merge(path, normalizedNode); @@ -140,19 +141,21 @@ public class PruningDataTreeModificationTest { verify(mockModification, times(1)).merge(path, normalizedNode); DataTreeCandidate candidate = getCandidate(); - assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType()); + assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().modificationType()); } @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(); + DataContainerChild outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); + ContainerNode normalizedNode = Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) + .withChild(outerNode) + .withChild(Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(AUG_CONTAINER)) + .withChild(ImmutableNodes.containerNode(AUG_INNER_CONTAINER)) + .build()) + .withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")) + .build(); YangInstanceIdentifier path = TestModel.TEST_PATH; @@ -160,17 +163,17 @@ public class PruningDataTreeModificationTest { dataTree.commit(getCandidate()); - ContainerNode prunedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).build(); + ContainerNode prunedNode = Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) + .withChild(outerNode) + .build(); - Optional> actual = dataTree.takeSnapshot().readNode(path); - assertTrue("After pruning present", actual.isPresent()); - assertEquals("After pruning", prunedNode, actual.get()); + assertEquals("After pruning", Optional.of(prunedNode), dataTree.takeSnapshot().readNode(path)); } @Test public void testMergeWithValidNamespaceAndInvalidNodeName() throws DataValidationFailedException { - NormalizedNode normalizedNode = ImmutableNodes.containerNode(INVALID_TEST_QNAME); + NormalizedNode normalizedNode = ImmutableNodes.containerNode(INVALID_TEST_QNAME); YangInstanceIdentifier path = INVALID_TEST_PATH; pruningDataTreeModification.merge(path, normalizedNode); @@ -178,12 +181,12 @@ public class PruningDataTreeModificationTest { verify(mockModification, times(1)).merge(path, normalizedNode); DataTreeCandidate candidate = getCandidate(); - assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType()); + assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().modificationType()); } @Test public void testWrite() { - NormalizedNode normalizedNode = CarsModel.create(); + NormalizedNode normalizedNode = CarsModel.create(); YangInstanceIdentifier path = CarsModel.BASE_PATH; pruningDataTreeModification.write(path, normalizedNode); @@ -201,13 +204,11 @@ public class PruningDataTreeModificationTest { localDataTree.validate(mod); localDataTree.commit(localDataTree.prepare(mod)); - NormalizedNode normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()).get(); - pruningDataTreeModification.write(YangInstanceIdentifier.empty(), normalizedNode); + NormalizedNode normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.of()).orElseThrow(); + pruningDataTreeModification.write(YangInstanceIdentifier.of(), normalizedNode); dataTree.commit(getCandidate()); - Optional> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()); - assertTrue("Root present", actual.isPresent()); - assertEquals("Root node", normalizedNode, actual.get()); + assertEquals(Optional.of(normalizedNode), dataTree.takeSnapshot().readNode(YangInstanceIdentifier.of())); } @Test @@ -215,23 +216,22 @@ public class PruningDataTreeModificationTest { final Shard mockShard = Mockito.mock(Shard.class); ShardDataTree shardDataTree = new ShardDataTree(mockShard, SCHEMA_CONTEXT, TreeType.CONFIGURATION); - NormalizedNode root = shardDataTree.readNode(YangInstanceIdentifier.empty()).get(); + NormalizedNode root = shardDataTree.readNode(YangInstanceIdentifier.of()).orElseThrow(); - NormalizedNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(root.getNodeType())).withChild( - ImmutableNodes.containerNode(AUG_CONTAINER)).build(); - pruningDataTreeModification.write(YangInstanceIdentifier.empty(), normalizedNode); + NormalizedNode normalizedNode = Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(root.name().getNodeType())) + .withChild(ImmutableNodes.containerNode(AUG_CONTAINER)) + .build(); + pruningDataTreeModification.write(YangInstanceIdentifier.of(), normalizedNode); dataTree.commit(getCandidate()); - Optional> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()); - assertEquals("Root present", true, actual.isPresent()); - assertEquals("Root node", root, actual.get()); + assertEquals(Optional.of(root), dataTree.takeSnapshot().readNode(YangInstanceIdentifier.of())); } @Test public void testWriteWithInvalidNamespace() throws DataValidationFailedException { - NormalizedNode normalizedNode = PeopleModel.emptyContainer(); + NormalizedNode normalizedNode = PeopleModel.emptyContainer(); YangInstanceIdentifier path = PeopleModel.BASE_PATH; pruningDataTreeModification.write(path, normalizedNode); @@ -239,20 +239,22 @@ public class PruningDataTreeModificationTest { verify(mockModification, times(1)).write(path, normalizedNode); DataTreeCandidate candidate = getCandidate(); - assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType()); + assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().modificationType()); } @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(); + DataContainerChild outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); + ContainerNode normalizedNode = Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) + .withChild(outerNode) + .withChild(Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(AUG_CONTAINER)) + .withChild(ImmutableNodes.containerNode(AUG_INNER_CONTAINER)) + .build()) + .withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")) + .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")) + .build(); YangInstanceIdentifier path = TestModel.TEST_PATH; @@ -260,13 +262,13 @@ public class PruningDataTreeModificationTest { dataTree.commit(getCandidate()); - ContainerNode prunedNode = ImmutableContainerNodeBuilder.create() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) - .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build(); + ContainerNode prunedNode = Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) + .withChild(outerNode) + .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")) + .build(); - Optional> actual = dataTree.takeSnapshot().readNode(path); - assertTrue("After pruning present", actual.isPresent()); - assertEquals("After pruning", prunedNode, actual.get()); + assertEquals(Optional.of(prunedNode), dataTree.takeSnapshot().readNode(path)); } @Test