Fix config-manager activator
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / test / java / org / opendaylight / controller / cluster / datastore / util / TestModel.java
index 9f6e2d1f453b9e691733450266d7a7468e52cd3f..3eeb06f93ca6cead53174dac1cd4f436b15fd46f 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ *
+ *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ *  This program and the accompanying materials are made available under the
+ *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ *  and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ */
+
 package org.opendaylight.controller.cluster.datastore.util;
 
 import org.opendaylight.yangtools.yang.common.QName;
@@ -17,6 +27,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContaine
 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;
@@ -37,11 +48,27 @@ public class TestModel {
       "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test",
       "2014-03-13", "test");
 
-  public static final QName AUG_QNAME = QName.create(
+  public static final QName AUG_NAME_QNAME = QName.create(
       "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:aug",
       "2014-03-13", "name");
 
+  public static final QName AUG_CONT_QNAME = QName.create(
+      "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:aug",
+      "2014-03-13", "cont");
+
+
   public static final QName DESC_QNAME = QName.create(TEST_QNAME, "desc");
+  public static final QName POINTER_QNAME = QName.create(TEST_QNAME, "pointer");
+  public static final QName SOME_REF_QNAME = QName.create(TEST_QNAME,
+      "some-ref");
+  public static final QName MYIDENTITY_QNAME = QName.create(TEST_QNAME,
+      "myidentity");
+  public static final QName SWITCH_FEATURES_QNAME = QName.create(TEST_QNAME,
+      "switch-features");
+
+  public static final QName AUGMENTED_LIST_QNAME = QName.create(TEST_QNAME,
+      "augmented-list");
+
   public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME,
       "outer-list");
   public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME,
@@ -62,8 +89,8 @@ public class TestModel {
       .of(TEST_QNAME);
   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 YangInstanceIdentifier OUTER_LIST_PATH =
+      YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
   public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two");
   public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three");
 
@@ -92,12 +119,12 @@ public class TestModel {
   public static final QName GRAND_CHILD_NAME_QNAME = QName.create(FAMILY_QNAME,
       "grand-child-name");
 
-  public static final YangInstanceIdentifier FAMILY_PATH = YangInstanceIdentifier
-      .of(FAMILY_QNAME);
-  public static final YangInstanceIdentifier FAMILY_DESC_PATH = YangInstanceIdentifier
-      .builder(FAMILY_PATH).node(DESC_QNAME).build();
-  public static final YangInstanceIdentifier CHILDREN_PATH = YangInstanceIdentifier
-      .builder(FAMILY_PATH).node(CHILDREN_QNAME).build();
+  public static final YangInstanceIdentifier FAMILY_PATH =
+      YangInstanceIdentifier.of(FAMILY_QNAME);
+  public static final YangInstanceIdentifier FAMILY_DESC_PATH =
+      YangInstanceIdentifier.builder(FAMILY_PATH).node(DESC_QNAME).build();
+  public static final YangInstanceIdentifier CHILDREN_PATH =
+      YangInstanceIdentifier.builder(FAMILY_PATH).node(CHILDREN_QNAME).build();
 
   private static final Integer FIRST_CHILD_ID = 1;
   private static final Integer SECOND_CHILD_ID = 2;
@@ -112,19 +139,19 @@ public class TestModel {
   private static final String SECOND_GRAND_CHILD_NAME = "second grand child";
 
   // first child
-  private static final YangInstanceIdentifier CHILDREN_1_PATH = YangInstanceIdentifier
-      .builder(CHILDREN_PATH)
-      .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID) //
-      .build();
+  private static final YangInstanceIdentifier CHILDREN_1_PATH =
+      YangInstanceIdentifier.builder(CHILDREN_PATH)
+          .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID) //
+          .build();
   private static final YangInstanceIdentifier CHILDREN_1_NAME_PATH =
       YangInstanceIdentifier.builder(CHILDREN_PATH)
           .nodeWithKey(CHILDREN_QNAME, CHILD_NAME_QNAME, FIRST_CHILD_NAME) //
           .build();
 
-  private static final YangInstanceIdentifier CHILDREN_2_PATH = YangInstanceIdentifier
-      .builder(CHILDREN_PATH)
-      .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID) //
-      .build();
+  private static final YangInstanceIdentifier CHILDREN_2_PATH =
+      YangInstanceIdentifier.builder(CHILDREN_PATH)
+          .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID) //
+          .build();
   private static final YangInstanceIdentifier CHILDREN_2_NAME_PATH =
       YangInstanceIdentifier.builder(CHILDREN_PATH)
           .nodeWithKey(CHILDREN_QNAME, CHILD_NAME_QNAME, SECOND_CHILD_NAME) //
@@ -132,7 +159,8 @@ public class TestModel {
 
 
   private static final YangInstanceIdentifier GRAND_CHILD_1_PATH =
-      YangInstanceIdentifier.builder(CHILDREN_1_PATH)
+      YangInstanceIdentifier
+          .builder(CHILDREN_1_PATH)
           .node(GRAND_CHILDREN_QNAME)
           //
           .nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
@@ -140,7 +168,8 @@ public class TestModel {
           .build();
 
   private static final YangInstanceIdentifier GRAND_CHILD_1_NAME_PATH =
-      YangInstanceIdentifier.builder(CHILDREN_1_PATH)
+      YangInstanceIdentifier
+          .builder(CHILDREN_1_PATH)
           .node(GRAND_CHILDREN_QNAME)
           //
           .nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NAME_QNAME,
@@ -148,7 +177,8 @@ public class TestModel {
           .build();
 
   private static final YangInstanceIdentifier GRAND_CHILD_2_PATH =
-      YangInstanceIdentifier.builder(CHILDREN_2_PATH)
+      YangInstanceIdentifier
+          .builder(CHILDREN_2_PATH)
           .node(GRAND_CHILDREN_QNAME)
           //
           .nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
@@ -156,15 +186,16 @@ public class TestModel {
           .build();
 
   private static final YangInstanceIdentifier GRAND_CHILD_2_NAME_PATH =
-      YangInstanceIdentifier.builder(CHILDREN_2_PATH)
+      YangInstanceIdentifier
+          .builder(CHILDREN_2_PATH)
           .node(GRAND_CHILDREN_QNAME)
           //
           .nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NAME_QNAME,
               SECOND_GRAND_CHILD_NAME) //
           .build();
 
-  private static final YangInstanceIdentifier DESC_PATH_ID = YangInstanceIdentifier
-      .builder(DESC_PATH).build();
+  private static final YangInstanceIdentifier DESC_PATH_ID =
+      YangInstanceIdentifier.builder(DESC_PATH).build();
   private static final YangInstanceIdentifier OUTER_LIST_1_PATH =
       YangInstanceIdentifier.builder(OUTER_LIST_PATH)
           .nodeWithKey(OUTER_LIST_QNAME, ID_QNAME, ONE_ID) //
@@ -175,10 +206,10 @@ public class TestModel {
           .nodeWithKey(OUTER_LIST_QNAME, ID_QNAME, TWO_ID) //
           .build();
 
-  private static final YangInstanceIdentifier TWO_TWO_PATH = YangInstanceIdentifier
-      .builder(OUTER_LIST_2_PATH).node(INNER_LIST_QNAME) //
-      .nodeWithKey(INNER_LIST_QNAME, NAME_QNAME, TWO_TWO_NAME) //
-      .build();
+  private static final YangInstanceIdentifier TWO_TWO_PATH =
+      YangInstanceIdentifier.builder(OUTER_LIST_2_PATH).node(INNER_LIST_QNAME) //
+          .nodeWithKey(INNER_LIST_QNAME, NAME_QNAME, TWO_TWO_NAME) //
+          .build();
 
   private static final YangInstanceIdentifier TWO_TWO_VALUE_PATH =
       YangInstanceIdentifier.builder(TWO_TWO_PATH).node(VALUE_QNAME) //
@@ -221,6 +252,7 @@ public class TestModel {
 
   /**
    * Returns a test document
+   * <p/>
    *
    * <pre>
    * test
@@ -250,62 +282,98 @@ public class TestModel {
   public static ContainerNode createTestContainer() {
 
 
+    // Create a list of shoes
+    // This is to test leaf list entry
     final LeafSetEntryNode<Object> nike =
         ImmutableLeafSetEntryNodeBuilder
             .create()
             .withNodeIdentifier(
-                new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
-                    "shoe"), "nike")).withValue("nike").build();
+                new YangInstanceIdentifier.NodeWithValue(QName.create(
+                    TEST_QNAME, "shoe"), "nike")).withValue("nike").build();
+
     final LeafSetEntryNode<Object> puma =
         ImmutableLeafSetEntryNodeBuilder
             .create()
             .withNodeIdentifier(
-                new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
-                    "shoe"), "puma")).withValue("puma").build();
+                new YangInstanceIdentifier.NodeWithValue(QName.create(
+                    TEST_QNAME, "shoe"), "puma")).withValue("puma").build();
+
     final LeafSetNode<Object> shoes =
         ImmutableLeafSetNodeBuilder
             .create()
             .withNodeIdentifier(
-                new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_QNAME,
-                    "shoe"))).withChild(nike).withChild(puma).build();
+                new YangInstanceIdentifier.NodeIdentifier(QName.create(
+                    TEST_QNAME, "shoe"))).withChild(nike).withChild(puma)
+            .build();
+
+
+    // Test a leaf-list where each entry contains an identity
+    final LeafSetEntryNode<Object> cap1 =
+        ImmutableLeafSetEntryNodeBuilder
+            .create()
+            .withNodeIdentifier(
+                new YangInstanceIdentifier.NodeWithValue(QName.create(
+                    TEST_QNAME, "capability"), DESC_QNAME))
+            .withValue(DESC_QNAME).build();
+
+    final LeafSetNode<Object> capabilities =
+        ImmutableLeafSetNodeBuilder
+            .create()
+            .withNodeIdentifier(
+                new YangInstanceIdentifier.NodeIdentifier(QName.create(
+                    TEST_QNAME, "capability"))).withChild(cap1).build();
 
+    ContainerNode switchFeatures =
+        ImmutableContainerNodeBuilder
+            .create()
+            .withNodeIdentifier(
+                new YangInstanceIdentifier.NodeIdentifier(SWITCH_FEATURES_QNAME))
+            .withChild(capabilities).build();
 
+    // Create a leaf list with numbers
     final LeafSetEntryNode<Object> five =
         ImmutableLeafSetEntryNodeBuilder
             .create()
             .withNodeIdentifier(
-                (new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
-                    "number"), 5))).withValue(5).build();
+                (new YangInstanceIdentifier.NodeWithValue(QName.create(
+                    TEST_QNAME, "number"), 5))).withValue(5).build();
     final LeafSetEntryNode<Object> fifteen =
         ImmutableLeafSetEntryNodeBuilder
             .create()
             .withNodeIdentifier(
-                (new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
-                    "number"), 15))).withValue(15).build();
+                (new YangInstanceIdentifier.NodeWithValue(QName.create(
+                    TEST_QNAME, "number"), 15))).withValue(15).build();
     final LeafSetNode<Object> numbers =
         ImmutableLeafSetNodeBuilder
             .create()
             .withNodeIdentifier(
-                new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_QNAME,
-                    "number"))).withChild(five).withChild(fifteen).build();
+                new YangInstanceIdentifier.NodeIdentifier(QName.create(
+                    TEST_QNAME, "number"))).withChild(five).withChild(fifteen)
+            .build();
 
 
-    Set<QName> childAugmentations = new HashSet<>();
-    childAugmentations.add(AUG_QNAME);
-    final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier =
-        new YangInstanceIdentifier.AugmentationIdentifier(null, childAugmentations);
-    final AugmentationNode augmentationNode =
-        Builders.augmentationBuilder()
-            .withNodeIdentifier(augmentationIdentifier)
-            .withChild(ImmutableNodes.leafNode(AUG_QNAME, "First Test"))
-            .build();
+    // Create augmentations
+    MapEntryNode mapEntry = createAugmentedListEntry(1, "First Test");
+
+
+    // Create the document
     return ImmutableContainerNodeBuilder
         .create()
-        .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME))
+        .withNodeIdentifier(
+            new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME))
         .withChild(ImmutableNodes.leafNode(DESC_QNAME, DESC))
-        .withChild(augmentationNode)
+        .withChild(ImmutableNodes.leafNode(POINTER_QNAME, "pointer"))
+        .withChild(
+            ImmutableNodes.leafNode(SOME_REF_QNAME, YangInstanceIdentifier
+                .builder().build()))
+        .withChild(ImmutableNodes.leafNode(MYIDENTITY_QNAME, DESC_QNAME))
+
+        // .withChild(augmentationNode)
         .withChild(shoes)
         .withChild(numbers)
+        .withChild(switchFeatures)
+        .withChild(
+            mapNodeBuilder(AUGMENTED_LIST_QNAME).withChild(mapEntry).build())
         .withChild(
             mapNodeBuilder(OUTER_LIST_QNAME)
                 .withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID))
@@ -313,6 +381,36 @@ public class TestModel {
 
   }
 
+  public static MapEntryNode createAugmentedListEntry(int id, String name) {
+
+    Set<QName> childAugmentations = new HashSet<>();
+    childAugmentations.add(AUG_CONT_QNAME);
+
+    ContainerNode augCont =
+        ImmutableContainerNodeBuilder
+            .create()
+            .withNodeIdentifier(
+                new YangInstanceIdentifier.NodeIdentifier(AUG_CONT_QNAME))
+            .withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name)).build();
+
+
+    final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier =
+        new YangInstanceIdentifier.AugmentationIdentifier(childAugmentations);
+
+    final AugmentationNode augmentationNode =
+        Builders.augmentationBuilder()
+            .withNodeIdentifier(augmentationIdentifier).withChild(augCont)
+            .build();
+
+    return ImmutableMapEntryNodeBuilder
+        .create()
+        .withNodeIdentifier(
+            new YangInstanceIdentifier.NodeIdentifierWithPredicates(
+                AUGMENTED_LIST_QNAME, ID_QNAME, id))
+        .withChild(ImmutableNodes.leafNode(ID_QNAME, id))
+        .withChild(augmentationNode).build();
+  }
+
 
   public static ContainerNode createFamily() {
     final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> familyContainerBuilder =
@@ -338,8 +436,8 @@ public class TestModel {
         .withChild(
             ImmutableNodes.leafNode(GRAND_CHILD_NUMBER_QNAME,
                 FIRST_GRAND_CHILD_ID)).withChild(
-        ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME,
-            FIRST_GRAND_CHILD_NAME));
+            ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME,
+                FIRST_GRAND_CHILD_NAME));
 
     secondGrandChildBuilder.withChild(
         ImmutableNodes