Clean up yang-parser-rfc7950 tests 17/95117/3
authormiroslav.kovac <miroslav.kovac@pantheon.tech>
Wed, 10 Feb 2021 12:05:56 +0000 (13:05 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 10 Feb 2021 15:33:46 +0000 (15:33 +0000)
Refactor using newer asserts and concepts, eliminating the use
of SchemaContextUtil.

JIRA: YANGTOOLS-1052
Change-Id: I6918a95fd4d1aec964cd5f80796305e73654345a
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
15 files changed:
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6868Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6883Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5396Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5437Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5550Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6669Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6771Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7879Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug8126Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug8307Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug8922Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT841Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5200Test.java

index 7b6d58514659e3c0d0f020caa502fd7638c3cb19..d45de78ba682129287cf0ba3eeaf21b2e62d0061 100644 (file)
@@ -8,23 +8,23 @@
 
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 import java.util.HashSet;
+import java.util.Optional;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
 
@@ -60,14 +60,15 @@ public class Bug6868Test {
         assertNotNull(schemaContext);
 
         for (final String expectedContainer : expectedContainers) {
-            assertTrue(String.format("Expected container %s not found.", expectedContainer),
-                    findNode(schemaContext, expectedContainer) instanceof ContainerSchemaNode);
+            assertThat(String.format("Expected container %s not found.", expectedContainer),
+                    schemaContext.findDataTreeChild(QName.create(FOO_NS, expectedContainer)).get(),
+                    instanceOf(ContainerSchemaNode.class));
         }
 
         final Set<String> unexpectedContainers = Sets.difference(ALL_CONTAINERS, expectedContainers);
         for (final String unexpectedContainer : unexpectedContainers) {
-            assertNull(String.format("Unexpected container %s.", unexpectedContainer),
-                    findNode(schemaContext, unexpectedContainer));
+            assertEquals(String.format("Unexpected container %s.", unexpectedContainer), Optional.empty(),
+                    schemaContext.findDataTreeChild(QName.create(FOO_NS, unexpectedContainer)));
         }
     }
 
@@ -85,11 +86,6 @@ public class Bug6868Test {
         return ImmutableSet.copyOf(supportedFeatures);
     }
 
-    private static SchemaNode findNode(final SchemaContext context, final String localName) {
-        return SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, QName.create(FOO_NS, localName)));
-    }
-
     @Test
     public void invalidYang10Test() throws Exception {
         try {
index 8891459a2f050ccdf6d214236ab4bd918f0980df..0d652525c1b03f273050325dcae20daf86311270 100644 (file)
@@ -53,7 +53,7 @@ public class Bug6883Test {
 
     private static AnydataSchemaNode assertAnyData(final SchemaContext context, final Iterable<String> localNamesPath) {
         final Iterable<QName> qNames = Iterables.transform(localNamesPath,
-            localName -> QName.create(FOO_NS, localName));
+                localName -> QName.create(FOO_NS, localName));
         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
                 SchemaPath.create(qNames, true));
         assertTrue(findDataSchemaNode instanceof AnydataSchemaNode);
index 6e62bf2444f618cddf2017a259d3ea014019f4aa..46016b21eb6c0f8a2746be2721ffe57b2aa33193 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -35,22 +36,22 @@ public class Bug5101Test {
 
         SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
                 SchemaPath.create(true, grp, myContainer));
-        assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+        assertThat(findDataSchemaNode, instanceOf(ContainerSchemaNode.class));
         ContainerSchemaNode myContainerInGrouping = (ContainerSchemaNode) findDataSchemaNode;
         assertEquals(Status.DEPRECATED, myContainerInGrouping.getStatus());
 
-        findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, myContainer));
-        assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+        findDataSchemaNode = context.findDataTreeChild(root, myContainer).get();
+        assertThat(findDataSchemaNode, instanceOf(ContainerSchemaNode.class));
         ContainerSchemaNode myContainerInRoot = (ContainerSchemaNode) findDataSchemaNode;
         assertEquals(Status.DEPRECATED, myContainerInRoot.getStatus());
 
-        findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, myContainer));
-        assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+        findDataSchemaNode = context.findDataTreeChild(myContainer).get();
+        assertThat(findDataSchemaNode, instanceOf(ContainerSchemaNode.class));
         ContainerSchemaNode myContainerInModule = (ContainerSchemaNode) findDataSchemaNode;
         assertEquals(Status.DEPRECATED, myContainerInModule.getStatus());
 
-        findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root));
-        assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+        findDataSchemaNode = context.findDataTreeChild(root).get();
+        assertThat(findDataSchemaNode, instanceOf(ContainerSchemaNode.class));
         ContainerSchemaNode rootContainer = (ContainerSchemaNode) findDataSchemaNode;
         assertEquals(Status.CURRENT, rootContainer.getStatus());
     }
index caa5a82eb580cc5bbd6c03be4c3e9d16e7b162e2..87597f9c59d0529ff52897c77f0fef416d3f886f 100644 (file)
@@ -8,10 +8,11 @@
 
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 import org.junit.Test;
@@ -19,12 +20,10 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 
 public class Bug5396Test {
     @Test
@@ -35,13 +34,12 @@ public class Bug5396Test {
         QName root = QName.create("foo", "root");
         QName myLeaf2 = QName.create("foo", "my-leaf2");
 
-        SchemaPath schemaPath = SchemaPath.create(true, root, myLeaf2);
-        SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, schemaPath);
-        assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
+        SchemaNode findDataSchemaNode = context.findDataTreeChild(root, myLeaf2).get();
+        assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
 
         LeafSchemaNode leaf2 = (LeafSchemaNode) findDataSchemaNode;
         TypeDefinition<?> type = leaf2.getType();
-        assertTrue(type instanceof UnionTypeDefinition);
+        assertThat(type, instanceOf(UnionTypeDefinition.class));
 
         UnionTypeDefinition union = (UnionTypeDefinition) type;
         List<TypeDefinition<?>> types = union.getTypes();
@@ -53,14 +51,14 @@ public class Bug5396Test {
         TypeDefinition<?> type2 = types.get(2);
         TypeDefinition<?> type3 = types.get(3);
 
-        assertFalse(type0.equals(type1));
-        assertFalse(type0.equals(type2));
-        assertFalse(type0.equals(type3));
+        assertNotEquals(type0, type1);
+        assertNotEquals(type0, type2);
+        assertNotEquals(type0, type3);
 
-        assertTrue(type0 instanceof StringTypeDefinition);
-        assertTrue(type1 instanceof StringTypeDefinition);
-        assertTrue(type2 instanceof StringTypeDefinition);
-        assertTrue(type3 instanceof StringTypeDefinition);
+        assertThat(type0, instanceOf(StringTypeDefinition.class));
+        assertThat(type1, instanceOf(StringTypeDefinition.class));
+        assertThat(type2, instanceOf(StringTypeDefinition.class));
+        assertThat(type3, instanceOf(StringTypeDefinition.class));
 
         StringTypeDefinition stringType0 = (StringTypeDefinition) type0;
         StringTypeDefinition stringType1 = (StringTypeDefinition) type1;
index 996b76d83524e4af80839e5b76767201877ba04d..5eac7c50c526a6299f119c11fff284706dc50af4 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
@@ -37,10 +36,8 @@ public class Bug5437Test {
         QName conGrp = QName.create(NS, REV, "con-grp");
         QName leafRef = QName.create(NS, REV, "leaf-ref");
 
-        SchemaPath leafRefPath = SchemaPath.create(true, root, conGrp, leafRef);
-        SchemaPath leafRef2Path = SchemaPath.create(true, root, leafRef2);
-        SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, leafRefPath);
-        SchemaNode findDataSchemaNode2 = SchemaContextUtil.findDataSchemaNode(context, leafRef2Path);
+        SchemaNode findDataSchemaNode = context.findDataTreeChild(root, conGrp, leafRef).get();
+        SchemaNode findDataSchemaNode2 = context.findDataTreeChild(root, leafRef2).get();
         assertThat(findDataSchemaNode, isA(LeafSchemaNode.class));
         assertThat(findDataSchemaNode2, isA(LeafSchemaNode.class));
 
index c673952ba86838638bdc4e2f986a12fcfbcf9d50..d29f8d2ed10a741f6533d5b9b4be1768a385e098 100644 (file)
@@ -7,16 +7,15 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 
 public class Bug5550Test {
     private static final String NS = "foo";
@@ -31,8 +30,7 @@ public class Bug5550Test {
         QName containerInGrouping = QName.create(NS, REV, "container-in-grouping");
         QName leaf1 = QName.create(NS, REV, "leaf-1");
 
-        SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, root, containerInGrouping, leaf1));
-        assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
+        SchemaNode findDataSchemaNode = context.findDataTreeChild(root, containerInGrouping, leaf1).get();
+        assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
     }
 }
index 20bdd12f10a514420105ff99699c984443594fcb..51ee39dd54da656b6279fbda0376d1543d24eb20 100644 (file)
@@ -12,7 +12,6 @@ import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -20,8 +19,6 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
@@ -70,9 +67,8 @@ public class Bug6669Test {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test1");
         assertNotNull(context);
 
-        final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, ROOT, BAR, BAR_1, M));
-        assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
+        final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, M).get();
+        assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
     }
 
     @Test
@@ -80,9 +76,8 @@ public class Bug6669Test {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test2");
         assertNotNull(context);
 
-        final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M));
-        assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
+        final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2, M).get();
+        assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
     }
 
     @Test
@@ -90,8 +85,8 @@ public class Bug6669Test {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test3");
         assertNotNull(context);
 
-        final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, QName.create(BAR_NS, REV, "l")));
-        assertTrue(findDataSchemaNode instanceof ListSchemaNode);
+        final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2,
+                QName.create(BAR_NS, REV, "l")).get();
+        assertThat(findDataSchemaNode, instanceOf(ListSchemaNode.class));
     }
 }
index 432f5f5eb59e7bb2590bbd65a3ff7511ecd0c5b1..2f29ac8efedbed98a5b2a429ac78ad65d534ad78 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -31,10 +32,8 @@ public class Bug6771Test {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/augment");
         assertNotNull(context);
 
-        verifyLeafType(SchemaContextUtil
-                .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
-        verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B)));
+        verifyLeafType(context.findDataTreeChild(ROOT, CONT_B, LEAF_CONT_B).get());
+        verifyLeafType(context.findDataTreeChild(ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B).get());
     }
 
     @Test
@@ -62,12 +61,11 @@ public class Bug6771Test {
     public void groupingTest() throws Exception {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/grouping");
         assertNotNull(context);
-        verifyLeafType(SchemaContextUtil
-                .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
+        verifyLeafType(context.findDataTreeChild(ROOT, CONT_B, LEAF_CONT_B).get());
     }
 
     private static void verifyLeafType(final SchemaNode schemaNode) {
-        assertTrue(schemaNode instanceof LeafSchemaNode);
-        assertTrue(((LeafSchemaNode) schemaNode).getType() instanceof Uint32TypeDefinition);
+        assertThat(schemaNode, instanceOf(LeafSchemaNode.class));
+        assertThat(((LeafSchemaNode) schemaNode).getType(), instanceOf(Uint32TypeDefinition.class));
     }
 }
index 687d0855e5c006bfb28e97e330bd3277dc03397f..9efa0284417e0b96f0622425d518a827548f90a5 100644 (file)
@@ -30,7 +30,7 @@ public class Bug7879Test {
         assertNotNull(context);
 
         assertTrue(findNode(context, qN("my-alarm"), qN("my-content"), qN("my-event-container"))
-            instanceof ContainerSchemaNode);
+                instanceof ContainerSchemaNode);
         final SchemaNode myEventValueLeaf = findNode(context, qN("my-alarm"), qN("my-content"), qN("my-event-value"));
         assertTrue(myEventValueLeaf instanceof LeafSchemaNode);
         assertEquals(Optional.of("new description"), myEventValueLeaf.getDescription());
index f513ed4ceb4677f66b564b6fc6862758739927f6..4370be2becb65fc9ef5f3ecac46b23edd2df86fc 100644 (file)
@@ -10,9 +10,11 @@ package org.opendaylight.yangtools.yang.stmt;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThrows;
 
+import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
@@ -31,13 +33,13 @@ public class Bug8126Test {
     public void testValidAugments() throws Exception {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8126/valid");
         assertThat(findNode(context, foo("root"), bar("my-container"), bar("my-choice"), bar("one"), bar("one"),
-            bar("mandatory-leaf")), instanceOf(LeafSchemaNode.class));
-        assertThat(findNode(context, foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2")),
+                bar("mandatory-leaf")), instanceOf(LeafSchemaNode.class));
+        assertThat(context.findDataTreeChild(foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2")).get(),
             instanceOf(LeafSchemaNode.class));
-
-        assertNull(findNode(context, foo("root"), bar("mandatory-list")));
+        assertEquals(Optional.empty(), context.findDataTreeChild(foo("root"), bar("mandatory-list")));
         assertNull(findNode(context, foo("root"), bar("mandatory-container"), bar("mandatory-choice")));
-        assertNull(findNode(context, foo("root"), bar("mandatory-container-2"), bar("one"), bar("mandatory-leaf-3")));
+        assertEquals(Optional.empty(), context.findDataTreeChild(foo("root"), bar("mandatory-container-2"), bar("one"),
+                bar("mandatory-leaf-3")));
     }
 
     @Test
@@ -70,7 +72,6 @@ public class Bug8126Test {
             "An augment cannot add node 'mandatory-leaf-3' because it is mandatory and in module different than "));
     }
 
-
     private static SchemaNode findNode(final SchemaContext context, final QName... qnames) {
         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, qnames));
     }
index 4231aed974625af40ebcb400a0b02fee683b7ecd..100d428ee38de1dee1c6542b239044917464cfc9 100644 (file)
@@ -7,22 +7,21 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
 import com.google.common.collect.ImmutableSetMultimap;
 import com.google.common.collect.SetMultimap;
+import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
@@ -69,11 +68,11 @@ public class Bug8307Test {
                 .buildEffective();
         assertNotNull(schemaContext);
 
-        assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_A)));
-        assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_B)));
-        assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_C)));
-        assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_A)));
-        assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_B)));
+        assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_FOO_CONT_A));
+        assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_FOO_CONT_B));
+        assertNotNull(schemaContext.findDataTreeChild(MY_FOO_CONT_C).orElse(null));
+        assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_BAR_CONT_A));
+        assertNotNull(schemaContext.findDataTreeChild(MY_BAR_CONT_B).orElse(null));
     }
 
     @Test
@@ -83,11 +82,11 @@ public class Bug8307Test {
                 .buildEffective();
         assertNotNull(schemaContext);
 
-        assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_A)));
-        assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_B)));
-        assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_C)));
-        assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_A)));
-        assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_B)));
+        assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_FOO_CONT_A));
+        assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_FOO_CONT_B));
+        assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_FOO_CONT_C));
+        assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_BAR_CONT_A));
+        assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_BAR_CONT_B));
     }
 
     @Test
@@ -98,11 +97,11 @@ public class Bug8307Test {
                 .buildEffective();
         assertNotNull(schemaContext);
 
-        assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_A)));
-        assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_B)));
-        assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_C)));
-        assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_A)));
-        assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_B)));
+        assertNotNull(schemaContext.findDataTreeChild(MY_FOO_CONT_A).orElse(null));
+        assertNotNull(schemaContext.findDataTreeChild(MY_FOO_CONT_B).orElse(null));
+        assertNotNull(schemaContext.findDataTreeChild(MY_FOO_CONT_C).orElse(null));
+        assertNotNull(schemaContext.findDataTreeChild(MY_BAR_CONT_A).orElse(null));
+        assertNotNull(schemaContext.findDataTreeChild(MY_BAR_CONT_B).orElse(null));
     }
 
     @Test
index f6777e2723bc09341ced7924a840b45e90224107..f66708eacc0af8ba8f210d5ab61d82c3b993a4fd 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.ImmutableSet;
@@ -19,8 +20,6 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 
 public class Bug8922Test {
     private static final String NS = "foo";
@@ -29,8 +28,8 @@ public class Bug8922Test {
     public void testAllFeaturesSupported() throws Exception {
         final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang");
         assertNotNull(context);
-        final SchemaNode findNode = findNode(context, qN("target"), qN("my-con"));
-        assertTrue(findNode instanceof ContainerSchemaNode);
+        final SchemaNode findNode = context.findDataTreeChild(qN("target"), qN("my-con")).get();
+        assertThat(findNode, instanceOf(ContainerSchemaNode.class));
         assertEquals(Optional.of("New description"), findNode.getDescription());
     }
 
@@ -38,15 +37,10 @@ public class Bug8922Test {
     public void testNoFeatureSupported() throws Exception {
         final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang", ImmutableSet.of());
         assertNotNull(context);
-        final SchemaNode findNode = findNode(context, qN("target"), qN("my-con"));
-        assertNull(findNode);
+        assertEquals(Optional.empty(), context.findDataTreeChild(qN("target"), qN("my-con")));
         assertTrue(context.getAvailableAugmentations().isEmpty());
     }
 
-    private static SchemaNode findNode(final SchemaContext context, final QName... qnames) {
-        return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, qnames));
-    }
-
     private static QName qN(final String localName) {
         return QName.create(NS, localName);
     }
index 83dbcb7e88d5e421db9c1670028dee61dbf4ada9..6fc5ffe882f905d643f25379f5a23d246512a78f 100644 (file)
@@ -52,7 +52,7 @@ public class EffectiveUsesRefineAndConstraintsTest {
         SchemaPath listInContainerPath = SchemaPath.create(true, rootContainer, containerFromGrouping, listInContainer);
         SchemaPath choiceFromGrpPath = SchemaPath.create(true, rootContainer, containerFromGrouping, choiceFromGrp);
         SchemaPath presenceContainerPath = SchemaPath.create(true, rootContainer, containerFromGrouping2,
-            presenceContainer);
+                presenceContainer);
 
         checkRefinedList(result, listInContainerPath);
         checkRefinedChoice(result, choiceFromGrpPath);
@@ -61,7 +61,7 @@ public class EffectiveUsesRefineAndConstraintsTest {
         SchemaPath originalListInContainerPath = SchemaPath.create(true, grp1, containerFromGrouping, listInContainer);
         SchemaPath originalChoiceFromGrpPath = SchemaPath.create(true, grp1, containerFromGrouping, choiceFromGrp);
         SchemaPath originalPresenceContainerPath = SchemaPath.create(true, grp1, containerFromGrouping2,
-            presenceContainer);
+                presenceContainer);
 
         checkOriginalList(result, originalListInContainerPath);
         checkOriginalChoice(result, originalChoiceFromGrpPath);
index b51a60a6b206e5e21246976f0605c88a1e090673..09dc733f4c6e29726d62e6e0e078c76b37fe508e 100644 (file)
@@ -29,10 +29,10 @@ public class YT841Test {
         final Module foo = context.findModule(FOO).get();
 
         final SchemaNode target = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true,
-            QName.create(FOO, "foo"),
-            QName.create(FOO, "foo"),
-            QName.create(FOO, "foo"),
-            QName.create(FOO, "input")));
+                QName.create(FOO, "foo"),
+                QName.create(FOO, "foo"),
+                QName.create(FOO, "foo"),
+                QName.create(FOO, "input")));
         assertNotNull(target);
 
     }
index 28c3cf97cf3e5b95ad32d2f502a24af25c8289b3..2b42c6b9bcf632549c5271da2dd69e5639f272f6 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.stmt.test;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 import java.util.Optional;
@@ -18,14 +19,12 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
 
 public class Bug5200Test {
@@ -41,17 +40,17 @@ public class Bug5200Test {
         QName myLeaf = QName.create(NS, REV, "my-leaf");
         QName myLeaf2 = QName.create(NS, REV, "my-leaf-2");
 
-        SchemaNode myLeafNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, myLeaf));
-        SchemaNode myLeaf2Node = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, myLeaf2));
+        SchemaNode myLeafNode = context.findDataTreeChild(root, myLeaf).get();
+        SchemaNode myLeaf2Node = context.findDataTreeChild(root, myLeaf2).get();
 
-        assertTrue(myLeafNode instanceof LeafSchemaNode);
-        assertTrue(myLeaf2Node instanceof LeafSchemaNode);
+        assertThat(myLeafNode, instanceOf(LeafSchemaNode.class));
+        assertThat(myLeaf2Node, instanceOf(LeafSchemaNode.class));
 
         TypeDefinition<?> myLeafType = ((LeafSchemaNode) myLeafNode).getType();
         TypeDefinition<?> myLeaf2Type = ((LeafSchemaNode) myLeaf2Node).getType();
 
-        assertTrue(myLeafType instanceof StringTypeDefinition);
-        assertTrue(myLeaf2Type instanceof Int32TypeDefinition);
+        assertThat(myLeafType, instanceOf(StringTypeDefinition.class));
+        assertThat(myLeaf2Type, instanceOf(Int32TypeDefinition.class));
 
         final LengthConstraint lengthConstraint =
                 ((StringTypeDefinition) myLeafType).getLengthConstraint().get();