Search in sources :

Example 11 with AnyxmlSchemaNode

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

the class DefinitionGenerator method processChoiceNode.

private void processChoiceNode(final Iterable<? extends DataSchemaNode> nodes, final String parentName, final ObjectNode definitions, final DefinitionNames definitionNames, final boolean isConfig, final SchemaInferenceStack stack, final ObjectNode properties, final OAversion oaversion) throws IOException {
    for (final DataSchemaNode node : nodes) {
        stack.enterSchemaTree(node.getQName());
        /*
                Add module name prefix to property name, when needed, when ServiceNow can process colons,
                use RestDocGenUtil#resolveNodesName for creating property name
             */
        final String name = node.getQName().getLocalName();
        final ObjectNode property;
        /*
                Ignore mandatoriness(passing unreferenced arrayNode to process...Node), because choice produces multiple
                properties
             */
        if (node instanceof LeafSchemaNode) {
            processLeafNode((LeafSchemaNode) node, name, properties, JsonNodeFactory.instance.arrayNode(), stack, definitions, definitionNames, oaversion);
        } else if (node instanceof AnyxmlSchemaNode) {
            processAnyXMLNode((AnyxmlSchemaNode) node, name, properties, JsonNodeFactory.instance.arrayNode());
        } else if (node instanceof AnydataSchemaNode) {
            processAnydataNode((AnydataSchemaNode) node, name, properties, JsonNodeFactory.instance.arrayNode());
        } else {
            if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) {
                property = processDataNodeContainer((DataNodeContainer) node, parentName, definitions, definitionNames, isConfig, stack, oaversion);
                if (!isConfig) {
                    processActionNodeContainer(node, parentName, definitions, definitionNames, stack, oaversion);
                }
            } else if (node instanceof LeafListSchemaNode) {
                property = processLeafListNode((LeafListSchemaNode) node, stack, definitions, definitionNames, oaversion);
            } else if (node instanceof ChoiceSchemaNode) {
                for (final CaseSchemaNode variant : ((ChoiceSchemaNode) node).getCases()) {
                    processChoiceNode(variant.getChildNodes(), parentName, definitions, definitionNames, isConfig, stack, properties, oaversion);
                }
                continue;
            } else {
                throw new IllegalArgumentException("Unknown DataSchemaNode type: " + node.getClass());
            }
            properties.set(name, property);
        }
        stack.exit();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)

Example 12 with AnyxmlSchemaNode

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

the class YangParserSimpleTest method testParseAnyXml.

@Test
public void testParseAnyXml() {
    final AnyxmlSchemaNode data = (AnyxmlSchemaNode) MODULE.getDataChildByName(QName.create(MODULE.getQNameModule(), "data"));
    assertFalse(data.equals(null));
    assertEquals("RegularAnyxmlEffectiveStatement{argument=(urn:opendaylight:simple-nodes?revision=2013-07-30)data}", data.toString());
    // test SchemaNode args
    assertEquals(QName.create(SN, "data"), data.getQName());
    assertEquals(Optional.of("anyxml desc"), data.getDescription());
    assertEquals(Optional.of("data ref"), data.getReference());
    assertEquals(Status.OBSOLETE, data.getStatus());
    assertEquals(0, data.getUnknownSchemaNodes().size());
    // test DataSchemaNode args
    assertFalse(data.isAugmenting());
    assertEquals(Optional.of(Boolean.FALSE), data.effectiveConfig());
    assertTrue(data.isMandatory());
    assertEquals("class != 'wheel'", data.getWhenCondition().orElseThrow().toString());
    final Collection<? extends MustDefinition> mustConstraints = data.getMustConstraints();
    assertEquals(2, mustConstraints.size());
    final String must1 = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
    final String must2 = "ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)";
    boolean found1 = false;
    boolean found2 = false;
    for (final MustDefinition must : mustConstraints) {
        if (must1.equals(must.getXpath().toString())) {
            found1 = true;
            assertEquals(Optional.of("An ethernet MTU must be 1500"), must.getErrorMessage());
        } else if (must2.equals(must.getXpath().toString())) {
            found2 = true;
            assertEquals(Optional.of("An atm MTU must be  64 .. 17966"), must.getErrorMessage());
            assertEquals(Optional.of("anyxml data error-app-tag"), must.getErrorAppTag());
            assertEquals(Optional.of("an error occured in data"), must.getDescription());
            assertEquals(Optional.of("data must ref"), must.getReference());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
}
Also used : MustDefinition(org.opendaylight.yangtools.yang.model.api.MustDefinition) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) Test(org.junit.Test)

Example 13 with AnyxmlSchemaNode

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

the class RpcStmtTest method rpcTest.

@Test
public void rpcTest() throws ReactorException {
    final EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild().addSource(sourceForResource("/model/baz.yang")).addSource(sourceForResource("/model/bar.yang")).addSource(sourceForResource("/rpc-stmt-test/foo.yang")).buildEffective();
    assertNotNull(result);
    final Module testModule = result.findModules("baz").iterator().next();
    assertEquals(1, testModule.getRpcs().size());
    final RpcDefinition rpc = testModule.getRpcs().iterator().next();
    assertEquals("get-config", rpc.getQName().getLocalName());
    final InputSchemaNode input = rpc.getInput();
    assertNotNull(input);
    assertEquals(2, input.getChildNodes().size());
    final ContainerSchemaNode container = (ContainerSchemaNode) input.getDataChildByName(QName.create(testModule.getQNameModule(), "source"));
    assertNotNull(container);
    AnyxmlSchemaNode anyXml = (AnyxmlSchemaNode) input.getDataChildByName(QName.create(testModule.getQNameModule(), "filter"));
    assertNotNull(anyXml);
    final OutputSchemaNode output = rpc.getOutput();
    assertNotNull(output);
    assertEquals(1, output.getChildNodes().size());
    anyXml = (AnyxmlSchemaNode) output.getDataChildByName(QName.create(testModule.getQNameModule(), "data"));
    assertNotNull(anyXml);
    final Module fooModule = result.findModule("foo", Revision.of("2016-09-23")).get();
    final Collection<? extends RpcDefinition> rpcs = fooModule.getRpcs();
    assertEquals(2, rpcs.size());
    RpcDefinition fooRpc1 = null;
    RpcDefinition fooRpc2 = null;
    for (RpcDefinition rpcDefinition : rpcs) {
        if ("foo-rpc-1".equals(rpcDefinition.getQName().getLocalName())) {
            fooRpc1 = rpcDefinition;
        } else if ("foo-rpc-2".equals(rpcDefinition.getQName().getLocalName())) {
            fooRpc2 = rpcDefinition;
        }
    }
    assertFalse(fooRpc1.equals(null));
    assertFalse(fooRpc1.equals("str"));
    assertFalse(fooRpc1.equals(fooRpc2));
    assertNotEquals(fooRpc1.getInput().hashCode(), fooRpc2.getInput().hashCode());
    assertNotEquals(fooRpc1.getOutput().hashCode(), fooRpc2.getOutput().hashCode());
    assertTrue(fooRpc1.getInput().equals(fooRpc1.getInput()));
    assertFalse(fooRpc1.getInput().equals(null));
    assertFalse(fooRpc1.getInput().equals("str"));
    assertFalse(fooRpc1.getInput().equals(fooRpc2.getInput()));
    assertTrue(fooRpc1.getOutput().equals(fooRpc1.getOutput()));
    assertFalse(fooRpc1.getOutput().equals(null));
    assertFalse(fooRpc1.getOutput().equals("str"));
    assertFalse(fooRpc1.getOutput().equals(fooRpc2.getOutput()));
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) Test(org.junit.Test)

Example 14 with AnyxmlSchemaNode

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

the class DeviationResolutionTest method testDeviateAdd.

@Test
public void testDeviateAdd() throws Exception {
    final EffectiveModelContext schemaContext = TestUtils.parseYangSource("/deviation-resolution-test/deviation-add/foo.yang", "/deviation-resolution-test/deviation-add/bar.yang");
    assertNotNull(schemaContext);
    final Module barModule = schemaContext.findModule("bar", Revision.of("2017-01-20")).get();
    final LeafListSchemaNode myLeafList = (LeafListSchemaNode) barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "my-leaf-list"));
    assertNotNull(myLeafList);
    assertEquals(Optional.of(Boolean.FALSE), myLeafList.effectiveConfig());
    assertEquals(3, myLeafList.getDefaults().size());
    final ElementCountConstraint constraint = myLeafList.getElementCountConstraint().get();
    assertEquals((Object) 10, constraint.getMaxElements());
    assertEquals((Object) 5, constraint.getMinElements());
    assertNotNull(myLeafList.getType().getUnits());
    final ListSchemaNode myList = (ListSchemaNode) barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "my-list"));
    assertNotNull(myList);
    assertEquals(2, myList.getUniqueConstraints().size());
    final ChoiceSchemaNode myChoice = (ChoiceSchemaNode) barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "my-choice"));
    assertNotNull(myChoice);
    assertEquals("c2", myChoice.getDefaultCase().get().getQName().getLocalName());
    final RpcDefinition myRpc = barModule.getRpcs().iterator().next();
    final InputSchemaNode input = myRpc.getInput();
    assertEquals(2, input.getMustConstraints().size());
    final OutputSchemaNode output = myRpc.getOutput();
    assertEquals(2, output.getMustConstraints().size());
    final NotificationDefinition myNotification = barModule.getNotifications().iterator().next();
    assertEquals(2, myNotification.getMustConstraints().size());
    final AnyxmlSchemaNode myAnyxml = (AnyxmlSchemaNode) barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "my-anyxml"));
    assertNotNull(myAnyxml);
    assertTrue(myAnyxml.isMandatory());
    final AnydataSchemaNode myAnyData = (AnydataSchemaNode) barModule.findDataChildByName(QName.create(barModule.getQNameModule(), "my-anydata")).orElse(null);
    assertNotNull(myAnyData);
    assertTrue(myAnyData.isMandatory());
}
Also used : LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ElementCountConstraint(org.opendaylight.yangtools.yang.model.api.ElementCountConstraint) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) Module(org.opendaylight.yangtools.yang.model.api.Module) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) Test(org.junit.Test)

Example 15 with AnyxmlSchemaNode

use of org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode 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)

Aggregations

AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)22 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)15 Test (org.junit.Test)13 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)13 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)12 AnydataSchemaNode (org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode)10 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)10 Module (org.opendaylight.yangtools.yang.model.api.Module)10 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)8 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)7 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)6 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)5 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)4 GroupingDefinition (org.opendaylight.yangtools.yang.model.api.GroupingDefinition)4 DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)3 TypedDataSchemaNode (org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 QName (org.opendaylight.yangtools.yang.common.QName)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2