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;
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)));
}
}
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 {
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);
*/
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;
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());
}
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;
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
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();
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;
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;
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));
*/
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";
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));
}
}
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;
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;
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
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
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));
}
}
*/
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;
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
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));
}
}
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());
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;
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
"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));
}
*/
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;
.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
.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
.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
*/
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;
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";
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());
}
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);
}
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);
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);
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);
}
*/
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;
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 {
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();