Search in sources :

Example 36 with ModuleEffectiveStatement

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

Example 37 with ModuleEffectiveStatement

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

Example 38 with ModuleEffectiveStatement

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

Example 39 with ModuleEffectiveStatement

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());
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ImmutableList(com.google.common.collect.ImmutableList) SchemaTreeAwareEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement) SchemaTreeEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)

Example 40 with ModuleEffectiveStatement

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

Aggregations

ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)45 Test (org.junit.Test)28 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)20 ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)12 NonNull (org.eclipse.jdt.annotation.NonNull)9 Objects.requireNonNull (java.util.Objects.requireNonNull)8 NotificationEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement)8 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)5 QName (org.opendaylight.yangtools.yang.common.QName)4 LeafEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement)4 LeafListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement)4 SubmoduleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement)4 ModuleStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 Revision (org.opendaylight.yangtools.yang.common.Revision)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 Module (org.opendaylight.yangtools.yang.model.api.Module)2