Remove TestUtils.findModule() 13/97413/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Sep 2021 10:22:03 +0000 (12:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Sep 2021 10:56:25 +0000 (12:56 +0200)
SchemaContext offers a convenient module lookup facility, use that
instead of this ancient thing. While it is slightly more verbose, it
reduces proliferation of duplicate functionality.

Change-Id: I4e913329173b786c54fb9d6be242e52b71fe2506
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
29 files changed:
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileExtensionStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileFeatureStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileGroupingStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIdentityStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileImportStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIncludeStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileLeafListStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileMetaStmtsTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileRpcStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileTypeDefStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileUsesStmtTest.java

index 5996ce28e56cd6f2fb3737550185e8c96bb2ec27..50f3e666e7288f7c77ffb1b8c65a15ead93eca30 100644 (file)
@@ -51,7 +51,7 @@ public class AugmentTest {
             .toURI());
 
         // foo.yang
-        final Module module1 = TestUtils.findModule(context, "foo").get();
+        final Module module1 = context.findModules("foo").iterator().next();
         Collection<? extends AugmentationSchemaNode> augmentations = module1.getAugmentations();
         assertEquals(1, augmentations.size());
         final AugmentationSchemaNode augment = augmentations.iterator().next();
@@ -98,7 +98,7 @@ public class AugmentTest {
         assertFalse(odl.isAugmenting());
 
         // baz.yang
-        final Module module3 = TestUtils.findModule(context, "baz").get();
+        final Module module3 = context.findModules("baz").iterator().next();
         augmentations = module3.getAugmentations();
         assertEquals(3, augmentations.size());
         AugmentationSchemaNode augment1 = null;
@@ -137,7 +137,7 @@ public class AugmentTest {
     public void testAugmentResolving() throws Exception {
         final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
             .toURI());
-        final Module module2 = TestUtils.findModule(context, "bar").get();
+        final Module module2 = context.findModules("bar").iterator().next();
         final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
                 module2.getQNameModule(), "interfaces"));
         final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
@@ -182,7 +182,7 @@ public class AugmentTest {
     public void testAugmentedChoice() throws Exception {
         final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
             .toURI());
-        final Module module2 = TestUtils.findModule(context, "bar").get();
+        final Module module2 = context.findModules("bar").iterator().next();
         final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
                 module2.getQNameModule(), "interfaces"));
         final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
@@ -258,7 +258,7 @@ public class AugmentTest {
         final XMLNamespace NS_BAR = XMLNamespace.of("urn:opendaylight:bar");
         final XMLNamespace NS_FOO = XMLNamespace.of("urn:opendaylight:foo");
         final Revision revision = Revision.of("2013-10-11");
-        final Module bar = TestUtils.findModule(context, "bar").get();
+        final Module bar = context.findModules("bar").iterator().next();
         final Collection<? extends RpcDefinition> rpcs = bar.getRpcs();
         assertEquals(2, rpcs.size());
 
index e79dce802c5f82855c98fa2e1acb488271dc37d2..154c297a0c2cb9ad2b51a2f80f3b8e06e25accce 100644 (file)
@@ -35,7 +35,7 @@ public class AugmentToExtensionTest {
         context = TestUtils.loadModules(getClass().getResource(
                 "/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
 
-        final Module devicesModule = TestUtils.findModule(context, "augment-module").get();
+        final Module devicesModule = context.findModules("augment-module").iterator().next();
         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(
             QName.create(devicesModule.getQNameModule(), "my-container"));
         for (final UsesNode usesNode : devicesContainer.getUses()) {
@@ -43,12 +43,11 @@ public class AugmentToExtensionTest {
         }
     }
 
-
     @Test
     public void testCorrectAugment() throws Exception {
         context = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
 
-        final Module devicesModule = TestUtils.findModule(context, "augment-module").get();
+        final Module devicesModule = context.findModules("augment-module").iterator().next();
 
         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
                 .create(devicesModule.getQNameModule(), "my-container"));
@@ -61,5 +60,4 @@ public class AugmentToExtensionTest {
 
         assertTrue(augmentationIsInContainer);
     }
-
 }
index e9710de65e49a462da3e965540686c5b9596e9f1..5b840723775d703d1b8cd1e56adb61c28bea2a57 100644 (file)
@@ -31,8 +31,8 @@ public class Bug1412Test {
 
     @Test
     public void test() throws Exception {
-        final Module bug1412 = TestUtils.findModule(
-            TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI()), "bug1412").get();
+        final Module bug1412 = TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI())
+            .findModules("bug1412").iterator().next();
 
         final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
                 bug1412.getQNameModule(), "node"));
index 16acd3fe1d635817d5142d946e105428d2af3300..cedae47e2323b7440add40c7c6c4561c2f364319 100644 (file)
@@ -8,13 +8,11 @@
 package org.opendaylight.yangtools.yang.stmt;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Collection;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
-import org.opendaylight.yangtools.yang.model.api.Module;
 
 /**
  * Test ANTLR4 grammar capability to parse unknown node in extension argument
@@ -24,19 +22,15 @@ import org.opendaylight.yangtools.yang.model.api.Module;
  * Note: Everything under unknown node is unknown node.
  */
 public class Bug1413Test {
-
     @Test
     public void test() throws Exception {
-        final Module bug1413 = TestUtils.findModule(
-            TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI()), "bug1413").get();
-        assertNotNull(bug1413);
-
-        Collection<? extends ExtensionDefinition> extensions = bug1413.getExtensionSchemaNodes();
+        Collection<? extends ExtensionDefinition> extensions = TestUtils.loadModules(
+            getClass().getResource("/bugs/bug1413").toURI())
+                .findModules("bug1413").iterator().next().getExtensionSchemaNodes();
         assertEquals(1, extensions.size());
 
         ExtensionDefinition info = extensions.iterator().next();
         assertEquals("text", info.getArgument());
         assertTrue(info.isYinElement());
     }
-
 }
index a67fdae6d2a9af1535d53416af625742acbab0be..fc5bb7a8c3f41775c3ade2c51480ae11446e33dd 100644 (file)
@@ -7,16 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.Module;
 
 public class Bug3859Test {
     @Test
     public void test() throws Exception {
-        final Module bug3859 = TestUtils.findModule(
-            TestUtils.loadModules(getClass().getResource("/bugs/bug3859").toURI()), "reference-in-unknown").get();
-        assertNotNull(bug3859);
+        assertEquals(1, TestUtils.loadModules(getClass().getResource("/bugs/bug3859").toURI())
+            .findModules("reference-in-unknown").size());
     }
 }
index fbd403891f62647eaaf37116dad54382d50fd496..c5ea15e7238e98c0f2e959a70d033b2583766e76 100644 (file)
@@ -29,8 +29,8 @@ public class Bug394Test {
     @Test
     public void testParseList() throws Exception {
         final SchemaContext context = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI());
-        final Module bug394 = TestUtils.findModule(context, "bug394").get();
-        final Module bug394_ext = TestUtils.findModule(context, "bug394-ext").get();
+        final Module bug394 = context.findModules("bug394").iterator().next();
+        final Module bug394_ext = context.findModules("bug394-ext").iterator().next();
 
         final ContainerSchemaNode logrecords = (ContainerSchemaNode) bug394.getDataChildByName(QName.create(
                 bug394.getQNameModule(), "logrecords"));
index ad4d7090081b7a935fe4931a7ba75b4f7caa309b..b863ef6f3e691ff70811b03e77f6cbb6050d6615 100644 (file)
@@ -37,9 +37,9 @@ public class OrderingTest {
     @Before
     public void setup() throws ReactorException, IOException, YangSyntaxErrorException, URISyntaxException {
         context = TestUtils.loadModules(getClass().getResource("/model").toURI());
-        foo = TestUtils.findModule(context, "foo").get();
-        bar = TestUtils.findModule(context, "bar").get();
-        baz = TestUtils.findModule(context, "baz").get();
+        foo = context.findModules("foo").iterator().next();
+        bar = context.findModules("bar").iterator().next();
+        baz = context.findModules("baz").iterator().next();
     }
 
     @Test
index 9f3112708122f372d4c3873f9ac4f0c98a393f8e..a0b7e8cc7958bbd1bc40c0ec07d1cf4407d098bd 100644 (file)
@@ -17,8 +17,6 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
@@ -27,7 +25,6 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
@@ -97,11 +94,6 @@ public final class TestUtils {
                 .getModules().iterator().next();
     }
 
-    @Deprecated(forRemoval = true)
-    public static Optional<? extends @NonNull Module> findModule(final SchemaContext context, final String moduleName) {
-        return context.getModules().stream().filter(module -> moduleName.equals(module.getName())).findAny();
-    }
-
     public static ModuleImport findImport(final Collection<? extends ModuleImport> imports, final String prefix) {
         for (ModuleImport moduleImport : imports) {
             if (moduleImport.getPrefix().equals(prefix)) {
index 629fdde467849cea96f6d5575d6cbc201d953f5f..1f5c73960c10514c62bb25ed2390f60e3b02e576 100644 (file)
@@ -65,7 +65,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testIPVersion() {
-        Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
+        Module tested = context.findModules("ietf-inet-types").iterator().next();
         Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         assertEquals(14, typedefs.size());
 
@@ -96,7 +96,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testEnumeration() {
-        Module tested = TestUtils.findModule(context, "custom-types-test").get();
+        Module tested = context.findModules("custom-types-test").iterator().next();
         Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
 
         TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version");
@@ -128,7 +128,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testIpAddress() {
-        Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
+        Module tested = context.findModules("ietf-inet-types").iterator().next();
         Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-address");
         UnionTypeDefinition baseType = (UnionTypeDefinition) type.getBaseType();
@@ -155,7 +155,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testDomainName() {
-        Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
+        Module tested = context.findModules("ietf-inet-types").iterator().next();
         Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         StringTypeDefinition type = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "domain-name");
         assertNotNull(type.getBaseType());
@@ -174,7 +174,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testInstanceIdentifier1() {
-        Module tested = TestUtils.findModule(context, "custom-types-test").get();
+        Module tested = context.findModules("custom-types-test").iterator().next();
         LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
                 QName.create(tested.getQNameModule(), "inst-id-leaf1"));
         InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType();
@@ -185,7 +185,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testInstanceIdentifier2() {
-        Module tested = TestUtils.findModule(context, "custom-types-test").get();
+        Module tested = context.findModules("custom-types-test").iterator().next();
         LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
                 QName.create(tested.getQNameModule(), "inst-id-leaf2"));
         InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType();
@@ -194,7 +194,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testIdentity() {
-        Module tested = TestUtils.findModule(context, "custom-types-test").get();
+        Module tested = context.findModules("custom-types-test").iterator().next();
         Collection<? extends IdentitySchemaNode> identities = tested.getIdentities();
         assertEquals(5, identities.size());
         IdentitySchemaNode cryptoAlg = null;
@@ -226,7 +226,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testBitsType1() {
-        Module tested = TestUtils.findModule(context, "custom-types-test").get();
+        Module tested = context.findModules("custom-types-test").iterator().next();
         LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
                 QName.create(tested.getQNameModule(), "mybits"));
         BitsTypeDefinition leafType = (BitsTypeDefinition) leaf.getType();
@@ -249,7 +249,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testBitsType2() {
-        Module tested = TestUtils.findModule(context, "custom-types-test").get();
+        Module tested = context.findModules("custom-types-test").iterator().next();
         Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "access-operations-type");
 
@@ -281,7 +281,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testIanaTimezones() {
-        Module tested = TestUtils.findModule(context, "iana-timezones").get();
+        Module tested = context.findModules("iana-timezones").iterator().next();
         Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "iana-timezone");
 
@@ -313,7 +313,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testObjectId128() {
-        Module tested = TestUtils.findModule(context, "ietf-yang-types").get();
+        Module tested = context.findModules("ietf-yang-types").iterator().next();
         Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         StringTypeDefinition testedType = (StringTypeDefinition) TestUtils.findTypedef(typedefs,
                 "object-identifier-128");
@@ -345,7 +345,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testIdentityref() {
-        Module tested = TestUtils.findModule(context, "custom-types-test").get();
+        Module tested = context.findModules("custom-types-test").iterator().next();
         Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref");
         IdentityrefTypeDefinition baseType = (IdentityrefTypeDefinition) testedType.getBaseType();
index 490889fb591e84bf28ffb8ade02a5ac35aa3c621..ba0737376f0a75bc0fc1727f22755aa76f52fc53 100644 (file)
@@ -12,8 +12,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.io.IOException;
-import java.net.URISyntaxException;
 import java.util.Collection;
 import org.junit.Before;
 import org.junit.Test;
@@ -33,11 +31,8 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class UsesAugmentTest {
-
     private static final QNameModule UG = QNameModule.create(
         XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:uses-grouping"), Revision.of("2013-07-30"));
     private static final QNameModule GD = QNameModule.create(
@@ -46,7 +41,7 @@ public class UsesAugmentTest {
     private SchemaContext context;
 
     @Before
-    public void init() throws ReactorException, IOException, YangSyntaxErrorException, URISyntaxException {
+    public void init() throws Exception {
         context = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
     }
 
@@ -108,7 +103,7 @@ public class UsesAugmentTest {
      */
     @Test
     public void testAugmentInUses() throws Exception {
-        final Module testModule = TestUtils.findModule(context, "uses-grouping").get();
+        final Module testModule = context.findModules("uses-grouping").iterator().next();
 
         // * notification pcreq
         final Collection<? extends NotificationDefinition> notifications = testModule.getNotifications();
@@ -411,7 +406,7 @@ public class UsesAugmentTest {
 
     @Test
     public void testTypedefs() throws Exception {
-        final Module testModule = TestUtils.findModule(context, "grouping-definitions").get();
+        final Module testModule = context.findModules("grouping-definitions").iterator().next();
         final Collection<? extends TypeDefinition<?>> types = testModule.getTypeDefinitions();
 
         TypeDefinition<?> intExt = null;
@@ -439,5 +434,4 @@ public class UsesAugmentTest {
         assertNotNull(pv);
         assertEquals(QName.create(GD, "union"), union.getQName());
     }
-
 }
index 073bccfeb26a5473c1905852966b092258160e44..f6dde62889e037a3ff9aa8f9a5cbf0d88cc70517 100644 (file)
@@ -44,8 +44,8 @@ public class YangParserIdentityTest {
     // prefix differs
     @Test
     public void testParsingImportPrefixIdentityTestModule() throws Exception {
-        Module module = TestUtils.findModule(StmtTestUtils.parseYangSources("/identity/import"),
-            "prefiximportidentitytest").get();
+        Module module = StmtTestUtils.parseYangSources("/identity/import").findModules("prefiximportidentitytest")
+            .iterator().next();
         Collection<? extends ModuleImport> imports = module.getImports();
         assertEquals(imports.size(), 1);
         ModuleImport dummy = TestUtils.findImport(imports, "dummy");
index b8e7d63accf331d82e86f09dd7d379f4e96c16cb..d66b2068ac1315a327ded3430d2b12c443b83ed6 100644 (file)
@@ -44,7 +44,7 @@ public class YangParserSimpleTest {
     @Before
     public void init() throws Exception {
         context = TestUtils.loadModules(getClass().getResource("/simple-test").toURI());
-        testModule = TestUtils.findModule(context, "simple-nodes").get();
+        testModule = context.findModules("simple-nodes").iterator().next();
     }
 
     @Test
index 5135b130992a5826848c4fceeb42d558d4cd37c9..b59425acb88dc55d3e696f89ed8ff92e815da653 100644 (file)
@@ -86,9 +86,9 @@ public class YangParserTest {
     @Before
     public void init() throws Exception {
         context = TestUtils.loadModules(getClass().getResource("/model").toURI());
-        foo = TestUtils.findModule(context, "foo").get();
-        bar = TestUtils.findModule(context, "bar").get();
-        baz = TestUtils.findModule(context, "baz").get();
+        foo = context.findModules("foo").iterator().next();
+        bar = context.findModules("bar").iterator().next();
+        baz = context.findModules("baz").iterator().next();
     }
 
     @Test
index a251296799076a9ab9abc8ce886697b8fdea4e1b..f5e36e422e155586ccbfd912243e1027ab810577 100644 (file)
@@ -317,8 +317,8 @@ public class YangParserWithContextTest {
         final StatementStreamSource test2 = sourceForResource("/context-augment-test/test2.yang");
         final StatementStreamSource test3 = sourceForResource("/context-augment-test/test3.yang");
 
-        final SchemaContext context = TestUtils.parseYangSources(resource, test1, test2, test3);
-        final Module t4 = TestUtils.findModule(context, "test4").get();
+        final Module t4 = TestUtils.parseYangSources(resource, test1, test2, test3).findModules("test4").iterator()
+            .next();
         final ContainerSchemaNode interfaces = (ContainerSchemaNode) t4.getDataChildByName(QName.create(
                 t4.getQNameModule(), "interfaces"));
         final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(t4.getQNameModule(),
index f6abe8edc7783ab09b0a7c510f90169b0b4c6aa4..7dded3c98a8de6793efedfd932cdb6174fe71b4e 100644 (file)
@@ -21,13 +21,11 @@ import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileAugmentStmtTest extends AbstractYinModulesTest {
-
     @Test
     public void testAugment() {
-        final Module testModule = TestUtils.findModule(context, "main-impl").get();
+        final Module testModule = context.findModules("main-impl").iterator().next();
         assertNotNull(testModule);
 
         final Collection<? extends AugmentationSchemaNode> augmentations = testModule.getAugmentations();
index 818e35870122fa71d8c5f3eb2fd9badcd430b24c..bdd86e51ad814708321f7b6b9fc366af38279705 100644 (file)
@@ -20,13 +20,11 @@ import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileChoiceStmtTest extends AbstractYinModulesTest {
-
     @Test
     public void testChoiceAndCases() {
-        final Module testModule = TestUtils.findModule(context, "config").get();
+        final Module testModule = context.findModules("config").iterator().next();
         assertNotNull(testModule);
 
         final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(
index cdd573ffb6b14c2df2573344550980402fd8b5df..5f6f06cf867ec42c9963ef79e5702048f479483b 100644 (file)
@@ -17,13 +17,12 @@ import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileExtensionStmtTest extends AbstractYinModulesTest {
 
     @Test
     public void testExtensions() {
-        Module testModule = TestUtils.findModule(context, "config").get();
+        Module testModule = context.findModules("config").iterator().next();
         assertNotNull(testModule);
 
         Collection<? extends ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
index d8c98772b998985e0fdf84cf4e8d5f1347caca80..f8a574103079084d049584464a354f52cdca3286 100644 (file)
@@ -13,8 +13,6 @@ import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.io.IOException;
-import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.Iterator;
 import org.junit.Before;
@@ -22,16 +20,13 @@ import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.stmt.TestUtils;
-import org.xml.sax.SAXException;
 
 public class YinFileFeatureStmtTest {
-
     private SchemaContext context;
 
     @Before
-    public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
+    public void init() throws Exception {
         context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/feature-test/")
             .toURI());
         assertEquals(1, context.getModules().size());
@@ -39,7 +34,7 @@ public class YinFileFeatureStmtTest {
 
     @Test
     public void testFeature() {
-        Module testModule = TestUtils.findModule(context, "yang-with-features").get();
+        Module testModule = context.findModules("yang-with-features").iterator().next();
         assertNotNull(testModule);
 
         Collection<? extends FeatureDefinition> features = testModule.getFeatures();
index d405e2bc9794c54f6eff48680f486bb5c41350b2..7683dc1d81ab90e9b89d8aef131ae82b0f8cafda 100644 (file)
@@ -11,7 +11,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Optional;
@@ -21,13 +20,11 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileGroupingStmtTest extends AbstractYinModulesTest {
-
     @Test
-    public void testGrouping() throws URISyntaxException {
-        final Module testModule = TestUtils.findModule(context, "config").get();
+    public void testGrouping() {
+        final Module testModule = context.findModules("config").iterator().next();
         assertNotNull(testModule);
 
         final Collection<? extends GroupingDefinition> groupings = testModule.getGroupings();
index 5e47285d2e1c521f6860027930e79da10fa91024..bfc91cad67740666addcbe5624dc020cd931314c 100644 (file)
@@ -9,18 +9,15 @@ package org.opendaylight.yangtools.yang.stmt.yin;
 
 import static org.junit.Assert.assertEquals;
 
-import java.net.URISyntaxException;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileHeaderStmtsTest extends AbstractYinModulesTest {
     @Test
-    public void testYinFileHeader() throws URISyntaxException {
-        Module testModule = TestUtils.findModule(context, "config").get();
-
+    public void testYinFileHeader() {
+        Module testModule = context.findModules("config").iterator().next();
         assertEquals(YangVersion.VERSION_1, testModule.getYangVersion());
         assertEquals(XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:controller:config"),
             testModule.getNamespace());
index af5d4d6a80e6c0198069a159d1ceed9ed87a101c..c3ad730f03c9a0d8ca9714af94c76d88bf6df059 100644 (file)
@@ -14,19 +14,16 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.Iterator;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileIdentityStmtTest extends AbstractYinModulesTest {
-
     @Test
-    public void testIdentity() throws URISyntaxException {
-        Module testModule = TestUtils.findModule(context, "config").get();
+    public void testIdentity() {
+        Module testModule = context.findModules("config").iterator().next();
         assertNotNull(testModule);
 
         Collection<? extends IdentitySchemaNode> identities = testModule.getIdentities();
index 58f85bddfd1ae49a4c65edff15f81efeaab0df6d..62fb46f96449418468c5acbfa0298112586722e2 100644 (file)
@@ -13,19 +13,17 @@ import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.text.ParseException;
 import java.util.Collection;
 import java.util.Iterator;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileImportStmtTest extends AbstractYinModulesTest {
 
     @Test
-    public void testImport() throws ParseException {
-        Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
+    public void testImport() {
+        Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
         assertNotNull(testModule);
 
         Collection<? extends ModuleImport> imports = testModule.getImports();
index 36388652202a6919c4ef95101f21734c7cf62ebb..4694672b3bc8ee0847eddad508f49535ea964f52 100644 (file)
@@ -8,41 +8,22 @@
 package org.opendaylight.yangtools.yang.stmt.yin;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.Iterator;
-import org.junit.Before;
+import java.util.Collection;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.Submodule;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.stmt.TestUtils;
-import org.xml.sax.SAXException;
 
 public class YinFileIncludeStmtTest {
-    private SchemaContext context;
-
-    @Before
-    public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
-        context = TestUtils.loadYinModules(getClass().getResource(
-            "/semantic-statement-parser/yin/include-belongs-to-test").toURI());
-        assertEquals(1, context.getModules().size());
-    }
-
     @Test
-    public void testInclude() throws URISyntaxException {
-        Module parentModule = TestUtils.findModule(context, "parent").get();
-        assertNotNull(parentModule);
-
-        assertEquals(1, parentModule.getSubmodules().size());
-        Iterator<? extends Submodule> submodulesIterator = parentModule.getSubmodules().iterator();
+    public void testInclude() throws Exception {
+        Collection<? extends Submodule> submodules = TestUtils.loadYinModules(getClass().getResource(
+            "/semantic-statement-parser/yin/include-belongs-to-test").toURI()).findModules("parent").iterator().next()
+            .getSubmodules();
+        assertEquals(1, submodules.size());
 
-        Submodule childModule = submodulesIterator.next() ;
-        assertNotNull(childModule);
+        Submodule childModule = submodules.iterator().next();
         assertEquals("child", childModule.getName());
         assertEquals(XMLNamespace.of("urn:opendaylight/parent"), childModule.getNamespace());
     }
index 376dac609e1d4a64338a25134cb3512c56bd47e4..dc71d03151eccf1731339129fe6f6c8ff94b667c 100644 (file)
@@ -16,13 +16,11 @@ import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileLeafListStmtTest extends AbstractYinModulesTest {
-
     @Test
     public void testLeafList() {
-        final Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
+        final Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
 
         final LeafListSchemaNode leafList = (LeafListSchemaNode) testModule.findDataChildByName(
             QName.create(testModule.getQNameModule(), "netconf-state"),
index f18941743abce99c9b492b2ebbf2a2feb04c0818..10bb22a654564dcda65aaa0de94dd99c5a468b86 100644 (file)
@@ -26,12 +26,11 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileListStmtTest extends AbstractYinModulesTest {
     @Test
     public void testListAndLeaves() {
-        final Module testModule = TestUtils.findModule(context, "config").get();
+        final Module testModule = context.findModules("config").iterator().next();
         assertNotNull(testModule);
 
         final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(QName.create(
index e667d1f914571dfefcc41f6b1fee1f677f267350..2635b38372ea144124ab4d9c5c2fe281929cc853 100644 (file)
@@ -10,17 +10,14 @@ package org.opendaylight.yangtools.yang.stmt.yin;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.net.URISyntaxException;
 import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileMetaStmtsTest extends AbstractYinModulesTest {
-
     @Test
-    public void testMetaStatements() throws URISyntaxException {
-        Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
+    public void testMetaStatements() {
+        Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
         assertNotNull(testModule);
 
         assertEquals(Optional.of("IETF NETCONF (Network Configuration) Working Group"), testModule.getOrganization());
index 02cbcaf53e249e1071be1a247dac3fd29a999abd..b51dd8260c106bceced46ae411ced1307e5e7a91 100644 (file)
@@ -17,13 +17,11 @@ import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileRpcStmtTest extends AbstractYinModulesTest {
-
     @Test
     public void testRpc() {
-        Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
+        Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
 
         Collection<? extends RpcDefinition> rpcs = testModule.getRpcs();
         assertEquals(1, rpcs.size());
index f23d9075b2431506cc89580315c3c153924eedf1..0b5b65c330f44d566eb6b5c9ef6ed32e0eaf5054 100644 (file)
@@ -16,12 +16,11 @@ import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileTypeDefStmtTest extends AbstractYinModulesTest {
     @Test
     public void testTypedef() {
-        Module testModule = TestUtils.findModule(context, "config").get();
+        Module testModule = context.findModules("config").iterator().next();
         assertNotNull(testModule);
 
         Collection<? extends TypeDefinition<?>> typeDefs = testModule.getTypeDefinitions();
index 372905c93a1ae03fcfe9fc92f6922b3acd5be5b2..1253382ad8ca01334186790833193c9acd9521d1 100644 (file)
@@ -18,12 +18,11 @@ import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
-import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileUsesStmtTest extends AbstractYinModulesTest {
     @Test
     public void testUses() {
-        final Module testModule = TestUtils.findModule(context, "main-impl").get();
+        final Module testModule = context.findModules("main-impl").iterator().next();
 
         final Collection<? extends AugmentationSchemaNode> augmentations = testModule.getAugmentations();
         assertEquals(1, augmentations.size());