use of org.opendaylight.yangtools.odlext.model.api.ContextInstanceEffectiveStatement 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());
}
Aggregations