Search in sources :

Example 1 with AnyxmlEffectiveStatement

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

the class DeclaredStatementsTest method testDeclaredAnyXml.

@Test
public void testDeclaredAnyXml() throws ReactorException {
    final StatementStreamSource anyxmlStmtModule = sourceForResource("/declared-statements-test/anyxml-declared-test.yang");
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(anyxmlStmtModule);
    assertNotNull(schemaContext);
    final Module testModule = schemaContext.findModules("anyxml-declared-test").iterator().next();
    assertNotNull(testModule);
    final AnyxmlSchemaNode anyxmlSchemaNode = (AnyxmlSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "foobar"));
    assertNotNull(anyxmlSchemaNode);
    final AnyxmlStatement anyxmlStatement = ((AnyxmlEffectiveStatement) anyxmlSchemaNode).getDeclared();
    final QName name = anyxmlStatement.argument();
    assertNotNull(name);
    final WhenStatement whenStatement = anyxmlStatement.getWhenStatement().get();
    assertNotNull(whenStatement.argument());
    final DescriptionStatement whenStatementDescription = whenStatement.getDescription().get();
    assertTrue(whenStatement.getReference().isPresent());
    final Collection<? extends IfFeatureStatement> ifFeatureStatements = anyxmlStatement.getIfFeatures();
    assertNotNull(ifFeatureStatements);
    assertEquals(1, ifFeatureStatements.size());
    final Predicate<Set<QName>> ifFeaturePredicate = ifFeatureStatements.iterator().next().getIfFeaturePredicate();
    assertNotNull(ifFeaturePredicate);
    final Collection<? extends MustStatement> mustStatements = anyxmlStatement.getMustStatements();
    assertNotNull(mustStatements);
    assertEquals(1, mustStatements.size());
    final MustStatement mustStatement = mustStatements.iterator().next();
    assertNotNull(mustStatement.argument());
    assertTrue(mustStatement.getErrorAppTagStatement().isPresent());
    assertTrue(mustStatement.getErrorMessageStatement().isPresent());
    assertTrue(mustStatement.getDescription().isPresent());
    assertTrue(mustStatement.getReference().isPresent());
    final ConfigStatement configStatement = anyxmlStatement.getConfig().get();
    assertFalse(configStatement.getValue());
    final StatusStatement statusStatement = anyxmlStatement.getStatus().get();
    final Status status = statusStatement.argument();
    assertNotNull(status);
    final DescriptionStatement descriptionStatement = anyxmlStatement.getDescription().get();
    assertEquals("anyxml description", descriptionStatement.argument());
    final ReferenceStatement referenceStatement = anyxmlStatement.getReference().get();
    assertEquals("anyxml reference", referenceStatement.argument());
    assertTrue(anyxmlStatement.getMandatory().isPresent());
}
Also used : MustStatement(org.opendaylight.yangtools.yang.model.api.stmt.MustStatement) Status(org.opendaylight.yangtools.yang.model.api.Status) ConfigStatement(org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement) Set(java.util.Set) StatementStreamSource(org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource) QName(org.opendaylight.yangtools.yang.common.QName) ReferenceStatement(org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement) StatusStatement(org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) WhenStatement(org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement) DescriptionStatement(org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement) AnyxmlEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlEffectiveStatement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) AnyxmlStatement(org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlStatement) Test(org.junit.Test)

Example 2 with AnyxmlEffectiveStatement

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

the class YT1212Test method testActiontatementReuse.

@Test
public void testActiontatementReuse() throws Exception {
    final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/anyxml.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
    final AnyxmlEffectiveStatement grpFoo = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(AnyxmlEffectiveStatement.class).orElseThrow();
    final AnyxmlEffectiveStatement foo = module.findFirstEffectiveSubstatement(AnyxmlEffectiveStatement.class).orElseThrow();
    // The statements should not be the same due SchemaPath being part of ActionDefinition
    assertNotSame(foo, grpFoo);
    // The statements are instantiated in the same module, hence they should have the same argument
    assertSame(foo.argument(), grpFoo.argument());
    // All substatements are context-independent, hence they get reused
    assertSame(foo.effectiveSubstatements(), grpFoo.effectiveSubstatements());
}
Also used : AnyxmlEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 AnyxmlEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlEffectiveStatement)2 Set (java.util.Set)1 QName (org.opendaylight.yangtools.yang.common.QName)1 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)1 Status (org.opendaylight.yangtools.yang.model.api.Status)1 AnyxmlStatement (org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlStatement)1 ConfigStatement (org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement)1 DescriptionStatement (org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement)1 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)1 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)1 MustStatement (org.opendaylight.yangtools.yang.model.api.stmt.MustStatement)1 ReferenceStatement (org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement)1 StatusStatement (org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement)1 WhenStatement (org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement)1 StatementStreamSource (org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource)1