use of org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement 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.ContainerEffectiveStatement 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());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement 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.ContainerEffectiveStatement 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());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement 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;
}
Aggregations