Search in sources :

Example 1 with ContainerEffectiveStatement

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

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());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) 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) Test(org.junit.Test)

Example 3 with ContainerEffectiveStatement

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());
}
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 4 with ContainerEffectiveStatement

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());
}
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 5 with ContainerEffectiveStatement

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

Aggregations

ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)6 Test (org.junit.Test)5 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)4 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)4 QName (org.opendaylight.yangtools.yang.common.QName)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)2 ContainerStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement)2 Revision (org.opendaylight.yangtools.yang.common.Revision)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)1 NotificationEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement)1 PresenceStatement (org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement)1 WhenStatement (org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement)1 StatementStreamSource (org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource)1