Search in sources :

Example 6 with InputSchemaNode

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

the class Bug9241Test method testImplicitInputAndOutputInAction.

@Test
public void testImplicitInputAndOutputInAction() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug9241/foo.yang");
    assertNotNull(schemaContext);
    final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-10-13")).get();
    final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(fooModule.getQNameModule(), "action-cont"));
    final ActionDefinition actionInCont = actionCont.getActions().iterator().next();
    final InputSchemaNode input = actionInCont.getInput();
    assertNotNull(input);
    assertEquals(1, input.getChildNodes().size());
    assertEquals(StatementOrigin.CONTEXT, ((EffectiveStatement<?, ?>) input).statementOrigin());
    final OutputSchemaNode output = actionInCont.getOutput();
    assertNotNull(output);
    assertEquals(1, output.getChildNodes().size());
    assertEquals(StatementOrigin.CONTEXT, ((EffectiveStatement<?, ?>) output).statementOrigin());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) Test(org.junit.Test)

Example 7 with InputSchemaNode

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

the class OperationAsContainer method getChildNodes.

@Override
public final Collection<? extends DataSchemaNode> getChildNodes() {
    final List<DataSchemaNode> ret = new ArrayList<>();
    final InputSchemaNode input = getInput();
    if (input != null) {
        ret.add(input);
    }
    final OutputSchemaNode output = getOutput();
    if (output != null) {
        ret.add(output);
    }
    return ret;
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) ArrayList(java.util.ArrayList) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode)

Example 8 with InputSchemaNode

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

the class RpcStmtTest method testImplicitInputAndOutput.

@Test
public void testImplicitInputAndOutput() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rpc-stmt-test/bar.yang");
    assertNotNull(schemaContext);
    final Module barModule = schemaContext.findModule("bar", Revision.of("2016-11-25")).get();
    final Collection<? extends RpcDefinition> rpcs = barModule.getRpcs();
    assertEquals(1, rpcs.size());
    final RpcDefinition barRpc = rpcs.iterator().next();
    final InputSchemaNode input = barRpc.getInput();
    assertNotNull(input);
    assertEquals(2, input.getChildNodes().size());
    assertEquals(StatementOrigin.CONTEXT, ((EffectiveStatement<?, ?>) input).statementOrigin());
    final OutputSchemaNode output = barRpc.getOutput();
    assertNotNull(output);
    assertEquals(2, output.getChildNodes().size());
    assertEquals(StatementOrigin.CONTEXT, ((EffectiveStatement<?, ?>) output).statementOrigin());
}
Also used : RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 9 with InputSchemaNode

use of org.opendaylight.yangtools.yang.model.api.InputSchemaNode 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 10 with InputSchemaNode

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

Aggregations

InputSchemaNode (org.opendaylight.yangtools.yang.model.api.InputSchemaNode)10 OutputSchemaNode (org.opendaylight.yangtools.yang.model.api.OutputSchemaNode)8 Test (org.junit.Test)7 Module (org.opendaylight.yangtools.yang.model.api.Module)7 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)6 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 ActionDefinition (org.opendaylight.yangtools.yang.model.api.ActionDefinition)2 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)2 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)2 NotificationDefinition (org.opendaylight.yangtools.yang.model.api.NotificationDefinition)2 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DOMResult (javax.xml.transform.dom.DOMResult)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 QName (org.opendaylight.yangtools.yang.common.QName)1