Revert "Unify ORv1 and IIv5"
[yangtools.git] / data / yang-data-tree-ri / src / test / java / org / opendaylight / yangtools / yang / data / tree / impl / ModificationMetadataTreeTest.java
index 87d15a9516532285a4e08330cdf081f483358969..6e0b41bbd63859b0e8221652e0ca8cfcd19ae023 100644 (file)
@@ -7,26 +7,21 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.impl;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry;
-import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
-import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.Optional;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
 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.impl.di.InMemoryDataTreeFactory;
@@ -57,18 +52,13 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  *      }
  * }
  */
-public class ModificationMetadataTreeTest extends AbstractTestModelTest {
+class ModificationMetadataTreeTest extends AbstractTestModelTest {
 
     private static final Short ONE_ID = 1;
     private static final Short TWO_ID = 2;
     private static final String TWO_ONE_NAME = "one";
     private static final String TWO_TWO_NAME = "two";
 
-    private static final YangInstanceIdentifier OUTER_LIST_1_PATH =
-            YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
-            .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)
-            .build();
-
     private static final YangInstanceIdentifier OUTER_LIST_2_PATH =
             YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
             .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
@@ -83,17 +73,28 @@ public class ModificationMetadataTreeTest extends AbstractTestModelTest {
             .node(TestModel.VALUE_QNAME)
             .build();
 
-    private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
-            .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME)
-                    .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME))
-                    .withChild(mapEntry(TestModel.INNER_LIST_QNAME,TestModel.NAME_QNAME, TWO_TWO_NAME))
-                    .build())
-                    .build();
+    private static final MapEntryNode BAR_NODE = ImmutableNodes.newMapEntryBuilder()
+        .withNodeIdentifier(NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID))
+        .withChild(ImmutableNodes.leafNode(TestModel.ID_QNAME, TWO_ID))
+        .withChild(ImmutableNodes.newSystemMapBuilder()
+            .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
+            .withChild(ImmutableNodes.newMapEntryBuilder()
+                .withNodeIdentifier(
+                    NodeIdentifierWithPredicates.of(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME))
+                .withChild(ImmutableNodes.leafNode(TestModel.NAME_QNAME, TWO_ONE_NAME))
+                .build())
+            .withChild(ImmutableNodes.newMapEntryBuilder()
+                .withNodeIdentifier(
+                    NodeIdentifierWithPredicates.of(TestModel.INNER_LIST_QNAME,TestModel.NAME_QNAME, TWO_TWO_NAME))
+                .withChild(ImmutableNodes.leafNode(TestModel.NAME_QNAME, TWO_TWO_NAME))
+                .build())
+            .build())
+        .build();
 
     private RootApplyStrategy rootOper;
 
-    @Before
-    public void prepare() throws ExcludedDataSchemaNodeException {
+    @BeforeEach
+    void prepare() throws ExcludedDataSchemaNodeException {
         rootOper = RootApplyStrategy.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
             DataTreeConfiguration.DEFAULT_OPERATIONAL));
     }
@@ -116,42 +117,47 @@ public class ModificationMetadataTreeTest extends AbstractTestModelTest {
      * @return a test document
      */
     public ContainerNode createDocumentOne() {
-        return Builders.containerBuilder()
+        return ImmutableNodes.newContainerBuilder()
             .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME))
             .withChild(createTestContainer())
             .build();
     }
 
     private static ContainerNode createTestContainer() {
-        return Builders.containerBuilder()
+        return ImmutableNodes.newContainerBuilder()
             .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
-            .withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
-                .withChild(mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID))
+            .withChild(ImmutableNodes.newSystemMapBuilder()
+                .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME))
+                .withChild(ImmutableNodes.newMapEntryBuilder()
+                    .withNodeIdentifier(
+                        NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID))
+                    .withChild(ImmutableNodes.leafNode(TestModel.ID_QNAME, ONE_ID))
+                    .build())
                 .withChild(BAR_NODE).build())
             .build();
     }
 
     @Test
-    public void basicReadWrites() {
-        final DataTreeModification modificationTree = new InMemoryDataTreeModification(
+    void basicReadWrites() {
+        final var modificationTree = new InMemoryDataTreeModification(
             new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNode.of(createDocumentOne(), Version.initial()), rootOper), rootOper);
-        final Optional<NormalizedNode> originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH);
+        final var originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH);
         assertTrue(originalBarNode.isPresent());
-        assertSame(BAR_NODE, originalBarNode.get());
+        assertSame(BAR_NODE, originalBarNode.orElseThrow());
 
         // writes node to /outer-list/1/inner_list/two/value
         modificationTree.write(TWO_TWO_VALUE_PATH, ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "test"));
 
         // reads node to /outer-list/1/inner_list/two/value
         // and checks if node is already present
-        final Optional<NormalizedNode> barTwoCModified = modificationTree.readNode(TWO_TWO_VALUE_PATH);
+        final var barTwoCModified = modificationTree.readNode(TWO_TWO_VALUE_PATH);
         assertTrue(barTwoCModified.isPresent());
-        assertEquals(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "test"), barTwoCModified.get());
+        assertEquals(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "test"), barTwoCModified.orElseThrow());
 
         // delete node to /outer-list/1/inner_list/two/value
         modificationTree.delete(TWO_TWO_VALUE_PATH);
-        final Optional<NormalizedNode> barTwoCAfterDelete = modificationTree.readNode(TWO_TWO_VALUE_PATH);
+        final var barTwoCAfterDelete = modificationTree.readNode(TWO_TWO_VALUE_PATH);
         assertFalse(barTwoCAfterDelete.isPresent());
     }
 
@@ -160,7 +166,7 @@ public class ModificationMetadataTreeTest extends AbstractTestModelTest {
         /**
          * Creates empty Snapshot with associated schema context.
          */
-        final DataTree t = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
+        final var t = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
             SCHEMA_CONTEXT);
 
         /**
@@ -173,44 +179,46 @@ public class ModificationMetadataTreeTest extends AbstractTestModelTest {
     }
 
     @Test
-    public void createFromEmptyState() {
+    void createFromEmptyState() {
 
-        final DataTreeModification modificationTree = createEmptyModificationTree();
+        final var modificationTree = createEmptyModificationTree();
         // Writes empty container node to /test
-        modificationTree.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+        modificationTree.write(TestModel.TEST_PATH,
+            ImmutableNodes.newContainerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build());
 
         // Writes empty list node to /test/outer-list
-        modificationTree.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+        modificationTree.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.newSystemMapBuilder()
+            .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME))
             .build());
 
         // Reads list node from /test/outer-list.
-        final Optional<NormalizedNode> potentialOuterList = modificationTree.readNode(TestModel.OUTER_LIST_PATH);
+        final var potentialOuterList = modificationTree.readNode(TestModel.OUTER_LIST_PATH);
         assertFalse(potentialOuterList.isPresent());
 
         // Reads container node from /test and verifies that it contains test node.
-        final Optional<NormalizedNode> potentialTest = modificationTree.readNode(TestModel.TEST_PATH);
+        final var potentialTest = modificationTree.readNode(TestModel.TEST_PATH);
         assertPresentAndType(potentialTest, ContainerNode.class);
     }
 
     @Test
-    public void writeSubtreeReadChildren() {
-        final DataTreeModification modificationTree = createEmptyModificationTree();
+    void writeSubtreeReadChildren() {
+        final var modificationTree = createEmptyModificationTree();
         modificationTree.write(TestModel.TEST_PATH, createTestContainer());
-        final Optional<NormalizedNode> potential = modificationTree.readNode(TWO_TWO_PATH);
+        final var potential = modificationTree.readNode(TWO_TWO_PATH);
         assertPresentAndType(potential, MapEntryNode.class);
     }
 
     @Test
-    public void writeSubtreeDeleteChildren() {
-        final DataTreeModification modificationTree = createEmptyModificationTree();
+    void writeSubtreeDeleteChildren() {
+        final var modificationTree = createEmptyModificationTree();
         modificationTree.write(TestModel.TEST_PATH, createTestContainer());
 
         // We verify data are present
-        final Optional<NormalizedNode> potentialBeforeDelete = modificationTree.readNode(TWO_TWO_PATH);
+        final var potentialBeforeDelete = modificationTree.readNode(TWO_TWO_PATH);
         assertPresentAndType(potentialBeforeDelete, MapEntryNode.class);
 
         modificationTree.delete(TWO_TWO_PATH);
-        final Optional<NormalizedNode> potentialAfterDelete = modificationTree.readNode(TWO_TWO_PATH);
+        final var potentialAfterDelete = modificationTree.readNode(TWO_TWO_PATH);
         assertFalse(potentialAfterDelete.isPresent());
 
     }
@@ -218,7 +226,7 @@ public class ModificationMetadataTreeTest extends AbstractTestModelTest {
     private static <T> T assertPresentAndType(final Optional<?> potential, final Class<T> type) {
         assertNotNull(potential);
         assertTrue(potential.isPresent());
-        assertTrue(type.isInstance(potential.get()));
-        return type.cast(potential.get());
+        assertTrue(type.isInstance(potential.orElseThrow()));
+        return type.cast(potential.orElseThrow());
     }
 }