BUG-7159: eliminate use of CrossStatementSourceReactor 47/49747/5
authorRobert Varga <rovarga@cisco.com>
Thu, 22 Dec 2016 15:27:26 +0000 (16:27 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 5 Jan 2017 12:02:09 +0000 (12:02 +0000)
yang-test-util provides a convenient way to parse YANG files
into a SchemaContext, without relying on the internal layout
of the yang parser. Convert tests to use these utilities,
which simplifies test setup and allows the yang parser layout
to evolve without breaking the world.

Change-Id: Icbd0556b990ea9d5ff93c34330049a9683e04970
Signed-off-by: Robert Varga <rovarga@cisco.com>
29 files changed:
opendaylight/config/yang-jmx-generator-plugin/pom.xml
opendaylight/config/yang-jmx-generator/pom.xml
opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/AbstractYangTest.java
opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryNameConflictTest.java
opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/unknownextension/UnknownExtensionTest.java
opendaylight/md-sal/benchmark-data-store/pom.xml
opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/AbstractInMemoryBrokerWriteTransactionBenchmark.java
opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/AbstractInMemoryDatastoreWriteTransactionBenchmark.java
opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/BenchmarkModel.java
opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithSameThreadedExecutorBenchmark.java
opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWriteTransactionBenchmark.java
opendaylight/md-sal/sal-binding-broker/pom.xml
opendaylight/md-sal/sal-binding-dom-it/pom.xml
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/DOMRpcServiceTestBugfix560.java
opendaylight/md-sal/sal-cluster-admin-impl/pom.xml
opendaylight/md-sal/sal-clustering-commons/pom.xml
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java
opendaylight/md-sal/sal-distributed-datastore/pom.xml
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/CompositeModel.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/TestModel.java
opendaylight/md-sal/sal-dom-broker/pom.xml
opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestModel.java
opendaylight/md-sal/sal-dom-xsql/pom.xml
opendaylight/md-sal/sal-dom-xsql/src/test/java/org/opendaylight/xsql/test/XSQLTest.java
opendaylight/md-sal/sal-inmemory-datastore/pom.xml
opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestModel.java
opendaylight/md-sal/sal-remoterpc-connector/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/AbstractRpcTest.java

index 1cd9971..9eb171d 100644 (file)
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
+    </dependency>
+
   </dependencies>
 
 </project>
index e1b905f..dd1812c 100644 (file)
@@ -45,8 +45,7 @@
     </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-parser-impl</artifactId>
-      <scope>test</scope>
+      <artifactId>yang-test-util</artifactId>
     </dependency>
   </dependencies>
 
index fa99dea..eb5f70d 100644 (file)
@@ -27,8 +27,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-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 abstract class AbstractYangTest {
     protected SchemaContext context;
@@ -57,8 +56,7 @@ public abstract class AbstractYangTest {
 
         yangISs.addAll(getConfigApiYangInputStreams());
 
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        context = reactor.buildEffective(yangISs);
+        context = YangParserTestUtils.parseYangStreams(yangISs);
         // close ISs
         for (InputStream is : yangISs) {
             is.close();
@@ -81,11 +79,10 @@ public abstract class AbstractYangTest {
     }
 
     public static List<InputStream> getConfigApiYangInputStreams() {
-        return getStreams("/META-INF/yang/config.yang",
-                "/META-INF/yang/rpc-context.yang");
+        return getStreams("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang");
     }
 
-    public Map<QName, IdentitySchemaNode> mapIdentitiesByQNames(Module module) {
+    public Map<QName, IdentitySchemaNode> mapIdentitiesByQNames(final Module module) {
         Map<QName, IdentitySchemaNode> result = new HashMap<>();
         for (IdentitySchemaNode identitySchemaNode : module.getIdentities()) {
             QName qName = identitySchemaNode.getQName();
@@ -98,7 +95,7 @@ public abstract class AbstractYangTest {
         return result;
     }
 
-    protected static List<InputStream> getStreams(String... paths) {
+    protected static List<InputStream> getStreams(final String... paths) {
         List<InputStream> result = new ArrayList<>();
         for (String path : paths) {
             InputStream is = AbstractYangTest.class.getResourceAsStream(path);
@@ -108,12 +105,13 @@ public abstract class AbstractYangTest {
         return result;
     }
 
-    protected Map<QName, ServiceInterfaceEntry>  loadThreadsServiceInterfaceEntries(String packageName) {
+    protected Map<QName, ServiceInterfaceEntry>  loadThreadsServiceInterfaceEntries(final String packageName) {
         Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
         return ServiceInterfaceEntry.create(threadsModule, packageName,identitiesToSIs);
     }
 
-    protected Map<String /* identity local name */, ModuleMXBeanEntry> loadThreadsJava(Map<QName, ServiceInterfaceEntry> modulesToSIEs, String packageName) {
+    protected Map<String /* identity local name */, ModuleMXBeanEntry> loadThreadsJava(
+            final Map<QName, ServiceInterfaceEntry> modulesToSIEs, final String packageName) {
         Map<String /* identity local name */, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry
                 .create(threadsJavaModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl
                 (context)), packageName);
index e7f1025..2fc1be1 100644 (file)
@@ -23,10 +23,8 @@ import org.junit.Test;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.YangModelSearchUtils;
 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Module;
-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;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -105,13 +103,13 @@ public class ModuleMXBeanEntryNameConflictTest extends AbstractYangTest {
                 "port");
     }
 
-    private String getYangModuleName(String name) {
+    private static String getYangModuleName(final String name) {
         int startIndex = 0;
         int endIndex = name.indexOf(".yang");
         return name.substring(startIndex, endIndex);
     }
 
-    private Module loadYangs(File testedModule, String moduleName)
+    private Module loadYangs(final File testedModule, final String moduleName)
             throws Exception {
         List<InputStream> yangISs = new ArrayList<>();
         yangISs.addAll(getStreams("/ietf-inet-types.yang"));
@@ -120,8 +118,7 @@ public class ModuleMXBeanEntryNameConflictTest extends AbstractYangTest {
 
         yangISs.addAll(getConfigApiYangInputStreams());
 
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        context = reactor.buildEffective(yangISs);
+        context =  YangParserTestUtils.parseYangStreams(yangISs);
         // close ISs
         for (InputStream is : yangISs) {
             is.close();
index 3aee10b..85a0ef0 100644 (file)
@@ -17,8 +17,7 @@ import org.junit.Test;
 import org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants;
 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntryTest;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.YangModelSearchUtils;
-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 UnknownExtensionTest extends ServiceInterfaceEntryTest {
 
@@ -28,21 +27,16 @@ public class UnknownExtensionTest extends ServiceInterfaceEntryTest {
                 .getResourceAsStream("test-ifcWithUnknownExtension.yang"));
         yangISs.addAll(getConfigApiYangInputStreams());
         try {
-            final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-            context = reactor.buildEffective(yangISs);
-            namesToModules = YangModelSearchUtils.mapModulesByNames(context
-                    .getModules());
+            context = YangParserTestUtils.parseYangStreams(yangISs);
+            namesToModules = YangModelSearchUtils.mapModulesByNames(context.getModules());
             configModule = namesToModules.get(ConfigConstants.CONFIG_MODULE);
-            threadsModule = namesToModules
-                    .get(ConfigConstants.CONFIG_THREADS_MODULE);
+            threadsModule = namesToModules.get(ConfigConstants.CONFIG_THREADS_MODULE);
             try {
                 super.testCreateFromIdentities();
                 fail();
             } catch (IllegalStateException e) {
-                assertTrue(
-                        e.getMessage(),
-                        e.getMessage().startsWith(
-                                "Unexpected unknown schema node."));
+                assertTrue(e.getMessage(),
+                        e.getMessage().startsWith("Unexpected unknown schema node."));
             }
         } finally {
             for (InputStream is : yangISs) {
index d652dcb..8f704a9 100644 (file)
@@ -23,17 +23,15 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-data-impl</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-parser-impl</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.openjdk.jmh</groupId>
       <artifactId>jmh-core</artifactId>
+      <version>1.17.3</version>
     </dependency>
     <dependency>
       <groupId>org.openjdk.jmh</groupId>
       <artifactId>jmh-generator-annprocess</artifactId>
+      <version>1.17.3</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
@@ -44,8 +42,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <artifactId>sal-broker-impl</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-simple</artifactId>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
+      <scope>compile</scope>
     </dependency>
   </dependencies>
 
index c5f95f9..7424adc 100644 (file)
@@ -9,9 +9,12 @@ package org.opendaylight.controller.md.sal.dom.store.benchmark;
 
 import java.io.InputStream;
 import java.util.Collections;
+import java.util.List;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 /**
  * Benchmark Model class loads the odl-datastore-test.yang model from resources.
@@ -19,7 +22,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  * This class serves as facilitator class which holds several references to initialized yang model as static final
  * members.
  *
- * @author Lukas Sedlak <lsedlak@cisco.com>
+ * @author Lukas Sedlak
  */
 public final class BenchmarkModel {
 
@@ -40,12 +43,11 @@ public final class BenchmarkModel {
     }
 
     public static SchemaContext createTestContext() {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
         final SchemaContext schemaContext;
         final List<InputStream> streams = Collections.singletonList(getInputStream());
 
         try {
-            schemaContext = reactor.buildEffective(streams);
+            schemaContext = YangParserTestUtils.parseYangStreams(streams);
         } catch (ReactorException e) {
             throw new RuntimeException("Unable to build schema context from " + streams, e);
         }
index 1aa19b2..330c947 100644 (file)
@@ -26,7 +26,7 @@ import org.openjdk.jmh.annotations.OutputTimeUnit;
  * of benchmark creates InMemoryDataStore with Data Change Listener Executor Service as Blocking Bounded Fast Thread Pool
  * and DOM Store Executor Service as Same Thread Executor.
  *
- * @author Lukas Sedlak <lsedlak@cisco.com>
+ * @author Lukas Sedlak
  */
 @State(Scope.Thread)
 @BenchmarkMode(Mode.AverageTime)
index d697f3c..930ceaf 100644 (file)
@@ -25,7 +25,7 @@ import org.openjdk.jmh.annotations.TearDown;
  * of benchmark creates InMemoryDataStore with Data Change Listener Executor Service as Same Thread Executor
  * and DOM Store Executor Service as Same Thread Executor.
  *
- * @author Lukas Sedlak <lsedlak@cisco.com>
+ * @author Lukas Sedlak
  */
 @State(Scope.Thread)
 @BenchmarkMode(Mode.AverageTime)
index 1e53fe2..98bd490 100644 (file)
       <artifactId>truth</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-parser-impl</artifactId>
-      <scope>test</scope>
-    </dependency>
 
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 8df8ad5..3960fce 100644 (file)
@@ -41,8 +41,7 @@
     </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-parser-impl</artifactId>
-      <scope>test</scope>
+      <artifactId>yang-test-util</artifactId>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 791c540..e240b19 100644 (file)
@@ -45,8 +45,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-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;
 
 /**
  * Test case for reported bug 560
@@ -79,7 +78,7 @@ public class DOMRpcServiceTestBugfix560 {
     @Before
     public void setUp() throws Exception {
         final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
-        testFactory.setExecutor(MoreExecutors.sameThreadExecutor());
+        testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
         testFactory.setStartWithParsedSchema(true);
         testContext = testFactory.getTestContext();
 
@@ -94,8 +93,7 @@ public class DOMRpcServiceTestBugfix560 {
 
         assertNotNull(moduleStream);
         final List<InputStream> rpcModels = Collections.singletonList(moduleStream);
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        schemaContext = reactor.buildEffective(rpcModels);
+        schemaContext = YangParserTestUtils.parseYangStreams(rpcModels);
     }
 
     private static org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier createBITllIdentifier(
@@ -110,7 +108,7 @@ public class DOMRpcServiceTestBugfix560 {
     private static InstanceIdentifier<TopLevelList> createBATllIdentifier(
             final String mount) {
         return InstanceIdentifier.builder(Top.class)
-                .child(TopLevelList.class, new TopLevelListKey(mount)).toInstance();
+                .child(TopLevelList.class, new TopLevelListKey(mount)).build();
     }
 
     @Test
index 4b1b75d..8289b84 100644 (file)
       <version>1.5.0-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
+    </dependency>
 
     <!-- Akka -->
     <dependency>
index 5b79bff..815b9a6 100644 (file)
       <artifactId>slf4j-simple</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
+    </dependency>
 
     <!-- Apache -->
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-model-util</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-parser-impl</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>config-api</artifactId>
index bb572e3..770a2ff 100644 (file)
@@ -50,8 +50,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLe
 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 {
 
@@ -198,16 +197,12 @@ public class TestModel {
         return resolveSchemaContext(inputStreams);
     }
 
-    private static SchemaContext resolveSchemaContext(List<InputStream> streams) {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
-
+    private static SchemaContext resolveSchemaContext(final List<InputStream> streams) {
         try {
-            schemaContext = reactor.buildEffective(streams);
+            return YangParserTestUtils.parseYangStreams(streams);
         } catch (ReactorException e) {
             throw new RuntimeException("Unable to build schema context from " + streams, e);
         }
-        return schemaContext;
     }
 
     /**
@@ -227,8 +222,7 @@ public class TestModel {
      *
      * </pre>
      */
-    public static NormalizedNode<?, ?> createDocumentOne(
-            SchemaContext schemaContext) {
+    public static NormalizedNode<?, ?> createDocumentOne(final SchemaContext schemaContext) {
         return ImmutableContainerNodeBuilder
                 .create()
                 .withNodeIdentifier(
@@ -360,7 +354,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);
index b5f1f19..b32f042 100644 (file)
       <artifactId>commons-lang3</artifactId>
     </dependency>
 
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
index 48cace9..2b72099 100644 (file)
@@ -36,8 +36,7 @@ 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.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 CompositeModel {
 
@@ -132,15 +131,11 @@ public class CompositeModel {
         inputStreams.add(getDatastoreAugInputStream());
         inputStreams.add(getDatastoreTestNotificationInputStream());
 
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
-
         try {
-            schemaContext = reactor.buildEffective(inputStreams);
+            return YangParserTestUtils.parseYangStreams(inputStreams);
         } catch (ReactorException e) {
             throw new RuntimeException("Unable to build schema context from " + inputStreams, e);
         }
-        return schemaContext;
     }
 
     /**
@@ -159,7 +154,7 @@ public class CompositeModel {
      *
      * </pre>
      */
-    public static NormalizedNode<?, ?> createDocumentOne(SchemaContext schemaContext) {
+    public static NormalizedNode<?, ?> createDocumentOne(final SchemaContext schemaContext) {
         return ImmutableContainerNodeBuilder.create()
                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()))
                 .withChild(createTestContainer()).build();
index fd011d2..164f363 100644 (file)
@@ -8,19 +8,15 @@
 
 package org.opendaylight.controller.md.cluster.datastore.model;
 
-import com.google.common.io.ByteSource;
-import com.google.common.io.Resources;
+import com.google.common.base.Throwables;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 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 SchemaContextHelper {
 
@@ -36,42 +32,25 @@ public class SchemaContextHelper {
         return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
     }
 
-    public static SchemaContext select(String... schemaFiles) {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
-        List<InputStream> streams = new ArrayList<>();
+    public static SchemaContext select(final String... schemaFiles) {
+        List<InputStream> streams = new ArrayList<>(schemaFiles.length);
 
         for (String schemaFile : schemaFiles) {
             streams.add(getInputStream(schemaFile));
         }
 
         try {
-            schemaContext = reactor.buildEffective(streams);
+            return YangParserTestUtils.parseYangStreams(streams);
         } catch (ReactorException e) {
             throw new RuntimeException("Unable to build schema context from " + streams, e);
         }
-
-        return schemaContext;
     }
 
     public static SchemaContext entityOwners() {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
-        File file = null;
-
         try {
-            file = new File("src/main/yang/entity-owners.yang");
-            final List<ByteSource> sources = Arrays.asList(Resources.asByteSource(file.toURI().toURL()));
-            try {
-                schemaContext = reactor.buildEffective(sources);
-            } catch (IOException e1) {
-                throw new ExceptionInInitializerError(e1);
-            } catch (ReactorException e2) {
-                throw new RuntimeException("Unable to build schema context from " + sources, e2);
-            }
-            return schemaContext;
-        } catch (MalformedURLException e3) {
-            throw new RuntimeException("Malformed URL detected in " + file, e3);
+            return YangParserTestUtils.parseYangSources(new File("src/main/yang/entity-owners.yang"));
+        } catch (IOException | ReactorException e) {
+            throw Throwables.propagate(e);
         }
     }
 }
index 37cef64..48b7e9b 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.controller.md.cluster.datastore.model;
 
-import com.google.common.io.ByteSource;
 import com.google.common.io.Resources;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Collections;
-import java.util.Set;
+import java.util.List;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -24,8 +24,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNo
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 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 {
 
@@ -60,22 +59,23 @@ public class TestModel {
     public static final QName THREE_QNAME = QName.create(TEST_QNAME,"three");
 
     public static SchemaContext createTestContext() {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
-        final Set<ByteSource> sources = Collections
-                .singleton(Resources.asByteSource(TestModel.class.getResource(DATASTORE_TEST_YANG)));
+        final List<InputStream> sources;
 
         try {
-            schemaContext = reactor.buildEffective(sources);
+            sources = Collections.singletonList(
+                Resources.asByteSource(TestModel.class.getResource(DATASTORE_TEST_YANG)).openStream());
         } catch (IOException e1) {
             throw new ExceptionInInitializerError(e1);
-        }  catch (ReactorException e2) {
-            throw new RuntimeException("Unable to build schema context from " + sources, e2);
         }
-        return schemaContext;
+
+        try {
+            return YangParserTestUtils.parseYangStreams(sources);
+        }  catch (ReactorException e) {
+            throw new RuntimeException("Unable to build schema context from " + sources, e);
+        }
     }
 
-    public static DataContainerChild<?, ?> outerNode(int... ids) {
+    public static DataContainerChild<?, ?> outerNode(final int... ids) {
         CollectionNodeBuilder<MapEntryNode, MapNode> outer = ImmutableNodes.mapNodeBuilder(OUTER_LIST_QNAME);
         for (int id: ids) {
             outer.addChild(ImmutableNodes.mapEntry(OUTER_LIST_QNAME, ID_QNAME, id));
@@ -84,7 +84,7 @@ public class TestModel {
         return outer.build();
     }
 
-    public static DataContainerChild<?, ?> outerNode(MapEntryNode... entries) {
+    public static DataContainerChild<?, ?> outerNode(final MapEntryNode... entries) {
         CollectionNodeBuilder<MapEntryNode, MapNode> outer = ImmutableNodes.mapNodeBuilder(OUTER_LIST_QNAME);
         for (MapEntryNode e: entries) {
             outer.addChild(e);
@@ -93,7 +93,7 @@ public class TestModel {
         return outer.build();
     }
 
-    public static DataContainerChild<?, ?> innerNode(String... names) {
+    public static DataContainerChild<?, ?> innerNode(final String... names) {
         CollectionNodeBuilder<MapEntryNode, MapNode> outer = ImmutableNodes.mapNodeBuilder(INNER_LIST_QNAME);
         for (String name: names) {
             outer.addChild(ImmutableNodes.mapEntry(INNER_LIST_QNAME, NAME_QNAME, name));
@@ -102,32 +102,32 @@ public class TestModel {
         return outer.build();
     }
 
-    public static MapEntryNode outerNodeEntry(int id, DataContainerChild<?, ?> inner) {
+    public static MapEntryNode outerNodeEntry(final int id, final DataContainerChild<?, ?> inner) {
         return ImmutableNodes.mapEntryBuilder(OUTER_LIST_QNAME, ID_QNAME, id).addChild(inner).build();
     }
 
-    public static NormalizedNode<?, ?> testNodeWithOuter(int... ids) {
+    public static NormalizedNode<?, ?> testNodeWithOuter(final int... ids) {
         return testNodeWithOuter(outerNode(ids));
     }
 
-    public static NormalizedNode<?, ?> testNodeWithOuter(DataContainerChild<?, ?> outer) {
+    public static NormalizedNode<?, ?> testNodeWithOuter(final DataContainerChild<?, ?> outer) {
         return ImmutableContainerNodeBuilder.create().withNodeIdentifier(
                 new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outer).build();
     }
 
-    public static NodeIdentifierWithPredicates outerEntryKey(int id) {
+    public static NodeIdentifierWithPredicates outerEntryKey(final int id) {
         return new NodeIdentifierWithPredicates(OUTER_LIST_QNAME, ID_QNAME, id);
     }
 
-    public static YangInstanceIdentifier outerEntryPath(int id) {
+    public static YangInstanceIdentifier outerEntryPath(final int id) {
         return OUTER_LIST_PATH.node(outerEntryKey(id));
     }
 
-    public static NodeIdentifierWithPredicates innerEntryKey(String name) {
+    public static NodeIdentifierWithPredicates innerEntryKey(final String name) {
         return new NodeIdentifierWithPredicates(INNER_LIST_QNAME, NAME_QNAME, name);
     }
 
-    public static YangInstanceIdentifier innerEntryPath(int id, String name) {
+    public static YangInstanceIdentifier innerEntryPath(final int id, final String name) {
         return OUTER_LIST_PATH.node(outerEntryKey(id)).node(INNER_LIST_QNAME).node(innerEntryKey(name));
     }
 }
index 2179667..9ac51a4 100644 (file)
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-data-impl</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-parser-impl</artifactId>
-    </dependency>
 
     <dependency>
       <groupId>junit</groupId>
       <artifactId>slf4j-simple</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
index 5013b46..563b7ce 100644 (file)
@@ -14,8 +14,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 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 {
 
@@ -42,15 +41,12 @@ public class TestModel {
     }
 
     public static SchemaContext createTestContext() {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
         final List<InputStream> streams = Collections.singletonList(getInputStream());
 
         try {
-            schemaContext = reactor.buildEffective(streams);
+            return YangParserTestUtils.parseYangStreams(streams);
         } catch (ReactorException e) {
             throw new RuntimeException("Unable to build schema context from " + streams, e);
         }
-        return schemaContext;
     }
 }
index 7885f5e..87e4000 100644 (file)
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
+    </dependency>
   </dependencies>
 
   <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:XSQL</url>
index d96769b..eccdab3 100644 (file)
@@ -22,9 +22,9 @@ import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCResultSet;
 import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCServer;
 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;
 
+@Deprecated
 public class XSQLTest {
     private static final String DATASTORE_TEST_YANG = "/sal-persisted-dom-test.yang";
     private XSQLBluePrint bluePrint = null;
@@ -114,7 +114,7 @@ public class XSQLTest {
         }
     }
 
-    private static void parseTables(String sql,XSQLBluePrint bp,JDBCResultSet rs){
+    private static void parseTables(final String sql,final XSQLBluePrint bp,final JDBCResultSet rs){
         try{
             JDBCServer.parseTables(rs, bp);
             log("Test Table parsing of \""+sql+"\" Passed!");
@@ -170,7 +170,7 @@ public class XSQLTest {
         }
     }
 
-    private static void parseFields(String sql,XSQLBluePrint bp,JDBCResultSet rs){
+    private static void parseFields(final String sql,final XSQLBluePrint bp,final JDBCResultSet rs){
         try{
             JDBCServer.parseFields(rs, bp);
             log("Test Fields parsing of \""+sql+"\" Passed!");
@@ -182,7 +182,7 @@ public class XSQLTest {
         }
     }
 
-    private static void log(String str) {
+    private static void log(final String str) {
         System.out.print("*** XSQL Tests -");
         System.out.println(str);
     }
@@ -192,15 +192,12 @@ public class XSQLTest {
     }
 
     public static SchemaContext createTestContext() {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
         final List<InputStream> streams = Collections.singletonList(getInputStream());
 
         try {
-            schemaContext = reactor.buildEffective(streams);
+            return YangParserTestUtils.parseYangStreams(streams);
         } catch (ReactorException e) {
             throw new RuntimeException("Unable to build schema context from " + streams, e);
         }
-        return schemaContext;
     }
 }
index af10f62..727ef22 100644 (file)
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-data-impl</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-parser-impl</artifactId>
-    </dependency>
 
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-test-model</artifactId>
       <scope>test</scope>
-      </dependency>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
index 247f4b2..e3aea1c 100644 (file)
@@ -14,8 +14,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 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 {
 
@@ -39,15 +38,12 @@ public class TestModel {
     }
 
     public static SchemaContext createTestContext() {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final SchemaContext schemaContext;
         final List<InputStream> streams = Collections.singletonList(getInputStream());
 
         try {
-            schemaContext = reactor.buildEffective(streams);
+            return YangParserTestUtils.parseYangStreams(streams);
         } catch (ReactorException e) {
             throw new RuntimeException("Unable to build schema context from " + streams, e);
         }
-        return schemaContext;
     }
 }
index c8251ef..260aa36 100644 (file)
             <artifactId>slf4j-simple</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-parser-impl</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>com.google.collections</groupId>
             <artifactId>google-collections</artifactId>
             <version>1.0</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-test-util</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
index afe351f..02dd857 100644 (file)
@@ -16,13 +16,11 @@ import static org.junit.Assert.assertTrue;
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.testkit.JavaTestKit;
-import com.google.common.collect.Lists;
-import com.google.common.io.ByteSource;
-import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -44,8 +42,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 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;
 
 /**
  * Base class for RPC tests.
@@ -102,18 +99,11 @@ public class AbstractRpcTest {
 
     @Before
     public void setUp() throws Exception {
-        final ByteSource byteSource = new ByteSource() {
-            @Override
-            public InputStream openStream() throws IOException {
-                return AbstractRpcTest.this.getClass().getResourceAsStream("/test-rpc.yang");
-            }
-        };
-
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        final ArrayList<ByteSource> sources = Lists.newArrayList(byteSource);
+        final List<InputStream> sources = Collections.singletonList(
+            AbstractRpcTest.this.getClass().getResourceAsStream("/test-rpc.yang"));
 
         try {
-            schemaContext = reactor.buildEffective(sources);
+            schemaContext = YangParserTestUtils.parseYangStreams(sources);
         } catch (ReactorException e) {
             throw new RuntimeException("Unable to build schema context from " + sources, e);
         }

©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.