Search in sources :

Example 6 with ModuleEffectiveStatement

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());
}
Also used : MountEffectiveStatement(org.opendaylight.yangtools.odlext.model.api.MountEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 7 with ModuleEffectiveStatement

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());
}
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)

Example 8 with ModuleEffectiveStatement

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());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 9 with ModuleEffectiveStatement

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);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 10 with ModuleEffectiveStatement

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);
}
Also used : ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Aggregations

ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)45 Test (org.junit.Test)28 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)20 ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)12 NonNull (org.eclipse.jdt.annotation.NonNull)9 Objects.requireNonNull (java.util.Objects.requireNonNull)8 NotificationEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement)8 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)5 QName (org.opendaylight.yangtools.yang.common.QName)4 LeafEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement)4 LeafListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement)4 SubmoduleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement)4 ModuleStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 Revision (org.opendaylight.yangtools.yang.common.Revision)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 Module (org.opendaylight.yangtools.yang.model.api.Module)2