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());
}
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());
}
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;
}
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());
}
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;
}
Aggregations