Search in sources :

Example 1 with ContainerStatement

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

the class Bug4610Test method test.

@Test
public void test() throws Exception {
    final EffectiveModelContext context = StmtTestUtils.parseYangSources("/bugs/bug4610");
    final Revision revision = Revision.of("2015-12-12");
    // Original
    final QName c1Bar = QName.create(QNameModule.create(XMLNamespace.of("bar"), revision), "c1");
    final ContainerEffectiveStatement g1container = findContainer(context, QName.create(c1Bar, "g1"), c1Bar);
    final QName g1argument = g1container.argument();
    final ContainerStatement g1original = g1container.getDeclared();
    final ContainerEffectiveStatement g2container = findContainer(context, QName.create(c1Bar, "g2"), c1Bar);
    assertEquals(g1argument, g2container.argument());
    assertSame(g1original, g2container.getDeclared());
    final QName c1Foo = QName.create(QNameModule.create(XMLNamespace.of("foo"), revision), "c1");
    final ContainerEffectiveStatement g3container = findContainer(context, QName.create(c1Foo, "g3"), c1Foo);
    assertNotEquals(g1argument, g3container.argument());
    assertSame(g1original, g3container.getDeclared());
    final SchemaTreeEffectiveStatement<?> rootContainer = context.getModuleStatement(c1Foo.getModule()).findSchemaTreeNode(QName.create(c1Foo, "root"), c1Foo).orElseThrow();
    assertThat(rootContainer, instanceOf(ContainerEffectiveStatement.class));
    assertNotEquals(g1argument, rootContainer.argument());
    assertSame(g1original, rootContainer.getDeclared());
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) QName(org.opendaylight.yangtools.yang.common.QName) ContainerStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 2 with ContainerStatement

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

the class DeclaredStatementsTest method testDeclaredContainer.

@Test
public void testDeclaredContainer() throws ReactorException {
    final StatementStreamSource containerStmtModule = sourceForResource("/declared-statements-test/container-declared-test.yang");
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(containerStmtModule);
    assertNotNull(schemaContext);
    final Module testModule = schemaContext.findModules("container-declared-test").iterator().next();
    assertNotNull(testModule);
    final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "test-container"));
    assertNotNull(containerSchemaNode);
    final ContainerStatement containerStatement = ((ContainerEffectiveStatement) containerSchemaNode).getDeclared();
    final QName name = containerStatement.argument();
    assertNotNull(name);
    final WhenStatement containerStatementWhen = containerStatement.getWhenStatement().get();
    final Collection<? extends IfFeatureStatement> containerStatementIfFeatures = containerStatement.getIfFeatures();
    assertNotNull(containerStatementIfFeatures);
    assertEquals(1, containerStatementIfFeatures.size());
    final Collection<? extends MustStatement> containerStatementMusts = containerStatement.getMustStatements();
    assertNotNull(containerStatementMusts);
    assertEquals(1, containerStatementMusts.size());
    final PresenceStatement containerStatementPresence = containerStatement.getPresence();
    assertNotNull(containerStatementPresence);
    assertNotNull(containerStatementPresence.argument());
    assertTrue(containerStatement.getConfig().isPresent());
    assertTrue(containerStatement.getStatus().isPresent());
    assertTrue(containerStatement.getDescription().isPresent());
    assertTrue(containerStatement.getReference().isPresent());
    final Collection<? extends TypedefStatement> containerStatementTypedefs = containerStatement.getTypedefs();
    assertNotNull(containerStatementTypedefs);
    assertEquals(1, containerStatementTypedefs.size());
    final Collection<? extends GroupingStatement> containerStatementGroupings = containerStatement.getGroupings();
    assertNotNull(containerStatementGroupings);
    assertEquals(1, containerStatementGroupings.size());
    final Collection<? extends DataDefinitionStatement> containerStatementDataDefinitions = containerStatement.getDataDefinitions();
    assertNotNull(containerStatementDataDefinitions);
    assertEquals(1, containerStatementDataDefinitions.size());
}
Also used : PresenceStatement(org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement) StatementStreamSource(org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource) QName(org.opendaylight.yangtools.yang.common.QName) ContainerStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement) WhenStatement(org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 3 with ContainerStatement

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

the class YangParserWithContextTest method testUnknownNodes.

@Test
public void testUnknownNodes() throws ReactorException {
    final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild().addSources(IETF).addSource(sourceForResource("/types/custom-types-test@2012-04-04.yang")).addSource(sourceForResource("/context-test/test3.yang")).buildEffective();
    final Module module = context.findModule("test3", Revision.of("2013-06-18")).get();
    final ContainerStatement network = ((ContainerSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(), "network"))).asEffectiveStatement().getDeclared();
    final Collection<? extends UnrecognizedStatement> unknownNodes = network.declaredSubstatements(UnrecognizedStatement.class);
    assertEquals(1, unknownNodes.size());
    final UnrecognizedStatement un = unknownNodes.iterator().next();
    final QName unType = un.statementDefinition().getStatementName();
    assertEquals(XMLNamespace.of("urn:custom.types.demo"), unType.getNamespace());
    assertEquals(Revision.ofNullable("2012-04-16"), unType.getRevision());
    assertEquals("mountpoint", unType.getLocalName());
    assertEquals("point", un.argument());
}
Also used : UnrecognizedStatement(org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement) QName(org.opendaylight.yangtools.yang.common.QName) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) ContainerStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 QName (org.opendaylight.yangtools.yang.common.QName)3 ContainerStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement)3 Module (org.opendaylight.yangtools.yang.model.api.Module)2 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)2 ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)2 Revision (org.opendaylight.yangtools.yang.common.Revision)1 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 PresenceStatement (org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement)1 UnrecognizedStatement (org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement)1 WhenStatement (org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement)1 StatementStreamSource (org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource)1