use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class MountTest method test.
@Test
public void test() throws Exception {
final ModuleEffectiveStatement foo = reactor.newBuild().addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/yang-ext.yang"))).addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/mount.yang"))).buildEffective().getModuleStatements().get(FOO);
final Optional<MountEffectiveStatement> fooMount = foo.findDataTreeNode(QName.create(FOO, "foo")).orElseThrow().findFirstEffectiveSubstatement(MountEffectiveStatement.class);
assertTrue(fooMount.isPresent());
final Optional<MountEffectiveStatement> barMount = foo.findDataTreeNode(QName.create(FOO, "bar")).orElseThrow().findFirstEffectiveSubstatement(MountEffectiveStatement.class);
assertTrue(barMount.isPresent());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class ContextReferenceTest method test.
@Test
public void test() throws Exception {
final ModuleEffectiveStatement foo = reactor.newBuild().addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/yang-ext.yang"))).addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/ctxref.yang"))).buildEffective().getModuleStatements().get(FOO);
final DataTreeEffectiveStatement<?> list = foo.findDataTreeNode(QName.create(FOO, "list")).orElseThrow();
assertThat(list, instanceOf(ListEffectiveStatement.class));
final ContextInstanceEffectiveStatement listType = list.findFirstEffectiveSubstatement(ContextInstanceEffectiveStatement.class).orElseThrow();
assertEquals(LIST_TYPE, listType.argument());
assertEquals(LIST_TYPE, listType.contextType().argument());
final ContextInstanceEffectiveStatement leafType = list.findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContextInstanceEffectiveStatement.class).orElseThrow();
assertEquals(LEAF_TYPE, leafType.argument());
assertEquals(LEAF_TYPE, leafType.contextType().argument());
final List<GroupingEffectiveStatement> groupings = foo.streamEffectiveSubstatements(GroupingEffectiveStatement.class).collect(Collectors.toList());
assertEquals(2, groupings.size());
final ContextReferenceEffectiveStatement listRef = groupings.get(1).findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContextReferenceEffectiveStatement.class).orElseThrow();
assertEquals(LIST_TYPE, listType.argument());
assertSame(listType.contextType(), listRef.contextType());
final ContextReferenceEffectiveStatement leafRef = groupings.get(0).findFirstEffectiveSubstatement(LeafListEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContextReferenceEffectiveStatement.class).orElseThrow();
assertEquals(LEAF_TYPE, leafType.argument());
assertSame(leafType.contextType(), leafRef.contextType());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class Bug5101Test method test.
@Test
public void test() throws Exception {
final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug5101.yang").getModuleStatement(QName.create("foo", "2016-01-29", "foo"));
final ContainerEffectiveStatement myContainerInGrouping = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElse(null);
assertThat(myContainerInGrouping, instanceOf(ContainerSchemaNode.class));
assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) myContainerInGrouping).getStatus());
// This relies on schema definition order
final Iterator<ContainerEffectiveStatement> containers = module.streamEffectiveSubstatements(ContainerEffectiveStatement.class).collect(Collectors.toList()).iterator();
final ContainerEffectiveStatement root = containers.next();
assertThat(root, instanceOf(ContainerSchemaNode.class));
assertEquals(Status.CURRENT, ((ContainerSchemaNode) root).getStatus());
final ContainerEffectiveStatement rootMyContainer = root.streamEffectiveSubstatements(ContainerEffectiveStatement.class).findAny().orElse(null);
assertThat(rootMyContainer, instanceOf(ContainerSchemaNode.class));
assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) rootMyContainer).getStatus());
final ContainerEffectiveStatement myContainer = containers.next();
assertFalse(containers.hasNext());
assertThat(myContainer, instanceOf(ContainerSchemaNode.class));
assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) myContainer).getStatus());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class Bug6771Test method choiceCaseTest.
@Test
public void choiceCaseTest() throws Exception {
final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/choice-case.yang").getModuleStatement(NS);
final QName myChoice = QName.create(NS, "my-choice");
final QName caseOne = QName.create(NS, "one");
final QName caseTwo = QName.create(NS, "two");
final QName caseThree = QName.create(NS, "three");
final QName containerOne = QName.create(NS, "container-one");
final QName containerTwo = QName.create(NS, "container-two");
final QName containerThree = QName.create(NS, "container-three");
verifyLeafType(module, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B);
verifyLeafType(module, ROOT, myChoice, caseTwo, containerTwo, LEAF_CONT_B);
verifyLeafType(module, ROOT, myChoice, caseThree, containerThree, INNER_CONTAINER, LEAF_CONT_B);
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class Bug6771Test method augmentTest.
@Test
public void augmentTest() throws Exception {
final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/augment.yang").getModuleStatement(NS);
verifyLeafType(module, ROOT, CONT_B, LEAF_CONT_B);
verifyLeafType(module, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B);
}
Aggregations