Search in sources :

Example 1 with ContextReferenceEffectiveStatement

use of org.opendaylight.yangtools.odlext.model.api.ContextReferenceEffectiveStatement 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());
}
Also used : LeafListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement) ListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement) ContextInstanceEffectiveStatement(org.opendaylight.yangtools.odlext.model.api.ContextInstanceEffectiveStatement) LeafListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) ContextReferenceEffectiveStatement(org.opendaylight.yangtools.odlext.model.api.ContextReferenceEffectiveStatement) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ContextInstanceEffectiveStatement (org.opendaylight.yangtools.odlext.model.api.ContextInstanceEffectiveStatement)1 ContextReferenceEffectiveStatement (org.opendaylight.yangtools.odlext.model.api.ContextReferenceEffectiveStatement)1 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)1 LeafEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement)1 LeafListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement)1 ListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement)1 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)1