Get rid of old Yang Parser in Controller
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / md / cluster / datastore / model / CompositeModel.java
index ece312752d83164e845bce5e4e674499bdc3fd47..fe2aed77806b09bc2c5d481ecd4a054a46101986 100644 (file)
@@ -1,5 +1,22 @@
+/*
+ * Copyright (c) 2014, 2015 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.md.cluster.datastore.model;
 
+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 java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
@@ -17,19 +34,10 @@ 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.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-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 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;
 
 public class CompositeModel {
 
@@ -41,6 +49,8 @@ public class CompositeModel {
       "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:aug",
       "2014-03-13", "name");
 
+  public static final QName AUG_CONTAINER = QName.create(AUG_QNAME, "aug-container");
+  public static final QName AUG_INNER_CONTAINER = QName.create(AUG_QNAME, "aug-inner-container");
   public static final QName DESC_QNAME = QName.create(TEST_QNAME, "desc");
   public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME,
       "outer-list");
@@ -205,7 +215,7 @@ public class CompositeModel {
   }
 
   private static InputStream getInputStream(final String resourceName) {
-    return TestModel.class.getResourceAsStream(resourceName);
+    return CompositeModel.class.getResourceAsStream(resourceName);
   }
 
   public static SchemaContext createTestContext() {
@@ -214,9 +224,15 @@ public class CompositeModel {
     inputStreams.add(getDatastoreAugInputStream());
     inputStreams.add(getDatastoreTestNotificationInputStream());
 
-    YangParserImpl parser = new YangParserImpl();
-    Set<Module> modules = parser.parseYangModelsFromStreams(inputStreams);
-    return parser.resolveSchemaContext(modules);
+    final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+    final SchemaContext schemaContext;
+
+    try {
+      schemaContext = reactor.buildEffective(inputStreams);
+    } catch (ReactorException e) {
+        throw new RuntimeException("Unable to build schema context from " + inputStreams, e);
+    }
+    return schemaContext;
   }
 
   /**
@@ -254,13 +270,13 @@ public class CompositeModel {
         ImmutableLeafSetEntryNodeBuilder
             .create()
             .withNodeIdentifier(
-                new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
+                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,
+                new YangInstanceIdentifier.NodeWithValue<>(QName.create(TEST_QNAME,
                     "shoe"), "puma")).withValue("puma").build();
     final LeafSetNode<Object> shoes =
         ImmutableLeafSetNodeBuilder
@@ -274,13 +290,13 @@ public class CompositeModel {
         ImmutableLeafSetEntryNodeBuilder
             .create()
             .withNodeIdentifier(
-                (new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
+                (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,
+                (new YangInstanceIdentifier.NodeWithValue<>(QName.create(TEST_QNAME,
                     "number"), 15))).withValue(15).build();
     final LeafSetNode<Object> numbers =
         ImmutableLeafSetNodeBuilder
@@ -293,7 +309,7 @@ public class CompositeModel {
     Set<QName> childAugmentations = new HashSet<>();
     childAugmentations.add(AUG_QNAME);
     final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier =
-        new YangInstanceIdentifier.AugmentationIdentifier(null, childAugmentations);
+        new YangInstanceIdentifier.AugmentationIdentifier(childAugmentations);
     final AugmentationNode augmentationNode =
         Builders.augmentationBuilder()
             .withNodeIdentifier(augmentationIdentifier)