Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / util / TestModel.java
index e1607c0..72b8a3b 100644 (file)
@@ -17,10 +17,8 @@ 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;
@@ -49,11 +47,9 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLe
 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.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+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",
@@ -103,10 +99,9 @@ public class TestModel {
     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");
@@ -118,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");
@@ -158,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);
     }
 
@@ -175,44 +173,21 @@ public class TestModel {
     }
 
     public static SchemaContext createTestContext() {
-        List<InputStream> inputStreams = new ArrayList<>();
-        inputStreams.add(getDatastoreTestInputStream());
-        inputStreams.add(getDatastoreAugInputStream());
-        inputStreams.add(getDatastoreTestNotificationInputStream());
-
-        return resolveSchemaContext(inputStreams);
+        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());
-
-        return resolveSchemaContext(inputStreams);
+        return YangParserTestUtils.parseYangResource(DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
-
     public static SchemaContext createTestContextWithoutAugmentationSchema() {
-        List<InputStream> inputStreams = new ArrayList<>();
-        inputStreams.add(getDatastoreTestInputStream());
-        inputStreams.add(getDatastoreTestNotificationInputStream());
-
-        return resolveSchemaContext(inputStreams);
-    }
-
-    private static SchemaContext resolveSchemaContext(List<InputStream> streams) {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
-
-        try {
-            schemaContext = reactor.buildEffective(streams);
-        } catch (ReactorException e) {
-            throw new RuntimeException("Unable to build schema context from " + streams, e);
-        }
-        return schemaContext;
+        return YangParserTestUtils.parseYangResources(TestModel.class, DATASTORE_TEST_YANG,
+            DATASTORE_TEST_NOTIFICATION_YANG);
     }
 
     /**
-     * Returns a test document
+     * Returns a test document.
      * <p/>
      * <p/>
      * <pre>
@@ -227,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(
@@ -280,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()
@@ -308,8 +280,8 @@ public class TestModel {
 
         // 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(
@@ -343,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)
@@ -362,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);
@@ -394,24 +367,24 @@ public class TestModel {
 
 
     public static ContainerNode createFamily() {
-        final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> familyContainerBuilder =
-                ImmutableContainerNodeBuilder.create().withNodeIdentifier(
+        final DataContainerNodeAttrBuilder<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(

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.