Search in sources :

Example 11 with ModuleEffectiveStatement

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

the class Bug8126Test method testValidAugments.

@Test
public void testValidAugments() throws Exception {
    final ModuleEffectiveStatement fooModule = StmtTestUtils.parseYangSources("/bugs/bug8126/valid").getModuleStatement(QNameModule.create(FOO_NS));
    assertThat(fooModule.findSchemaTreeNode(foo("root"), bar("my-container"), bar("my-choice"), bar("one"), bar("one"), bar("mandatory-leaf")).orElse(null), instanceOf(LeafSchemaNode.class));
    assertThat(fooModule.findSchemaTreeNode(foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2")).orElse(null), instanceOf(LeafSchemaNode.class));
    assertEquals(Optional.empty(), fooModule.findSchemaTreeNode(foo("root"), bar("mandatory-list")));
    assertEquals(Optional.empty(), fooModule.findSchemaTreeNode(foo("root"), bar("mandatory-container"), bar("mandatory-choice")));
    assertEquals(Optional.empty(), fooModule.findSchemaTreeNode(foo("root"), bar("mandatory-container-2"), bar("one"), bar("mandatory-leaf-3")));
}
Also used : LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 12 with ModuleEffectiveStatement

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

the class DeclaredStatementsTest method testDeclaredModuleAndSubmodule.

@Test
public void testDeclaredModuleAndSubmodule() throws ReactorException {
    final StatementStreamSource parentModule = sourceForResource("/declared-statements-test/parent-module-declared-test.yang");
    final StatementStreamSource childModule = sourceForResource("/declared-statements-test/child-module-declared-test.yang");
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(parentModule, childModule);
    assertNotNull(schemaContext);
    final Module testModule = schemaContext.findModules("parent-module-declared-test").iterator().next();
    assertNotNull(testModule);
    final ModuleStatement moduleStatement = ((ModuleEffectiveStatement) testModule).getDeclared();
    assertNotNull(moduleStatement.argument());
    final YangVersionStatement moduleStatementYangVersion = moduleStatement.getYangVersion();
    assertNotNull(moduleStatementYangVersion);
    assertNotNull(moduleStatementYangVersion.argument());
    final NamespaceStatement moduleStatementNamspace = moduleStatement.getNamespace();
    assertNotNull(moduleStatementNamspace);
    assertNotNull(moduleStatementNamspace.argument());
    final PrefixStatement moduleStatementPrefix = moduleStatement.getPrefix();
    assertNotNull(moduleStatementPrefix);
    assertNotNull(moduleStatementPrefix.argument());
    assertEquals(1, moduleStatement.getIncludes().size());
    final IncludeStatement includeStatement = moduleStatement.getIncludes().iterator().next();
    assertEquals("child-module-declared-test", includeStatement.argument());
    final Collection<? extends Submodule> submodules = testModule.getSubmodules();
    assertNotNull(submodules);
    assertEquals(1, submodules.size());
    final Submodule submodule = submodules.iterator().next();
    final SubmoduleStatement submoduleStatement = ((SubmoduleEffectiveStatement) submodule).getDeclared();
    assertNotNull(submoduleStatement.argument());
    final YangVersionStatement submoduleStatementYangVersion = submoduleStatement.getYangVersion();
    assertNotNull(submoduleStatementYangVersion);
    final BelongsToStatement belongsToStatement = submoduleStatement.getBelongsTo();
    assertNotNull(belongsToStatement);
    assertNotNull(belongsToStatement.argument());
    assertNotNull(belongsToStatement.getPrefix());
}
Also used : NamespaceStatement(org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement) StatementStreamSource(org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource) ModuleStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement) Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) BelongsToStatement(org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) PrefixStatement(org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement) YangVersionStatement(org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement) SubmoduleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement) IncludeStatement(org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement) SubmoduleStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 13 with ModuleEffectiveStatement

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

the class YT1208Test method testLeafStatementReuse.

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

Example 14 with ModuleEffectiveStatement

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

the class YT1208Test method testTypedefStatementReuse.

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

Example 15 with ModuleEffectiveStatement

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

the class YT1208Test method testCaseStatementReuse.

@Test
public void testCaseStatementReuse() throws Exception {
    final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/case.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
    final NotificationEffectiveStatement notif = module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
    final CaseEffectiveStatement grpBar = notif.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(CaseEffectiveStatement.class).orElseThrow();
    final CaseEffectiveStatement contBar = notif.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(CaseEffectiveStatement.class).orElseThrow();
    assertSame(contBar, grpBar);
}
Also used : ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) CaseEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) ChoiceEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement) NotificationEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement) 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