Switch default stream output to Magnesium
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / util / TestModel.java
index 70bae6fcb3feb98506a326e2d1b7f946fa83df7e..8aa2420dfb45c2d69fed019300a22941d109fbc2 100644 (file)
@@ -11,18 +11,17 @@ 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 com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.io.InputStream;
 import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 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;
@@ -40,18 +39,16 @@ 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.DataContainerNodeAttrBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
+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.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
-public class TestModel {
+public final class TestModel {
 
     public static final QName TEST_QNAME = QName.create(
             "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test",
@@ -96,15 +93,15 @@ public class TestModel {
     public static final QName CHOICE_QNAME = QName.create(TEST_QNAME, "choice");
     public static final QName SHOE_QNAME = QName.create(TEST_QNAME, "shoe");
     public static final QName ANY_XML_QNAME = QName.create(TEST_QNAME, "any");
+    public static final QName EMPTY_QNAME = QName.create(TEST_QNAME, "empty-leaf");
     public static final QName INVALID_QNAME = QName.create(TEST_QNAME, "invalid");
     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
     private static final String DATASTORE_AUG_YANG = "/odl-datastore-augmentation.yang";
     private static final String DATASTORE_TEST_NOTIFICATION_YANG = "/odl-datastore-test-notification.yang";
 
-
     public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
-    public static final YangInstanceIdentifier DESC_PATH = YangInstanceIdentifier.
-            builder(TEST_PATH).node(DESC_QNAME).build();
+    public static final YangInstanceIdentifier DESC_PATH = YangInstanceIdentifier
+            .builder(TEST_PATH).node(DESC_QNAME).build();
     public static final YangInstanceIdentifier OUTER_LIST_PATH =
             YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
     public static final QName TWO_THREE_QNAME = QName.create(TEST_QNAME, "two");
@@ -116,13 +113,12 @@ public class TestModel {
     private static final String TWO_ONE_NAME = "one";
     private static final String TWO_TWO_NAME = "two";
     private static final String DESC = "Hello there";
-    private static final Long LONG_ID = 1L;
     private static final Boolean ENABLED = true;
     private static final Short SHORT_ID = 1;
     private static final Byte BYTE_ID = 1;
     // Family specific constants
     public static final QName FAMILY_QNAME = QName.create(
-            "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:notification-test", "2014-04-17", "family");
+        "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:notification-test", "2014-04-17", "family");
     public static final QName CHILDREN_QNAME = QName.create(FAMILY_QNAME, "children");
     public static final QName GRAND_CHILDREN_QNAME = QName.create(FAMILY_QNAME, "grand-children");
     public static final QName CHILD_NUMBER_QNAME = QName.create(FAMILY_QNAME, "child-number");
@@ -148,7 +144,6 @@ public class TestModel {
     private static final String FIRST_GRAND_CHILD_NAME = "first grand child";
     private static final String SECOND_GRAND_CHILD_NAME = "second grand child";
 
-
     private static final MapEntryNode BAR_NODE = mapEntryBuilder(
             OUTER_LIST_QNAME, ID_QNAME, TWO_ID) //
             .withChild(mapNodeBuilder(INNER_LIST_QNAME) //
@@ -157,15 +152,19 @@ public class TestModel {
                     .build()) //
             .build();
 
-    public static final InputStream getDatastoreTestInputStream() {
+    private TestModel() {
+        throw new UnsupportedOperationException();
+    }
+
+    public static InputStream getDatastoreTestInputStream() {
         return getInputStream(DATASTORE_TEST_YANG);
     }
 
-    public static final InputStream getDatastoreAugInputStream() {
+    public static InputStream getDatastoreAugInputStream() {
         return getInputStream(DATASTORE_AUG_YANG);
     }
 
-    public static final InputStream getDatastoreTestNotificationInputStream() {
+    public static InputStream getDatastoreTestNotificationInputStream() {
         return getInputStream(DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
@@ -174,39 +173,21 @@ public class TestModel {
     }
 
     public static SchemaContext createTestContext() {
-        List<InputStream> inputStreams = new ArrayList<>();
-        inputStreams.add(getDatastoreTestInputStream());
-        inputStreams.add(getDatastoreAugInputStream());
-        inputStreams.add(getDatastoreTestNotificationInputStream());
-
-        YangParserImpl parser = new YangParserImpl();
-        Set<Module> modules = parser.parseYangModelsFromStreams(inputStreams);
-        return parser.resolveSchemaContext(modules);
+        return YangParserTestUtils.parseYangResources(TestModel.class, DATASTORE_TEST_YANG, DATASTORE_AUG_YANG,
+            DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
     public static SchemaContext createTestContextWithoutTestSchema() {
-        List<InputStream> inputStreams = new ArrayList<>();
-        inputStreams.add(getDatastoreTestNotificationInputStream());
-
-        YangParserImpl parser = new YangParserImpl();
-        Set<Module> modules = parser.parseYangModelsFromStreams(inputStreams);
-        return parser.resolveSchemaContext(modules);
+        return YangParserTestUtils.parseYangResource(DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
-
     public static SchemaContext createTestContextWithoutAugmentationSchema() {
-        List<InputStream> inputStreams = new ArrayList<>();
-        inputStreams.add(getDatastoreTestInputStream());
-        inputStreams.add(getDatastoreTestNotificationInputStream());
-
-        YangParserImpl parser = new YangParserImpl();
-        Set<Module> modules = parser.parseYangModelsFromStreams(inputStreams);
-        return parser.resolveSchemaContext(modules);
+        return YangParserTestUtils.parseYangResources(TestModel.class, DATASTORE_TEST_YANG,
+            DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
-
     /**
-     * Returns a test document
+     * Returns a test document.
      * <p/>
      * <p/>
      * <pre>
@@ -221,11 +202,8 @@ public class TestModel {
      *                  name "two"
      *
      * </pre>
-     *
-     * @return
      */
-    public static NormalizedNode<?, ?> createDocumentOne(
-            SchemaContext schemaContext) {
+    public static NormalizedNode<?, ?> createDocumentOne(final SchemaContext schemaContext) {
         return ImmutableContainerNodeBuilder
                 .create()
                 .withNodeIdentifier(
@@ -234,7 +212,7 @@ public class TestModel {
 
     }
 
-    public static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createBaseTestContainerBuilder() {
+    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(
@@ -274,14 +252,14 @@ public class TestModel {
                 ImmutableLeafSetEntryNodeBuilder
                         .create()
                         .withNodeIdentifier(
-                                (new NodeWithValue<>(QName.create(
-                                        TEST_QNAME, "number"), 5))).withValue(5).build();
+                                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();
+                                new NodeWithValue<>(QName.create(
+                                        TEST_QNAME, "number"), 15)).withValue(15).build();
         final LeafSetNode<Object> numbers =
                 ImmutableLeafSetNodeBuilder
                         .create()
@@ -295,20 +273,20 @@ public class TestModel {
         MapEntryNode augMapEntry = createAugmentedListEntry(1, "First Test");
 
         // Create a bits leaf
-        NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>>
+        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 YangInstanceIdentifier.NodeIdentifier(UNKEYED_LIST_QNAME)).
-                        withChild(ImmutableNodes.leafNode(NAME_QNAME, "unkeyed-entry-name")).build();
+                Builders.unkeyedListEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.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")),
-                new NodeIdentifierWithPredicates(QName.create(TEST_QNAME, "list-entry"),
+                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"))),
@@ -327,7 +305,7 @@ public class TestModel {
                 .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, BigInteger.valueOf(100)))
+                .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))
@@ -337,11 +315,12 @@ public class TestModel {
                 .withChild(Builders.choiceBuilder()
                         .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TWO_THREE_QNAME))
                         .withChild(ImmutableNodes.leafNode(TWO_QNAME, "two")).build())
-                .withChild(Builders.orderedMapBuilder().
-                        withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ORDERED_LIST_QNAME)).
-                        withValue(ImmutableList.<MapEntryNode>builder().add(
+                .withChild(Builders.orderedMapBuilder()
+                        .withNodeIdentifier(new YangInstanceIdentifier.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())
+                                mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "2").build()).build())
+                        .build())
                 .withChild(shoes)
                 .withChild(numbers)
                 .withChild(switchFeatures)
@@ -356,7 +335,7 @@ public class TestModel {
         return createBaseTestContainerBuilder().build();
     }
 
-    public static MapEntryNode createAugmentedListEntry(int id, String name) {
+    public static MapEntryNode createAugmentedListEntry(final int id, final String name) {
 
         Set<QName> childAugmentations = new HashSet<>();
         childAugmentations.add(AUG_CONT_QNAME);
@@ -380,7 +359,7 @@ public class TestModel {
         return ImmutableMapEntryNodeBuilder
                 .create()
                 .withNodeIdentifier(
-                        new YangInstanceIdentifier.NodeIdentifierWithPredicates(
+                        YangInstanceIdentifier.NodeIdentifierWithPredicates.of(
                                 AUGMENTED_LIST_QNAME, ID_QNAME, id))
                 .withChild(ImmutableNodes.leafNode(ID_QNAME, id))
                 .withChild(augmentationNode).build();
@@ -388,24 +367,24 @@ public class TestModel {
 
 
     public static ContainerNode createFamily() {
-        final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> familyContainerBuilder =
-                ImmutableContainerNodeBuilder.create().withNodeIdentifier(
+        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode>
+            familyContainerBuilder = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
                         new YangInstanceIdentifier.NodeIdentifier(FAMILY_QNAME));
 
         final CollectionNodeBuilder<MapEntryNode, MapNode> childrenBuilder =
                 mapNodeBuilder(CHILDREN_QNAME);
 
-        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> firstChildBuilder =
-                mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID);
-        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> secondChildBuilder =
-                mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID);
-
-        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> firstGrandChildBuilder =
-                mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
-                        FIRST_GRAND_CHILD_ID);
-        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> secondGrandChildBuilder =
-                mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
-                        SECOND_GRAND_CHILD_ID);
+        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode>
+            firstChildBuilder = mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID);
+        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode>
+            secondChildBuilder = mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID);
+
+        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode>
+            firstGrandChildBuilder = mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
+                    FIRST_GRAND_CHILD_ID);
+        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode>
+            secondGrandChildBuilder = mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
+                    SECOND_GRAND_CHILD_ID);
 
         firstGrandChildBuilder
                 .withChild(