BUG-7435: eliminate use of yang-parser-impl internals 50/49750/4
authorRobert Varga <rovarga@cisco.com>
Thu, 22 Dec 2016 18:08:41 +0000 (19:08 +0100)
committerMartin Ciglan <mciglan@cisco.com>
Wed, 4 Jan 2017 12:06:15 +0000 (13:06 +0100)
Switch to using YangParserTestUtil instead.

Change-Id: I98e0870051e42372adf7d7284b10b368e68516f6
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/mdsal-binding-generator-impl/pom.xml
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/Bug6135Test.java
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/Bug4621.java
binding2/mdsal-binding2-generator-impl/pom.xml
binding2/mdsal-binding2-generator-impl/src/main/test/java/org/opendaylight/mdsal/binding2/TestUtils.java [deleted file]
binding2/mdsal-binding2-generator-impl/src/main/test/java/org/opendaylight/mdsal/binding2/YangTemplateTest.java
dom/mdsal-dom-broker/pom.xml
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/util/TestModel.java
dom/mdsal-dom-inmemory-datastore/pom.xml
dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestModel.java

index 1d2d7f81603ef761d948236d084a8fba1f9bc6b9..1bb6354de5dd9bf6735a629404f77b8629aa9dca 100644 (file)
             <artifactId>javassist</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-parser-impl</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-data-impl</artifactId>
index 52b35607cd941cc86c37fbfba2593cbeaa8f2fab..cc1f05f6efd0df04e6d08a7942a0a3c3e9080a09 100644 (file)
@@ -12,8 +12,10 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import com.google.common.collect.ImmutableList;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URISyntaxException;
 import java.util.List;
 import org.junit.Test;
@@ -21,37 +23,19 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
 import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class BindingGeneratorImplTest {
 
-    private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20131021 = new YangStatementSourceImpl(
-            "/isis-topology/network-topology@2013-10-21.yang", false);
-
-    private static final YangStatementSourceImpl ISIS_20131021 = new YangStatementSourceImpl(
-            "/isis-topology/isis-topology@2013-10-21.yang", false);
-
-    private static final YangStatementSourceImpl L3_20131021 = new YangStatementSourceImpl(
-            "/isis-topology/l3-unicast-igp-topology@2013-10-21.yang", false);
-
     @Test
     public void isisTotpologyStatementParserTest() throws IOException,
-            YangSyntaxErrorException, URISyntaxException, SourceException,
-            ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-
-        reactor.addSources(ISIS_20131021, L3_20131021,
-                NETWORK_TOPOLOGY_20131021);
+            URISyntaxException, ReactorException {
+        final InputStream topo = getClass().getResourceAsStream("/isis-topology/network-topology@2013-10-21.yang");
+        final InputStream isis = getClass().getResourceAsStream("/isis-topology/isis-topology@2013-10-21.yang");
+        final InputStream l3 = getClass().getResourceAsStream("/isis-topology/l3-unicast-igp-topology@2013-10-21.yang");
 
-        EffectiveSchemaContext context = reactor.buildEffective();
+        SchemaContext context = YangParserTestUtils.parseYangStreams(ImmutableList.of(isis, l3, topo));
         assertNotNull(context);
 
         List<Type> generateTypes = new BindingGeneratorImpl(false)
@@ -62,7 +46,7 @@ public class BindingGeneratorImplTest {
 
     @Test
     public void choiceNodeGenerationTest() throws IOException,
-            YangSyntaxErrorException, URISyntaxException, SourceException, ReactorException {
+            URISyntaxException, ReactorException {
         File resourceFile = new File(getClass().getResource(
                 "/binding-generator-impl-test/choice-test.yang").toURI());
 
@@ -159,8 +143,7 @@ public class BindingGeneratorImplTest {
     }
 
     @Test
-    public void notificationGenerationTest() throws IOException,
-            YangSyntaxErrorException, URISyntaxException, SourceException, ReactorException {
+    public void notificationGenerationTest() throws IOException, URISyntaxException, ReactorException {
         File resourceFile = new File(getClass().getResource(
                 "/binding-generator-impl-test/notification-test.yang").toURI());
 
index 8024f377a8b40c892dc126c3b8a15f513c3a032e..963bb83a126467cdc0cafdb6cd95591550b80dd5 100644 (file)
@@ -11,27 +11,24 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
 import java.util.List;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
 import org.opendaylight.yangtools.sal.binding.model.api.Type;
+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.parser.stmt.rfc6020.YangStatementSourceImpl;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class Bug6135Test {
 
     @Ignore
     @Test
-    public void bug6135Test() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSource(new YangStatementSourceImpl("/bug-6135/foo.yang", false));
-
-        final EffectiveSchemaContext context = reactor.buildEffective();
+    public void bug6135Test() throws FileNotFoundException, ReactorException, URISyntaxException {
+        final SchemaContext context = YangParserTestUtils.parseYangSource("/bug-6135/foo.yang");
         assertNotNull(context);
 
         final List<Type> generateTypes = new BindingGeneratorImpl(false).generateTypes(context);
index c3e98fb964e0211cd28fc54f686b2f197bc5824b..bac2e6ea23cc45c5d8530c2d0a669b79de40a3c7 100644 (file)
@@ -10,12 +10,12 @@ package org.opendaylight.yangtools.sal.binding.yang.types;
 import static org.junit.Assert.assertNotNull;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
@@ -24,9 +24,7 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 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.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class Bug4621 {
 
@@ -34,13 +32,10 @@ public class Bug4621 {
     public ExpectedException expectedEx = ExpectedException.none();
 
     @Test
-    public void bug4621test() throws ReactorException, URISyntaxException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
+    public void bug4621test() throws FileNotFoundException, ReactorException, URISyntaxException {
         File file = new File(getClass().getResource("/bug-4621/foo.yang").toURI());
-        reactor.addSource(new YangStatementSourceImpl(file.getPath(), true));
 
-        final SchemaContext schemaContext = reactor.buildEffective();
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(file);
         final Module moduleValid = schemaContext.findModuleByNamespace(new URI("foo")).iterator().next();
         final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
 
@@ -52,7 +47,6 @@ public class Bug4621 {
                 .getDataChildByName(leafrefNode);
         LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
         TypeDefinition<?> leafTypeRel = leafRel.getType();
-        Type leafrefRelResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel);
-        assertNotNull(leafrefRelResolvedType);
+        assertNotNull(typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel));
     }
 }
\ No newline at end of file
index da2d9ca7f840f1ebda9e68f9fbc38691a8a3fff2..74076b1660925a76a6a3f5325a74d24b2fcb80c0 100644 (file)
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-data-impl</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-test-util</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>mdsal-binding2-generator-api</artifactId>
diff --git a/binding2/mdsal-binding2-generator-impl/src/main/test/java/org/opendaylight/mdsal/binding2/TestUtils.java b/binding2/mdsal-binding2-generator-impl/src/main/test/java/org/opendaylight/mdsal/binding2/TestUtils.java
deleted file mode 100644 (file)
index bd3c545..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2016 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.mdsal.binding2;
-
-import com.google.common.annotations.Beta;
-import java.io.File;
-import java.net.URI;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Beta
-public final class TestUtils {
-
-    private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class);
-
-    private TestUtils() {
-        throw new UnsupportedOperationException("Utility class");
-    }
-
-    public static Set<Module> loadModules(final URI resourceDirectory)
-            throws SourceException, ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        File[] files = new File(resourceDirectory).listFiles();
-
-        for (File file : files) {
-            if (file.getName().endsWith(".yang")) {
-                addSources(reactor, new YangStatementSourceImpl(file.getPath(), true));
-            } else {
-                LOG.info("Ignoring non-yang file {}", file);
-            }
-        }
-
-        EffectiveSchemaContext ctx = reactor.buildEffective();
-        return ctx.getModules();
-    }
-
-    private static void addSources(final CrossSourceStatementReactor.BuildAction reactor,
-        final YangStatementSourceImpl... sources) {
-        for (YangStatementSourceImpl source : sources) {
-            reactor.addSource(source);
-        }
-    }
-}
index e473f01d6f70ab73f69974c9cccd13c2149f863d..96f05fb95364aae09cc9ef5062dde556cff8c2bd 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.mdsal.binding2;
 
 import com.google.common.annotations.Beta;
+import java.io.FileNotFoundException;
 import java.net.URISyntaxException;
 import java.util.Set;
 import org.junit.Before;
@@ -19,6 +20,7 @@ import org.opendaylight.mdsal.binding2.txt.yangTemplateForNodes;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 @Beta
 public class YangTemplateTest {
@@ -26,8 +28,8 @@ public class YangTemplateTest {
     private Set<Module> modules;
 
     @Before
-    public void setup() throws URISyntaxException, ReactorException {
-        modules = TestUtils.loadModules(getClass().getResource("/yang-template").toURI());
+    public void setup() throws URISyntaxException, ReactorException, FileNotFoundException {
+        modules = YangParserTestUtils.parseYangSources("/yang-template").getModules();
     }
 
     @Test
index 442369e6a578fe1c73431f5961bb6a2d2fb54c34..e1236621cb87bf7dd85284b94b47e20f4000d5c2 100644 (file)
@@ -89,9 +89,8 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-simple</artifactId>
-      <scope>test</scope>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-test-util</artifactId>
     </dependency>
   </dependencies>
 
index 812d6a23bd3bd5130aa0a6979bdadd1c59c9139a..2f97daa948ac67378f80bc5081d501f523dfda3e 100644 (file)
@@ -9,14 +9,11 @@ package org.opendaylight.mdsal.dom.broker.util;
 
 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.parser.spi.source.SourceException;
-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 {
 
@@ -53,18 +50,10 @@ public class TestModel {
     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
 
     public static SchemaContext createTestContext() throws ReactorException {
-        return parseYangStreams(Collections.singletonList(getInputStream()));
+        return YangParserTestUtils.parseYangStreams(Collections.singletonList(getInputStream()));
     }
 
     private static InputStream getInputStream() {
         return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
     }
-
-    private static SchemaContext parseYangStreams(final List<InputStream> streams)
-            throws SourceException, ReactorException {
-
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        return reactor.buildEffective(streams);
-    }
 }
index 471be2acf9557a016af5b7e8c3f0c4a1783b06d2..f61a85c9ba84d3331000d1cfba165f55739cec8f 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.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>mockito-configuration</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>mockito-configuration</artifactId>
-            <scope>test</scope>
+            <artifactId>yang-test-util</artifactId>
         </dependency>
     </dependencies>
 
index 134812b8da847ec30fb30c54fcdf29877d9e2912..8e4cf2b8f7401a553bae3c3b6cc0fd2ef280aa8f 100644 (file)
@@ -10,15 +10,12 @@ package org.opendaylight.controller.md.sal.dom.store.impl;
 import java.io.IOException;
 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.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-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 {
 
@@ -38,18 +35,10 @@ public class TestModel {
     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
 
     public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException, ReactorException {
-        return parseYangStreams(Collections.singletonList(getInputStream()));
+        return YangParserTestUtils.parseYangStreams(Collections.singletonList(getInputStream()));
     }
 
     private static InputStream getInputStream() {
         return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
     }
-
-    private static SchemaContext parseYangStreams(List<InputStream> streams)
-            throws SourceException, ReactorException {
-
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        return reactor.buildEffective(streams);
-    }
 }