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