Search in sources :

Example 16 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class YT1208Test method testLeafListStatementReuse.

@Test
public void testLeafListStatementReuse() throws Exception {
    final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/leaflist.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
    final NotificationEffectiveStatement notif = module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
    final LeafListEffectiveStatement grpBar = notif.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(LeafListEffectiveStatement.class).orElseThrow();
    final LeafListEffectiveStatement contBar = notif.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(LeafListEffectiveStatement.class).orElseThrow();
    assertSame(contBar, grpBar);
}
Also used : ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) LeafListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) NotificationEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 17 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class YT1208Test method testAugmentStatementReuse.

@Test
public void testAugmentStatementReuse() throws Exception {
    final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/augment.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
    final NotificationEffectiveStatement notif = module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
    final AugmentEffectiveStatement grpAug = notif.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(AugmentEffectiveStatement.class).orElseThrow();
    final AugmentEffectiveStatement contAug = notif.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(AugmentEffectiveStatement.class).orElseThrow();
    assertSame(contAug, grpAug);
}
Also used : ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) NotificationEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement) AugmentEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.AugmentEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 18 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class YT1212Test method testContainerStatementReuse.

@Test
public void testContainerStatementReuse() throws Exception {
    final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/container.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
    final NotificationEffectiveStatement notif = module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
    final List<GroupingEffectiveStatement> groupings = notif.effectiveSubstatements().stream().filter(GroupingEffectiveStatement.class::isInstance).map(GroupingEffectiveStatement.class::cast).collect(Collectors.toList());
    assertEquals(2, groupings.size());
    final GroupingEffectiveStatement grp = groupings.get(0);
    assertEquals("grp", grp.argument().getLocalName());
    final GroupingEffectiveStatement barGrp = groupings.get(1);
    assertEquals("bar", barGrp.argument().getLocalName());
    final ContainerEffectiveStatement bar = notif.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
    // Container needs to be reused
    assertSame(bar.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow(), barGrp.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow());
}
Also used : ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) NotificationEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 19 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class Bug4610Test method findContainer.

private static ContainerEffectiveStatement findContainer(final EffectiveModelContext context, final QName grouping, final QName container) {
    final ModuleEffectiveStatement module = context.getModuleStatement(grouping.getModule());
    final GroupingEffectiveStatement grp = module.streamEffectiveSubstatements(GroupingEffectiveStatement.class).filter(stmt -> grouping.equals(stmt.argument())).findAny().orElseThrow();
    final SchemaTreeEffectiveStatement<?> node = grp.findSchemaTreeNode(container).orElse(null);
    assertThat(node, instanceOf(ContainerEffectiveStatement.class));
    return (ContainerEffectiveStatement) node;
}
Also used : 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)

Example 20 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class Bug7879Test method test.

@Test
public void test() throws Exception {
    final ModuleEffectiveStatement module = assertEffectiveModelDir("/bugs/bug7879").getModuleStatement(qn("my-model"));
    final SchemaTreeEffectiveStatement<?> container = module.findSchemaTreeNode(qn("my-alarm"), qn("my-content"), qn("my-event-container")).orElse(null);
    assertThat(container, instanceOf(ContainerSchemaNode.class));
    final SchemaTreeEffectiveStatement<?> leaf = module.findSchemaTreeNode(qn("my-alarm"), qn("my-content"), qn("my-event-value")).orElse(null);
    assertThat(leaf, instanceOf(LeafSchemaNode.class));
    assertEquals(Optional.of("new description"), ((LeafSchemaNode) leaf).getDescription());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) 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