use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class YT1212Test method testLeafStatementReuse.
@Test
public void testLeafStatementReuse() throws Exception {
final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/leaf.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final LeafEffectiveStatement grpFoo = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
final LeafEffectiveStatement foo = module.findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
// The statements should not be the same due SchemaPath being part of LeafSchemaNode
assertNotSame(foo, grpFoo);
// The statements are instantiated in the same module, hence they should have the same argument
assertSame(foo.argument(), grpFoo.argument());
// The 'type' is not context-independent, but it being copy-insensitive and statements get reused
assertSame(foo.effectiveSubstatements(), grpFoo.effectiveSubstatements());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement 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());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class YT1312Test method testRefineDefault.
@Test
public void testRefineDefault() throws Exception {
final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1312/foo.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final LeafListEffectiveStatement grpFoo = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(LeafListEffectiveStatement.class).orElseThrow();
final LeafListEffectiveStatement foo = module.findFirstEffectiveSubstatement(LeafListEffectiveStatement.class).orElseThrow();
assertNotSame(foo, grpFoo);
assertEquals(Optional.empty(), grpFoo.findFirstEffectiveSubstatementArgument(DefaultEffectiveStatement.class));
assertEquals(Optional.of("abc"), foo.findFirstEffectiveSubstatementArgument(DefaultEffectiveStatement.class));
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class DefaultSchemaTreeInference method of.
/**
* Create a new instance.
*
* @param modelContext Associated {@link EffectiveModelContext}
* @param path An absolute schema node identifier
* @return A new instance
*/
public static DefaultSchemaTreeInference of(final EffectiveModelContext modelContext, final Absolute path) {
final List<QName> steps = path.getNodeIdentifiers();
final QName first = steps.get(0);
final ModuleEffectiveStatement module = modelContext.findModuleStatement(first.getModule()).orElseThrow(() -> new IllegalArgumentException("No module for " + first));
final ImmutableList.Builder<SchemaTreeEffectiveStatement<?>> builder = ImmutableList.builderWithExpectedSize(steps.size());
SchemaTreeAwareEffectiveStatement<?, ?> parent = module;
final Iterator<QName> it = steps.iterator();
while (true) {
final QName qname = it.next();
final SchemaTreeEffectiveStatement<?> found = parent.findSchemaTreeNode(qname).orElseThrow(() -> new IllegalArgumentException("Cannot resolve step " + qname + " in " + builder.build()));
builder.add(found);
if (it.hasNext()) {
checkArgument(found instanceof SchemaTreeAwareEffectiveStatement, "Cannot resolve steps %s past %s", steps, found);
parent = (SchemaTreeAwareEffectiveStatement<?, ?>) found;
} else {
break;
}
}
return new DefaultSchemaTreeInference(modelContext, builder.build());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class EffectiveSchemaContextTest method testEffectiveSchemaContext.
@Test
public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException, YangSyntaxErrorException {
final EffectiveSchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild().addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/foo.yang")).addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/bar.yang")).addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/baz.yang")).buildEffective();
assertNotNull(schemaContext);
final Collection<? extends DataSchemaNode> dataDefinitions = schemaContext.getDataDefinitions();
assertEquals(3, dataDefinitions.size());
final Collection<? extends DataSchemaNode> childNodes = schemaContext.getChildNodes();
assertEquals(3, childNodes.size());
final Collection<? extends NotificationDefinition> notifications = schemaContext.getNotifications();
assertEquals(3, notifications.size());
final Collection<? extends RpcDefinition> rpcs = schemaContext.getOperations();
assertEquals(3, rpcs.size());
final Collection<? extends ExtensionDefinition> extensions = schemaContext.getExtensions();
assertEquals(3, extensions.size());
for (ModuleEffectiveStatement module : schemaContext.getModuleStatements().values()) {
assertEquals(1, module.getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
}
assertNull(schemaContext.dataChildByName(QName.create("foo-namespace", "2016-09-21", "foo-cont")));
assertFalse(schemaContext.findModule("foo", Revision.of("2016-08-21")).isPresent());
assertFalse(schemaContext.findModule(XMLNamespace.of("foo-namespace"), Revision.of("2016-08-21")).isPresent());
assertFalse(schemaContext.isAugmenting());
assertFalse(schemaContext.isAddedByUses());
assertEquals(Optional.empty(), schemaContext.effectiveConfig());
assertFalse(schemaContext.getWhenCondition().isPresent());
assertEquals(0, schemaContext.getMustConstraints().size());
assertFalse(schemaContext.getDescription().isPresent());
assertFalse(schemaContext.getReference().isPresent());
assertEquals(SchemaContext.NAME, schemaContext.getQName());
assertEquals(Status.CURRENT, schemaContext.getStatus());
assertNotNull(schemaContext.getUses());
assertTrue(schemaContext.getUses().isEmpty());
assertNotNull(schemaContext.getAvailableAugmentations());
assertTrue(schemaContext.getAvailableAugmentations().isEmpty());
assertTrue(schemaContext.findModule("foo", Revision.of("2016-09-21")).isPresent());
assertEquals(3, schemaContext.getModules().size());
assertEquals(3, schemaContext.getRootDeclaredStatements().size());
assertEquals(3, schemaContext.getModuleStatements().size());
}
Aggregations