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