Search in sources :

Example 1 with OutputSchemaNode

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

the class Bug6871Test method testValidYang11Model.

@Test
public void testValidYang11Model() {
    final Module foo = assertEffectiveModel("/rfc7950/bug6871/foo.yang").findModule("foo", Revision.of("2016-12-14")).orElseThrow();
    final var notifications = foo.getNotifications();
    assertEquals(1, notifications.size());
    final NotificationDefinition myNotification = notifications.iterator().next();
    var mustConstraints = myNotification.getMustConstraints();
    assertEquals(2, mustConstraints.size());
    final var rpcs = foo.getRpcs();
    assertEquals(1, rpcs.size());
    final RpcDefinition myRpc = rpcs.iterator().next();
    final InputSchemaNode input = myRpc.getInput();
    assertNotNull(input);
    mustConstraints = input.getMustConstraints();
    assertEquals(2, mustConstraints.size());
    final OutputSchemaNode output = myRpc.getOutput();
    assertNotNull(output);
    mustConstraints = output.getMustConstraints();
    assertEquals(2, mustConstraints.size());
}
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) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) Module(org.opendaylight.yangtools.yang.model.api.Module) AbstractYangTest(org.opendaylight.yangtools.yang.stmt.AbstractYangTest) Test(org.junit.Test)

Example 2 with OutputSchemaNode

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

the class YinFileRpcStmtTest method testRpc.

@Test
public void testRpc() {
    Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
    Collection<? extends RpcDefinition> rpcs = testModule.getRpcs();
    assertEquals(1, rpcs.size());
    RpcDefinition rpc = rpcs.iterator().next();
    assertEquals("get-schema", rpc.getQName().getLocalName());
    assertEquals(Optional.of("This operation is used to retrieve a schema from the\n" + "NETCONF server.\n" + "\n" + "Positive Response:\n" + "The NETCONF server returns the requested schema.\n" + "\n" + "Negative Response:\n" + "If requested schema does not exist, the <error-tag> is\n" + "'invalid-value'.\n" + "\n" + "If more than one schema matches the requested parameters, the\n" + "<error-tag> is 'operation-failed', and <error-app-tag> is\n" + "'data-not-unique'."), rpc.getDescription());
    InputSchemaNode input = rpc.getInput();
    assertNotNull(input);
    assertEquals(3, input.getChildNodes().size());
    OutputSchemaNode output = rpc.getOutput();
    assertNotNull(output);
    assertEquals(1, output.getChildNodes().size());
}
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) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 3 with OutputSchemaNode

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

the class OperationBuilder method buildPostOperation.

public static ObjectNode buildPostOperation(final OperationDefinition operDef, final String moduleName, final Optional<String> deviceName, final String parentName, final DefinitionNames definitionNames, final OAversion oaversion) {
    final ObjectNode postOperation = JsonNodeFactory.instance.objectNode();
    final ArrayNode parameters = JsonNodeFactory.instance.arrayNode();
    final String operName = operDef.getQName().getLocalName();
    final String inputName = operName + INPUT_SUFFIX;
    final InputSchemaNode input = operDef.getInput();
    final OutputSchemaNode output = operDef.getOutput();
    if (!input.getChildNodes().isEmpty()) {
        final String discriminator = definitionNames.getDiscriminator(input);
        final String clearDefName = parentName + "_" + operName + INPUT_SUFFIX;
        final String defName = clearDefName + discriminator;
        final String defTopName = clearDefName + TOP + discriminator;
        insertRequestBodyParameter(parameters, postOperation, defTopName, defName, inputName, oaversion);
    } else {
        final ObjectNode payload = JsonNodeFactory.instance.objectNode();
        final ObjectNode jsonSchema = JsonNodeFactory.instance.objectNode();
        final ObjectNode properties = JsonNodeFactory.instance.objectNode();
        final ObjectNode inputSchema = JsonNodeFactory.instance.objectNode();
        inputSchema.put(TYPE_KEY, OBJECT);
        properties.set(INPUT_KEY, inputSchema);
        jsonSchema.put(TYPE_KEY, OBJECT);
        jsonSchema.set(PROPERTIES_KEY, properties);
        if (oaversion.equals(OAversion.V3_0)) {
            final ObjectNode content = JsonNodeFactory.instance.objectNode();
            final ObjectNode jsonTypeValue = JsonNodeFactory.instance.objectNode();
            jsonTypeValue.set(SCHEMA_KEY, jsonSchema);
            content.set(MediaType.APPLICATION_JSON, jsonTypeValue);
            final ObjectNode xmlSchema = JsonNodeFactory.instance.objectNode();
            xmlSchema.put(TYPE_KEY, OBJECT);
            final ObjectNode xml = JsonNodeFactory.instance.objectNode();
            xml.put(NAME_KEY, INPUT);
            xmlSchema.set(XML_KEY, xml);
            final ObjectNode xmlTypeValue = JsonNodeFactory.instance.objectNode();
            xmlTypeValue.set(SCHEMA_KEY, xmlSchema);
            content.set(MediaType.APPLICATION_XML, xmlTypeValue);
            payload.set(CONTENT_KEY, content);
            payload.put(DESCRIPTION_KEY, inputName);
            postOperation.set(REQUEST_BODY_KEY, payload);
        } else {
            payload.put(IN_KEY, BODY);
            payload.put(NAME_KEY, inputName);
            payload.set(SCHEMA_KEY, jsonSchema);
            parameters.add(payload);
        }
    }
    setConsumesIfNeeded(postOperation, oaversion);
    postOperation.set(PARAMETERS_KEY, parameters);
    final ObjectNode responses = JsonNodeFactory.instance.objectNode();
    final String description = String.format("RPC %s success", operName);
    if (!output.getChildNodes().isEmpty()) {
        final ObjectNode schema = JsonNodeFactory.instance.objectNode();
        final String defName = parentName + "_" + operName + OUTPUT_SUFFIX + TOP + definitionNames.getDiscriminator(output);
        schema.put(REF_KEY, getAppropriateModelPrefix(oaversion) + defName);
        responses.set(String.valueOf(Response.Status.OK.getStatusCode()), buildResponse(description, Optional.of(schema), oaversion));
    } else {
        responses.set(String.valueOf(Response.Status.NO_CONTENT.getStatusCode()), buildResponse(description, Optional.empty(), oaversion));
    }
    postOperation.set(RESPONSES_KEY, responses);
    postOperation.put(DESCRIPTION_KEY, operDef.getDescription().orElse(""));
    postOperation.put(SUMMARY_KEY, buildSummaryValue(HttpMethod.POST, moduleName, deviceName, operName));
    postOperation.set(TAGS_KEY, buildTagsValue(deviceName, moduleName));
    return postOperation;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 4 with OutputSchemaNode

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

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

Aggregations

InputSchemaNode (org.opendaylight.yangtools.yang.model.api.InputSchemaNode)8 OutputSchemaNode (org.opendaylight.yangtools.yang.model.api.OutputSchemaNode)8 Test (org.junit.Test)6 Module (org.opendaylight.yangtools.yang.model.api.Module)6 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)5 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)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 ArrayList (java.util.ArrayList)1 ActionDefinition (org.opendaylight.yangtools.yang.model.api.ActionDefinition)1 AnydataSchemaNode (org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode)1 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)1 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)1 ElementCountConstraint (org.opendaylight.yangtools.yang.model.api.ElementCountConstraint)1 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)1 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)1