Search in sources :

Example 1 with GroupingDefinition

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

the class SchemaInferenceStackTest method findDataSchemaNodeTest2.

@Test
public void findDataSchemaNodeTest2() {
    final QName myLeafInGrouping2 = QName.create(myModule.getQNameModule(), "my-leaf-in-gouping2");
    final PathExpression expr = mock(PathExpression.class);
    doReturn(true).when(expr).isAbsolute();
    doReturn(new LocationPathSteps(YangLocationPath.relative(YangXPathAxis.CHILD.asStep(myLeafInGrouping2)))).when(expr).getSteps();
    final GroupingDefinition grouping = getGroupingByName(myModule, "my-grouping");
    final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
    assertSame(grouping, stack.enterGrouping(grouping.getQName()));
    assertEquals(grouping.getDataChildByName(myLeafInGrouping2), stack.resolvePathExpression(expr));
}
Also used : PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) QName(org.opendaylight.yangtools.yang.common.QName) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Test(org.junit.Test)

Example 2 with GroupingDefinition

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

the class YT1050Test method before.

@Before
public void before() {
    context = YangParserTestUtils.parseYangResource("/yt1050.yang");
    module = context.getModules().iterator().next();
    final ListSchemaNode grpUses = (ListSchemaNode) module.findDataChildByName(GRP_USES).get();
    primaryType = (LeafSchemaNode) grpUses.findDataChildByName(TYPE).get();
    final GroupingDefinition grp = module.getGroupings().iterator().next();
    secondaryType = (LeafSchemaNode) ((ListSchemaNode) grp.findDataChildByName(SECONDARY).get()).findDataChildByName(TYPE).get();
}
Also used : ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Before(org.junit.Before)

Example 3 with GroupingDefinition

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

the class SchemaContextProxyTest method testGetGroupings.

@Test
public void testGetGroupings() {
    final Module moduleConfig = mockModule(CONFIG_NAME);
    final SchemaContext schemaContext = mockSchema(moduleConfig);
    final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, new HashSet<>(), moduleConfig);
    final GroupingDefinition mockedGrouping = mock(GroupingDefinition.class);
    final Set<GroupingDefinition> groupings = Collections.singleton(mockedGrouping);
    doReturn(groupings).when(moduleConfig).getGroupings();
    final Collection<? extends GroupingDefinition> schemaContextProxyGroupings = filteringSchemaContextProxy.getGroupings();
    assertTrue(schemaContextProxyGroupings.contains(mockedGrouping));
}
Also used : SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) AbstractSchemaContext(org.opendaylight.yangtools.yang.model.spi.AbstractSchemaContext) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Test(org.junit.Test)

Example 4 with GroupingDefinition

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

the class UsesStatementSupport method createEffective.

@Override
protected UsesEffectiveStatement createEffective(final Current<QName, UsesStatement> stmt, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    final EffectiveStatement<?, ?> source = verifyNotNull(stmt.getFromNamespace(SourceGroupingNamespace.class, Empty.value())).buildEffective();
    verify(source instanceof GroupingDefinition, "Unexpected source %s", source);
    final GroupingDefinition sourceGrouping = (GroupingDefinition) source;
    final int flags = EffectiveStmtUtils.historyAndStatusFlags(stmt.history(), substatements);
    final QName argument = stmt.getArgument();
    final UsesStatement declared = stmt.declared();
    if (substatements.isEmpty()) {
        return argument.equals(declared.argument()) ? new EmptyLocalUsesEffectiveStatement(declared, sourceGrouping, flags) : new SimpleCopiedUsesEffectiveStatement(declared, argument, sourceGrouping, flags);
    }
    if (declared.argument().equals(argument)) {
        return new RegularLocalUsesEffectiveStatement(declared, sourceGrouping, flags, substatements);
    }
    if (findFirstStatement(substatements, RefineEffectiveStatement.class) == null) {
        return new SimpleCopiedUsesEffectiveStatement(declared, argument, sourceGrouping, flags, substatements);
    }
    return new FullCopiedUsesEffectiveStatement(declared, argument, sourceGrouping, flags, substatements);
}
Also used : UsesStatement(org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement) RefineEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.RefineEffectiveStatement) ModuleCtxToModuleQName(org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName) QName(org.opendaylight.yangtools.yang.common.QName) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition)

Example 5 with GroupingDefinition

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

the class EffectiveBuildTest method extensionsTest.

@Test
public void extensionsTest() throws ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
    assertNotNull(result);
    Collection<? extends GroupingDefinition> groupings = result.getGroupings();
    assertEquals(1, groupings.size());
    GroupingDefinition grp = groupings.iterator().next();
    Collection<? extends DataSchemaNode> childNodes = grp.getChildNodes();
    assertEquals(1, childNodes.size());
    DataSchemaNode child = childNodes.iterator().next();
    assertTrue(child instanceof LeafSchemaNode);
    LeafSchemaNode leaf = (LeafSchemaNode) child;
    assertNotNull(leaf.getType());
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Test(org.junit.Test)

Aggregations

GroupingDefinition (org.opendaylight.yangtools.yang.model.api.GroupingDefinition)18 Test (org.junit.Test)13 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)8 Module (org.opendaylight.yangtools.yang.model.api.Module)8 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)7 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)6 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)6 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)5 QName (org.opendaylight.yangtools.yang.common.QName)4 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)4 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)4 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)3 RestConfModule (org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 UsesNode (org.opendaylight.yangtools.yang.model.api.UsesNode)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Before (org.junit.Before)1 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)1 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)1