Inline isServerConfigurationPayload()
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / util / TestModel.java
index d99134682fea48a459ffa7a5e8c63a3af02c2555..37d102d0f352e98aaf5382290a2c751091d57528 100644 (file)
@@ -10,40 +10,23 @@ package org.opendaylight.controller.cluster.datastore.util;
 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.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes.leafNode;
 
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.io.InputStream;
-import java.math.BigDecimal;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.List;
+import org.opendaylight.yangtools.yang.common.Decimal64;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Uint64;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 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.YangInstanceIdentifier.NodeWithValue;
-import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
-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.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public final class TestModel {
@@ -170,138 +153,84 @@ public final class TestModel {
         return TestModel.class.getResourceAsStream(resourceName);
     }
 
-    public static SchemaContext createTestContext() {
+    public static EffectiveModelContext createTestContext() {
         return YangParserTestUtils.parseYangResources(TestModel.class, DATASTORE_TEST_YANG, DATASTORE_AUG_YANG,
             DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
-    public static SchemaContext createTestContextWithoutTestSchema() {
+    public static EffectiveModelContext createTestContextWithoutTestSchema() {
         return YangParserTestUtils.parseYangResource(DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
-    public static SchemaContext createTestContextWithoutAugmentationSchema() {
+    public static EffectiveModelContext createTestContextWithoutAugmentationSchema() {
         return YangParserTestUtils.parseYangResources(TestModel.class, DATASTORE_TEST_YANG,
             DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
     public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> createBaseTestContainerBuilder() {
-        // Create a list of shoes
-        // This is to test leaf list entry
-        final LeafSetEntryNode<Object> nike = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
-                new NodeWithValue<>(SHOE_QNAME, "nike")).withValue("nike").build();
-
-        final LeafSetEntryNode<Object> puma = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
-                new NodeWithValue<>(SHOE_QNAME, "puma")).withValue("puma").build();
-
-        final LeafSetNode<Object> shoes = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(
-                new NodeIdentifier(SHOE_QNAME)).withChild(nike).withChild(puma).build();
-
-        // Test a leaf-list where each entry contains an identity
-        final LeafSetEntryNode<Object> cap1 =
-                ImmutableLeafSetEntryNodeBuilder
-                        .create()
-                        .withNodeIdentifier(
-                                new NodeWithValue<>(QName.create(
-                                        TEST_QNAME, "capability"), DESC_QNAME))
-                        .withValue(DESC_QNAME).build();
-
-        final LeafSetNode<Object> capabilities =
-                ImmutableLeafSetNodeBuilder
-                        .create()
-                        .withNodeIdentifier(
-                                new NodeIdentifier(QName.create(
-                                        TEST_QNAME, "capability"))).withChild(cap1).build();
-
-        ContainerNode switchFeatures =
-                ImmutableContainerNodeBuilder
-                        .create()
-                        .withNodeIdentifier(
-                                new NodeIdentifier(SWITCH_FEATURES_QNAME))
-                        .withChild(capabilities).build();
-
-        // Create a leaf list with numbers
-        final LeafSetEntryNode<Object> five =
-                ImmutableLeafSetEntryNodeBuilder
-                        .create()
-                        .withNodeIdentifier(
-                                new NodeWithValue<>(QName.create(
-                                        TEST_QNAME, "number"), 5)).withValue(5).build();
-        final LeafSetEntryNode<Object> fifteen =
-                ImmutableLeafSetEntryNodeBuilder
-                        .create()
-                        .withNodeIdentifier(
-                                new NodeWithValue<>(QName.create(
-                                        TEST_QNAME, "number"), 15)).withValue(15).build();
-        final LeafSetNode<Object> numbers =
-                ImmutableLeafSetNodeBuilder
-                        .create()
-                        .withNodeIdentifier(
-                                new NodeIdentifier(QName.create(
-                                        TEST_QNAME, "number"))).withChild(five).withChild(fifteen)
-                        .build();
-
-
-        // Create augmentations
-        MapEntryNode augMapEntry = createAugmentedListEntry(1, "First Test");
-
-        // Create a bits leaf
-        NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>>
-                myBits = Builders.leafBuilder()
-                .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "my-bits")))
-                .withValue(ImmutableSet.of("foo", "bar"));
-
-        // Create unkeyed list entry
-        UnkeyedListEntryNode unkeyedListEntry = Builders.unkeyedListEntryBuilder()
-                .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME))
-                .withChild(ImmutableNodes.leafNode(NAME_QNAME, "unkeyed-entry-name"))
-                .build();
-
         // Create YangInstanceIdentifier with all path arg types.
-        YangInstanceIdentifier instanceID = YangInstanceIdentifier.create(
-                new NodeIdentifier(QName.create(TEST_QNAME, "qname")),
-                NodeIdentifierWithPredicates.of(QName.create(TEST_QNAME, "list-entry"),
-                        QName.create(TEST_QNAME, "key"), 10),
-                new AugmentationIdentifier(ImmutableSet.of(
-                        QName.create(TEST_QNAME, "aug1"), QName.create(TEST_QNAME, "aug2"))),
-                new NodeWithValue<>(QName.create(TEST_QNAME, "leaf-list-entry"), "foo"));
-
-        Map<QName, Object> keyValues = new HashMap<>();
-        keyValues.put(CHILDREN_QNAME, FIRST_CHILD_NAME);
-
+        YangInstanceIdentifier instanceID = YangInstanceIdentifier.of(
+            new NodeIdentifier(QName.create(TEST_QNAME, "qname")),
+            NodeIdentifierWithPredicates.of(QName.create(TEST_QNAME, "list-entry"),
+                QName.create(TEST_QNAME, "key"), 10),
+            new NodeWithValue<>(QName.create(TEST_QNAME, "leaf-list-entry"), "foo"));
 
         // Create the document
-        return ImmutableContainerNodeBuilder
-                .create()
-                .withNodeIdentifier(new NodeIdentifier(TEST_QNAME))
-                .withChild(myBits.build())
-                .withChild(ImmutableNodes.leafNode(DESC_QNAME, DESC))
-                .withChild(ImmutableNodes.leafNode(BOOLEAN_LEAF_QNAME, ENABLED))
-                .withChild(ImmutableNodes.leafNode(SHORT_LEAF_QNAME, SHORT_ID))
-                .withChild(ImmutableNodes.leafNode(BYTE_LEAF_QNAME, BYTE_ID))
-                .withChild(ImmutableNodes.leafNode(TestModel.BIGINTEGER_LEAF_QNAME, Uint64.valueOf(100)))
-                .withChild(ImmutableNodes.leafNode(TestModel.BIGDECIMAL_LEAF_QNAME, BigDecimal.valueOf(1.2)))
-                .withChild(ImmutableNodes.leafNode(SOME_REF_QNAME, instanceID))
-                .withChild(ImmutableNodes.leafNode(MYIDENTITY_QNAME, DESC_QNAME))
-                .withChild(Builders.unkeyedListBuilder()
-                        .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME))
-                        .withChild(unkeyedListEntry).build())
-                .withChild(Builders.choiceBuilder()
-                        .withNodeIdentifier(new NodeIdentifier(TWO_THREE_QNAME))
-                        .withChild(ImmutableNodes.leafNode(TWO_QNAME, "two")).build())
-                .withChild(Builders.orderedMapBuilder()
-                        .withNodeIdentifier(new NodeIdentifier(ORDERED_LIST_QNAME))
-                        .withValue(ImmutableList.<MapEntryNode>builder().add(
-                                mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "1").build(),
-                                mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "2").build()).build())
-                        .build())
-                .withChild(shoes)
-                .withChild(numbers)
-                .withChild(switchFeatures)
-                .withChild(mapNodeBuilder(AUGMENTED_LIST_QNAME).withChild(augMapEntry).build())
-                .withChild(mapNodeBuilder(OUTER_LIST_QNAME)
-                                .withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID))
-                                .withChild(BAR_NODE).build()
-                );
+        return ImmutableNodes.newContainerBuilder()
+            .withNodeIdentifier(new NodeIdentifier(TEST_QNAME))
+            // Create a bits leaf
+            .withChild(leafNode(QName.create(TEST_QNAME, "my-bits"), ImmutableSet.of("foo", "bar")))
+            .withChild(leafNode(DESC_QNAME, DESC))
+            .withChild(leafNode(BOOLEAN_LEAF_QNAME, ENABLED))
+            .withChild(leafNode(SHORT_LEAF_QNAME, SHORT_ID))
+            .withChild(leafNode(BYTE_LEAF_QNAME, BYTE_ID))
+            .withChild(leafNode(TestModel.BIGINTEGER_LEAF_QNAME, Uint64.valueOf(100)))
+            .withChild(leafNode(TestModel.BIGDECIMAL_LEAF_QNAME, Decimal64.valueOf("1.2").scaleTo(2)))
+            .withChild(leafNode(SOME_REF_QNAME, instanceID))
+            .withChild(leafNode(MYIDENTITY_QNAME, DESC_QNAME))
+            .withChild(ImmutableNodes.newUnkeyedListBuilder()
+                .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME))
+                // Create unkeyed list entry
+                .withChild(ImmutableNodes.newUnkeyedListEntryBuilder()
+                    .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME))
+                    .withChild(leafNode(NAME_QNAME, "unkeyed-entry-name"))
+                    .build())
+                .build())
+            .withChild(ImmutableNodes.newChoiceBuilder()
+                .withNodeIdentifier(new NodeIdentifier(TWO_THREE_QNAME))
+                .withChild(leafNode(TWO_QNAME, "two")).build())
+            .withChild(ImmutableNodes.newUserMapBuilder()
+                .withNodeIdentifier(new NodeIdentifier(ORDERED_LIST_QNAME))
+                .withValue(List.of(
+                    mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "1").build(),
+                    mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "2").build()))
+                .build())
+            .withChild(ImmutableNodes.newSystemLeafSetBuilder()
+                .withNodeIdentifier(new NodeIdentifier(SHOE_QNAME))
+                .withChildValue("nike")
+                .withChildValue("puma")
+                .build())
+            .withChild(ImmutableNodes.newSystemLeafSetBuilder()
+                .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "number")))
+                .withChildValue(5)
+                .withChildValue(15)
+                .build())
+            .withChild(ImmutableNodes.newContainerBuilder()
+                .withNodeIdentifier(new NodeIdentifier(SWITCH_FEATURES_QNAME))
+                // Test a leaf-list where each entry contains an identity
+                .withChild(ImmutableNodes.newSystemLeafSetBuilder()
+                    .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "capability")))
+                    .withChildValue(DESC_QNAME)
+                    .build())
+                .build())
+            .withChild(mapNodeBuilder(AUGMENTED_LIST_QNAME)
+                // Create augmentations
+                .withChild(createAugmentedListEntry(1, "First Test"))
+                .build())
+            .withChild(mapNodeBuilder(OUTER_LIST_QNAME)
+                .withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID))
+                .withChild(BAR_NODE)
+                .build());
     }
 
     public static ContainerNode createTestContainer() {
@@ -309,76 +238,41 @@ public final class TestModel {
     }
 
     public static MapEntryNode createAugmentedListEntry(final int id, final String name) {
-        Set<QName> childAugmentations = new HashSet<>();
-        childAugmentations.add(AUG_CONT_QNAME);
-
-        ContainerNode augCont = ImmutableContainerNodeBuilder.create()
-                        .withNodeIdentifier(new NodeIdentifier(AUG_CONT_QNAME))
-                        .withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name))
-                        .build();
-
-
-        final AugmentationIdentifier augmentationIdentifier = new AugmentationIdentifier(childAugmentations);
-        final AugmentationNode augmentationNode =
-                Builders.augmentationBuilder()
-                        .withNodeIdentifier(augmentationIdentifier).withChild(augCont)
-                        .build();
-
-        return ImmutableMapEntryNodeBuilder.create()
-                .withNodeIdentifier(NodeIdentifierWithPredicates.of(AUGMENTED_LIST_QNAME, ID_QNAME, id))
-                .withChild(ImmutableNodes.leafNode(ID_QNAME, id))
-                .withChild(augmentationNode).build();
+        return ImmutableNodes.newMapEntryBuilder()
+            .withNodeIdentifier(NodeIdentifierWithPredicates.of(AUGMENTED_LIST_QNAME, ID_QNAME, id))
+            .withChild(leafNode(ID_QNAME, id))
+            .withChild(ImmutableNodes.newContainerBuilder()
+                .withNodeIdentifier(new NodeIdentifier(AUG_CONT_QNAME))
+                .withChild(leafNode(AUG_NAME_QNAME, name))
+                .build())
+            .build();
     }
 
     public static ContainerNode createFamily() {
-        final DataContainerNodeBuilder<NodeIdentifier, ContainerNode>
-            familyContainerBuilder = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
-                        new NodeIdentifier(FAMILY_QNAME));
-
-        final CollectionNodeBuilder<MapEntryNode, MapNode> childrenBuilder =
-                mapNodeBuilder(CHILDREN_QNAME);
-
-        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode>
-            firstChildBuilder = mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID);
-        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode>
-            secondChildBuilder = mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID);
-
-        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode>
-            firstGrandChildBuilder = mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
-                    FIRST_GRAND_CHILD_ID);
-        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode>
-            secondGrandChildBuilder = mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
-                    SECOND_GRAND_CHILD_ID);
-
-        firstGrandChildBuilder
-                .withChild(
-                        ImmutableNodes.leafNode(GRAND_CHILD_NUMBER_QNAME,
-                                FIRST_GRAND_CHILD_ID)).withChild(
-                ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME,
-                        FIRST_GRAND_CHILD_NAME));
-
-        secondGrandChildBuilder.withChild(
-                ImmutableNodes.leafNode(GRAND_CHILD_NUMBER_QNAME, SECOND_GRAND_CHILD_ID))
-                .withChild(ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME, SECOND_GRAND_CHILD_NAME));
-
-        firstChildBuilder
-                .withChild(ImmutableNodes.leafNode(CHILD_NUMBER_QNAME, FIRST_CHILD_ID))
-                .withChild(ImmutableNodes.leafNode(CHILD_NAME_QNAME, FIRST_CHILD_NAME))
-                .withChild(mapNodeBuilder(GRAND_CHILDREN_QNAME)
-                    .withChild(firstGrandChildBuilder.build())
-                    .build());
-
-
-        secondChildBuilder
-                .withChild(ImmutableNodes.leafNode(CHILD_NUMBER_QNAME, SECOND_CHILD_ID))
-                .withChild(ImmutableNodes.leafNode(CHILD_NAME_QNAME, SECOND_CHILD_NAME))
-                .withChild(mapNodeBuilder(GRAND_CHILDREN_QNAME)
-                    .withChild(firstGrandChildBuilder.build())
-                    .build());
-
-        childrenBuilder.withChild(firstChildBuilder.build());
-        childrenBuilder.withChild(secondChildBuilder.build());
-
-        return familyContainerBuilder.withChild(childrenBuilder.build()).build();
+        final var firstGrandChildBuilder = mapEntryBuilder(
+                GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME, FIRST_GRAND_CHILD_ID)
+            .withChild(leafNode(GRAND_CHILD_NUMBER_QNAME,FIRST_GRAND_CHILD_ID))
+            .withChild(leafNode(GRAND_CHILD_NAME_QNAME, FIRST_GRAND_CHILD_NAME));
+
+        return ImmutableNodes.newContainerBuilder()
+            .withNodeIdentifier(new NodeIdentifier(FAMILY_QNAME))
+            .withChild(ImmutableNodes.newSystemMapBuilder()
+                .withNodeIdentifier(new NodeIdentifier(CHILDREN_QNAME))
+                .withChild(mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID)
+                    .withChild(leafNode(CHILD_NUMBER_QNAME, FIRST_CHILD_ID))
+                    .withChild(leafNode(CHILD_NAME_QNAME, FIRST_CHILD_NAME))
+                    .withChild(mapNodeBuilder(GRAND_CHILDREN_QNAME)
+                        .withChild(firstGrandChildBuilder.build())
+                        .build())
+                    .build())
+                .withChild(mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID)
+                    .withChild(leafNode(CHILD_NUMBER_QNAME, SECOND_CHILD_ID))
+                    .withChild(leafNode(CHILD_NAME_QNAME, SECOND_CHILD_NAME))
+                    .withChild(mapNodeBuilder(GRAND_CHILDREN_QNAME)
+                        .withChild(firstGrandChildBuilder.build())
+                        .build())
+                    .build())
+                .build())
+            .build();
     }
 }