Search in sources :

Example 11 with GroupingDefinition

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

the class YangParserSimpleTest method testParseContainer.

@Test
public void testParseContainer() {
    final ContainerSchemaNode nodes = (ContainerSchemaNode) MODULE.getDataChildByName(QName.create(MODULE.getQNameModule(), "nodes"));
    // test SchemaNode args
    assertEquals(SN_NODES, nodes.getQName());
    assertEquals(Optional.of("nodes collection"), nodes.getDescription());
    assertEquals(Optional.of("nodes ref"), nodes.getReference());
    assertEquals(Status.CURRENT, nodes.getStatus());
    assertEquals(0, nodes.getUnknownSchemaNodes().size());
    // test DataSchemaNode args
    assertFalse(nodes.isAugmenting());
    assertEquals(Optional.of(Boolean.FALSE), nodes.effectiveConfig());
    // constraints
    assertEquals("class != 'wheel'", nodes.getWhenCondition().orElseThrow().toString());
    final Collection<? extends MustDefinition> mustConstraints = nodes.getMustConstraints();
    assertEquals(2, mustConstraints.size());
    final String must1 = "ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)";
    final String errMsg1 = "An atm MTU must be  64 .. 17966";
    final String must2 = "ifId != 0";
    boolean found1 = false;
    boolean found2 = false;
    for (final MustDefinition must : mustConstraints) {
        if (must1.equals(must.getXpath().toString())) {
            found1 = true;
            assertEquals(Optional.of(errMsg1), must.getErrorMessage());
        } else if (must2.equals(must.getXpath().toString())) {
            found2 = true;
            assertFalse(must.getErrorMessage().isPresent());
            assertFalse(must.getErrorAppTag().isPresent());
            assertFalse(must.getDescription().isPresent());
            assertFalse(must.getReference().isPresent());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(nodes.isPresenceContainer());
    // typedef
    final Collection<? extends TypeDefinition<?>> typedefs = nodes.getTypeDefinitions();
    assertEquals(1, typedefs.size());
    final TypeDefinition<?> nodesType = typedefs.iterator().next();
    final QName typedefQName = QName.create(SN, "nodes-type");
    assertEquals(typedefQName, nodesType.getQName());
    assertFalse(nodesType.getDescription().isPresent());
    assertFalse(nodesType.getReference().isPresent());
    assertEquals(Status.CURRENT, nodesType.getStatus());
    assertEquals(0, nodesType.getUnknownSchemaNodes().size());
    // child nodes
    // total size = 8: defined 6, inserted by uses 2
    assertEquals(8, nodes.getChildNodes().size());
    final LeafListSchemaNode added = (LeafListSchemaNode) nodes.getDataChildByName(QName.create(MODULE.getQNameModule(), "added"));
    assertEquals(QName.create(SN, "added"), added.getQName());
    assertEquals(QName.create(SN, "mytype"), added.getType().getQName());
    final ListSchemaNode links = (ListSchemaNode) nodes.getDataChildByName(QName.create(MODULE.getQNameModule(), "links"));
    assertFalse(links.isUserOrdered());
    final Collection<? extends GroupingDefinition> groupings = nodes.getGroupings();
    assertEquals(1, groupings.size());
    final GroupingDefinition nodeGroup = groupings.iterator().next();
    assertEquals(QName.create(SN, "node-group"), nodeGroup.getQName());
    final Collection<? extends UsesNode> uses = nodes.getUses();
    assertEquals(1, uses.size());
    final UsesNode use = uses.iterator().next();
    assertEquals(nodeGroup, use.getSourceGrouping());
}
Also used : LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) UsesNode(org.opendaylight.yangtools.yang.model.api.UsesNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) MustDefinition(org.opendaylight.yangtools.yang.model.api.MustDefinition) Test(org.junit.Test)

Example 12 with GroupingDefinition

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

the class OrderingTest method testOrderingNestedChildNodes2.

@Test
public void testOrderingNestedChildNodes2() throws Exception {
    final Collection<? extends GroupingDefinition> groupings = BAZ.getGroupings();
    assertEquals(1, groupings.size());
    final GroupingDefinition target = groupings.iterator().next();
    final Collection<? extends DataSchemaNode> childNodes = target.getChildNodes();
    final String[] expectedOrder = { "data", "how", "address", "port", "addresses" };
    final String[] actualOrder = new String[childNodes.size()];
    int offset = 0;
    for (final DataSchemaNode child : childNodes) {
        actualOrder[offset] = child.getQName().getLocalName();
        offset++;
    }
    assertArrayEquals(expectedOrder, actualOrder);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Test(org.junit.Test)

Example 13 with GroupingDefinition

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

the class EffectiveBuildTest method effectiveBuildTest.

@Test
public void effectiveBuildTest() throws ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSources(SIMPLE_MODULE).buildEffective();
    assertNotNull(result);
    Module simpleModule = result.findModules("simple-module").iterator().next();
    assertNotNull(simpleModule);
    final QName q1 = QName.create(SIMPLE_MODULE_QNAME, "root-container");
    final QName q2 = QName.create(SIMPLE_MODULE_QNAME, "sub-container");
    final QName q3 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container");
    final QName q4 = QName.create(SIMPLE_MODULE_QNAME, "root-container2");
    final QName q5 = QName.create(SIMPLE_MODULE_QNAME, "sub-container2");
    final QName q6 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container2");
    final QName q7 = QName.create(SIMPLE_MODULE_QNAME, "grp");
    ContainerSchemaNode rootCon = (ContainerSchemaNode) simpleModule.getDataChildByName(q1);
    assertNotNull(rootCon);
    ContainerSchemaNode subCon = (ContainerSchemaNode) rootCon.getDataChildByName(q2);
    assertNotNull(subCon);
    ContainerSchemaNode subSubCon = (ContainerSchemaNode) subCon.getDataChildByName(q3);
    assertNotNull(subSubCon);
    ContainerSchemaNode rootCon2 = (ContainerSchemaNode) simpleModule.getDataChildByName(q4);
    assertNotNull(rootCon2);
    ContainerSchemaNode subCon2 = (ContainerSchemaNode) rootCon2.getDataChildByName(q5);
    assertNotNull(subCon2);
    ContainerSchemaNode subSubCon2 = (ContainerSchemaNode) subCon2.getDataChildByName(q6);
    assertNotNull(subSubCon2);
    GroupingDefinition grp = simpleModule.getGroupings().iterator().next();
    assertNotNull(grp);
    assertEquals(q7, grp.getQName());
    ContainerSchemaNode grpSubCon2 = (ContainerSchemaNode) grp.getDataChildByName(q5);
    assertNotNull(grpSubCon2);
    ContainerSchemaNode grpSubSubCon2 = (ContainerSchemaNode) grpSubCon2.getDataChildByName(q6);
    assertNotNull(grpSubSubCon2);
    assertEquals(q3, subSubCon.getQName());
    assertEquals(q6, subSubCon2.getQName());
    assertEquals(q6, grpSubSubCon2.getQName());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Test(org.junit.Test)

Example 14 with GroupingDefinition

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

the class GroupingAndUsesStmtTest method groupingTest.

@Test
public void groupingTest() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSources(MODULE, GROUPING_MODULE).buildEffective();
    assertNotNull(result);
    final Module testModule = result.findModules("baz").iterator().next();
    assertNotNull(testModule);
    final Collection<? extends GroupingDefinition> groupings = testModule.getGroupings();
    assertEquals(1, groupings.size());
    final Iterator<? extends GroupingDefinition> groupingsIterator = groupings.iterator();
    final GroupingDefinition grouping = groupingsIterator.next();
    assertEquals("target", grouping.getQName().getLocalName());
    assertEquals(5, grouping.getChildNodes().size());
    final AnyxmlSchemaNode anyXmlNode = (AnyxmlSchemaNode) grouping.getDataChildByName(QName.create(testModule.getQNameModule(), "data"));
    assertNotNull(anyXmlNode);
    final ChoiceSchemaNode choiceNode = (ChoiceSchemaNode) grouping.getDataChildByName(QName.create(testModule.getQNameModule(), "how"));
    assertNotNull(choiceNode);
    final LeafSchemaNode leafNode = (LeafSchemaNode) grouping.getDataChildByName(QName.create(testModule.getQNameModule(), "address"));
    assertNotNull(leafNode);
    final ContainerSchemaNode containerNode = (ContainerSchemaNode) grouping.getDataChildByName(QName.create(testModule.getQNameModule(), "port"));
    assertNotNull(containerNode);
    final ListSchemaNode listNode = (ListSchemaNode) grouping.getDataChildByName(QName.create(testModule.getQNameModule(), "addresses"));
    assertNotNull(listNode);
    assertEquals(1, grouping.getGroupings().size());
    assertEquals("target-inner", grouping.getGroupings().iterator().next().getQName().getLocalName());
    assertEquals(1, grouping.getTypeDefinitions().size());
    assertEquals("group-type", grouping.getTypeDefinitions().iterator().next().getQName().getLocalName());
    final Collection<? extends UnrecognizedStatement> unknownSchemaNodes = grouping.asEffectiveStatement().getDeclared().declaredSubstatements(UnrecognizedStatement.class);
    assertEquals(1, unknownSchemaNodes.size());
    final UnrecognizedStatement extensionUse = unknownSchemaNodes.iterator().next();
    assertEquals("opendaylight", extensionUse.statementDefinition().getStatementName().getLocalName());
}
Also used : UnrecognizedStatement(org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) Test(org.junit.Test)

Example 15 with GroupingDefinition

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

the class GroupingTest method testCascadeUses.

@Test
public void testCascadeUses() throws Exception {
    final EffectiveModelContext loadModules = TestUtils.parseYangSource("/grouping-test/cascade-uses.yang");
    assertEquals(1, loadModules.getModules().size());
    final Module testModule = Iterables.getOnlyElement(loadModules.findModules("cascade-uses"));
    final QNameModule namespace = testModule.getQNameModule();
    final Collection<? extends GroupingDefinition> groupings = testModule.getGroupings();
    GroupingDefinition gu = null;
    GroupingDefinition gv = null;
    GroupingDefinition gx = null;
    GroupingDefinition gy = null;
    GroupingDefinition gz = null;
    GroupingDefinition gzz = null;
    for (final GroupingDefinition gd : groupings) {
        final String name = gd.getQName().getLocalName();
        switch(name) {
            case "grouping-U":
                gu = gd;
                break;
            case "grouping-V":
                gv = gd;
                break;
            case "grouping-X":
                gx = gd;
                break;
            case "grouping-Y":
                gy = gd;
                break;
            case "grouping-Z":
                gz = gd;
                break;
            case "grouping-ZZ":
                gzz = gd;
                break;
            default:
                break;
        }
    }
    assertNotNull(gu);
    assertNotNull(gv);
    assertNotNull(gx);
    assertNotNull(gy);
    assertNotNull(gz);
    assertNotNull(gzz);
    final QNameModule expectedModule = QNameModule.create(XMLNamespace.of("urn:grouping:cascade-uses"), Revision.of("2013-07-18"));
    // grouping-U
    Collection<? extends DataSchemaNode> childNodes = gu.getChildNodes();
    assertEquals(7, childNodes.size());
    final LeafSchemaNode leafGroupingU = (LeafSchemaNode) gu.getDataChildByName(QName.create(namespace, "leaf-grouping-U"));
    assertFalse(leafGroupingU.isAddedByUses());
    for (final DataSchemaNode childNode : childNodes) {
        if (!childNode.getQName().equals(leafGroupingU.getQName())) {
            assertIsAddedByUses(childNode, true);
        }
    }
    // grouping-V
    childNodes = gv.getChildNodes();
    assertEquals(4, childNodes.size());
    LeafSchemaNode leafGroupingV = null;
    ContainerSchemaNode containerGroupingV = null;
    for (final DataSchemaNode childNode : childNodes) {
        if ("leaf-grouping-V".equals(childNode.getQName().getLocalName())) {
            leafGroupingV = (LeafSchemaNode) childNode;
        } else if ("container-grouping-V".equals(childNode.getQName().getLocalName())) {
            containerGroupingV = (ContainerSchemaNode) childNode;
        } else {
            assertIsAddedByUses(childNode, true);
        }
    }
    assertNotNull(leafGroupingV);
    assertFalse(leafGroupingV.isAddedByUses());
    // grouping-V/container-grouping-V
    assertNotNull(containerGroupingV);
    assertFalse(containerGroupingV.isAddedByUses());
    assertEquals(QName.create(expectedModule, "container-grouping-V"), containerGroupingV.getQName());
    childNodes = containerGroupingV.getChildNodes();
    assertEquals(2, childNodes.size());
    for (final DataSchemaNode childNode : childNodes) {
        assertIsAddedByUses(childNode, true);
    }
    // grouping-V/container-grouping-V/leaf-grouping-X
    final LeafSchemaNode leafXinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName(QName.create(namespace, "leaf-grouping-X"));
    assertEquals(QName.create(expectedModule, "leaf-grouping-X"), leafXinContainerV.getQName());
    // grouping-V/container-grouping-V/leaf-grouping-Y
    final LeafSchemaNode leafYinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName(QName.create(namespace, "leaf-grouping-Y"));
    assertEquals(QName.create(expectedModule, "leaf-grouping-Y"), leafYinContainerV.getQName());
    // grouping-X
    childNodes = gx.getChildNodes();
    assertEquals(2, childNodes.size());
    // grouping-X/leaf-grouping-X
    final LeafSchemaNode leafXinGX = (LeafSchemaNode) gx.getDataChildByName(QName.create(namespace, "leaf-grouping-X"));
    assertFalse(leafXinGX.isAddedByUses());
    assertEquals(QName.create(expectedModule, "leaf-grouping-X"), leafXinGX.getQName());
    // grouping-X/leaf-grouping-Y
    final LeafSchemaNode leafYinGX = (LeafSchemaNode) gx.getDataChildByName(QName.create(namespace, "leaf-grouping-Y"));
    assertTrue(leafYinGX.isAddedByUses());
    assertEquals(QName.create(expectedModule, "leaf-grouping-Y"), leafYinGX.getQName());
    // grouping-Y
    childNodes = gy.getChildNodes();
    assertEquals(1, childNodes.size());
    // grouping-Y/leaf-grouping-Y
    final LeafSchemaNode leafYinGY = (LeafSchemaNode) gy.getDataChildByName(QName.create(namespace, "leaf-grouping-Y"));
    assertFalse(leafYinGY.isAddedByUses());
    assertEquals(QName.create(expectedModule, "leaf-grouping-Y"), leafYinGY.getQName());
    // grouping-Z
    childNodes = gz.getChildNodes();
    assertEquals(1, childNodes.size());
    // grouping-Z/leaf-grouping-Z
    final LeafSchemaNode leafZinGZ = (LeafSchemaNode) gz.getDataChildByName(QName.create(namespace, "leaf-grouping-Z"));
    assertFalse(leafZinGZ.isAddedByUses());
    assertEquals(QName.create(expectedModule, "leaf-grouping-Z"), leafZinGZ.getQName());
    // grouping-ZZ
    childNodes = gzz.getChildNodes();
    assertEquals(1, childNodes.size());
    // grouping-ZZ/leaf-grouping-ZZ
    final LeafSchemaNode leafZZinGZZ = (LeafSchemaNode) gzz.getDataChildByName(QName.create(namespace, "leaf-grouping-ZZ"));
    assertFalse(leafZZinGZZ.isAddedByUses());
    assertEquals(QName.create(expectedModule, "leaf-grouping-ZZ"), leafZZinGZZ.getQName());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) 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