Remove more TestUtils classes 17/97717/5
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 2 Oct 2021 19:56:53 +0000 (21:56 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 5 Oct 2021 08:36:41 +0000 (10:36 +0200)
We have some duplication still and some assert code which should be with
its users in AugmentTest.

Change-Id: Ic0df63afaf8f2a5003339b8315a85aaea08de1b5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
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/TestUtils.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java

index 553c8a1c4573d36043b52da70b7927c90d824eeb..16f4e438b190271fdf31b7e84a7c2b859e8cf5d8 100644 (file)
@@ -67,7 +67,7 @@ public class AugmentTest {
         final Collection<? extends DataSchemaNode> augmentChildren = augment.getChildNodes();
         assertEquals(4, augmentChildren.size());
         for (final DataSchemaNode dsn : augmentChildren) {
-            TestUtils.checkIsAugmenting(dsn, false);
+            checkIsAugmenting(dsn, false);
         }
 
         final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName(QName.create(
@@ -150,7 +150,7 @@ public class AugmentTest {
         // augment "/br:interfaces/br:ifEntry" {
         final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(BAZ,
                 "augment-holder"));
-        TestUtils.checkIsAugmenting(augmentHolder, true);
+        checkIsAugmenting(augmentHolder, true);
         assertEquals(Q2, augmentHolder.getQName());
 
         // foo.yang
@@ -190,7 +190,7 @@ public class AugmentTest {
                 module2.getQNameModule(), "ifEntry"));
         final ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(
                 BAZ, "augment-holder"));
-        TestUtils.checkIsAugmenting(augmentedHolder, true);
+        checkIsAugmenting(augmentedHolder, true);
 
         // foo.yang
         // augment "/br:interfaces/br:ifEntry/bz:augment-holder"
@@ -341,4 +341,24 @@ public class AugmentTest {
         final LeafSchemaNode id = (LeafSchemaNode) node.getDataChildByName(QName.create(test.getQNameModule(), "id"));
         assertTrue(id.isAugmenting());
     }
+
+    /**
+     * Test if node has augmenting flag set to expected value. In case this is  DataNodeContainer/ChoiceNode, check its
+     * child nodes/case nodes too.
+     *
+     * @param node node to check
+     * @param expected expected value
+     */
+    private static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
+        assertEquals(expected, node.isAugmenting());
+        if (node instanceof DataNodeContainer) {
+            for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
+                checkIsAugmenting(child, expected);
+            }
+        } else if (node instanceof ChoiceSchemaNode) {
+            for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
+                checkIsAugmenting(caseNode, expected);
+            }
+        }
+    }
 }
index 27114fa4fb333623b1f023576d03fa7cebdc3bb6..0d07b374dd6d01d307eeb15377f27b2a69b8b148 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.junit.Assert.assertEquals;
-
 import java.io.File;
 import java.io.IOException;
 import java.net.URI;
@@ -17,17 +15,12 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-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.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinStatementStreamSource;
@@ -69,18 +62,17 @@ public final class TestUtils {
             .buildEffective();
     }
 
-    public static EffectiveModelContext loadModuleResources(final Class<?> refClass, final String... resourceNames)
-            throws IOException, ReactorException, YangSyntaxErrorException {
-        final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild();
-
-        for (String resourceName : resourceNames) {
-            reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(refClass,
-                resourceName)));
+    public static EffectiveModelContext parseYangSource(final String... yangSourceFilePath) throws Exception {
+        final var reactor = RFC7950Reactors.defaultReactor().newBuild();
+        for (var resourcePath : yangSourceFilePath) {
+            reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forPath(Path.of(
+                TestUtils.class.getResource(resourcePath).toURI()))));
         }
-
         return reactor.buildEffective();
     }
 
+    // FIXME: these remain unaudited
+
     public static EffectiveModelContext loadYinModules(final URI resourceDirectory)
             throws ReactorException, SAXException, IOException {
         final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild();
@@ -119,39 +111,4 @@ public final class TestUtils {
         }
         return null;
     }
-
-    /**
-     * Test if node has augmenting flag set to expected value. In case this is
-     * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too.
-     *
-     * @param node
-     *            node to check
-     * @param expected
-     *            expected value
-     */
-    public static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
-        assertEquals(expected, node.isAugmenting());
-        if (node instanceof DataNodeContainer) {
-            for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
-                checkIsAugmenting(child, expected);
-            }
-        } else if (node instanceof ChoiceSchemaNode) {
-            for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
-                checkIsAugmenting(caseNode, expected);
-            }
-        }
-    }
-
-    public static EffectiveModelContext parseYangSource(final String... yangSourceFilePath) throws Exception {
-        final var reactor = RFC7950Reactors.defaultReactor().newBuild();
-        for (var resourcePath : yangSourceFilePath) {
-            reactor.addSource(sourceForResource(resourcePath));
-        }
-        return reactor.buildEffective();
-    }
-
-    public static YangStatementStreamSource sourceForResource(final String resourceName) throws Exception {
-        return YangStatementStreamSource.create(YangTextSchemaSource.forPath(Path.of(
-            TestUtils.class.getResource(resourceName).toURI())));
-    }
 }
index ad7ce2b243550ad3855707efcae5b19b44283654..c2c4ab3f38323aa77f231281b5a4b0ff730f2783 100644 (file)
@@ -24,7 +24,7 @@ public class YangParserNegativeTest {
     @Test
     public void testInvalidImport() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile1.yang"));
+            () -> TestUtils.parseYangSource("/negative-scenario/testfile1.yang"));
 
         final Throwable rootCause = Throwables.getRootCause(ex);
         assertThat(rootCause, isA(InferenceException.class));
@@ -35,7 +35,7 @@ public class YangParserNegativeTest {
     @Test
     public void testTypeNotFound() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile2.yang"));
+            () -> TestUtils.parseYangSource("/negative-scenario/testfile2.yang"));
         final Throwable rootCause = Throwables.getRootCause(ex);
         assertThat(rootCause, isA(InferenceException.class));
         assertThat(rootCause.getMessage(),
@@ -45,7 +45,7 @@ public class YangParserNegativeTest {
     @Test
     public void testInvalidAugmentTarget() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModuleResources(getClass(),
+            () -> TestUtils.parseYangSource(
                 "/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang"));
         final Throwable rootCause = Throwables.getRootCause(ex);
         assertThat(rootCause, isA(InferenceException.class));
@@ -56,7 +56,7 @@ public class YangParserNegativeTest {
     @Test
     public void testInvalidRefine() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile4.yang"));
+            () -> TestUtils.parseYangSource("/negative-scenario/testfile4.yang"));
         final Throwable cause = ex.getCause();
         assertThat(cause, isA(SourceException.class));
         assertThat(cause.getMessage(), containsString("Error in module 'test4' in the refine of uses "
@@ -67,7 +67,7 @@ public class YangParserNegativeTest {
     @Test
     public void testInvalidLength() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile5.yang"));
+            () -> TestUtils.parseYangSource("/negative-scenario/testfile5.yang"));
         final Throwable cause = ex.getCause();
         assertThat(cause, isA(SourceException.class));
         assertThat(cause.getMessage(), containsString("Invalid length constraint [4..10]"));
@@ -128,7 +128,7 @@ public class YangParserNegativeTest {
     @Test
     public void testDuplicityInAugmentTarget1() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModuleResources(getClass(),
+            () -> TestUtils.parseYangSource(
                 "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment1.yang"));
         final Throwable cause = ex.getCause();
         assertThat(cause, isA(InferenceException.class));
@@ -139,7 +139,7 @@ public class YangParserNegativeTest {
     @Test
     public void testDuplicityInAugmentTarget2() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModuleResources(getClass(),
+            () -> TestUtils.parseYangSource(
                 "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment2.yang"));
         final Throwable rootCause = Throwables.getRootCause(ex);
         assertThat(rootCause, isA(SubstatementIndexingException.class));
@@ -150,7 +150,7 @@ public class YangParserNegativeTest {
     @Test
     public void testMandatoryInAugment() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModuleResources(getClass(),
+            () -> TestUtils.parseYangSource(
                 "/negative-scenario/testfile8.yang", "/negative-scenario/testfile7.yang"));
         final Throwable cause = ex.getCause();
         assertThat(cause, isA(InferenceException.class));