use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class JSONRestconfServiceImplTest method testInvokeRpcWithInput.
@SuppressWarnings("rawtypes")
@Test
public void testInvokeRpcWithInput() throws Exception {
final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode) null);
doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(eq(MAKE_TOAST_QNAME), any(NormalizedNode.class));
final String uriPath = "toaster:make-toast";
final String input = loadData("/full-versions/make-toast-rpc-input.json");
final Optional<String> output = this.service.invokeRpc(uriPath, Optional.of(input));
assertEquals("Output present", false, output.isPresent());
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).invokeRpc(eq(MAKE_TOAST_QNAME), capturedNode.capture());
assertTrue("Expected ContainerNode. Actual " + capturedNode.getValue().getClass(), capturedNode.getValue() instanceof ContainerNode);
final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
verifyLeafNode(actualNode, TOASTER_DONENESS_QNAME, Uint32.valueOf(10));
verifyLeafNode(actualNode, TOASTER_TYPE_QNAME, WHEAT_BREAD_QNAME);
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class JSONRestconfServiceImplTest method testInvokeRpcWithOutput.
@Test
public void testInvokeRpcWithOutput() throws Exception {
final NormalizedNode outputNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_OUTPUT_QNAME)).withChild(ImmutableNodes.leafNode(TEXT_OUT_QNAME, "foo")).build();
final DOMRpcResult expResult = new DefaultDOMRpcResult(outputNode);
doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(any(QName.class), any());
final String uriPath = "toaster:testOutput";
final Optional<String> output = this.service.invokeRpc(uriPath, Optional.empty());
assertEquals("Output present", true, output.isPresent());
assertNotNull("Returned null response", output.get());
assertThat("Missing \"textOut\"", output.get(), containsString("\"textOut\":\"foo\""));
verify(brokerFacade).invokeRpc(eq(TEST_OUTPUT_QNAME), any());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class CreateStreamUtilTest method createStreamWrongValueTest.
@Test(expected = RestconfDocumentedException.class)
public void createStreamWrongValueTest() {
payload = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getInput, "String value", "path");
final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
assertEquals(result.getErrors(), Collections.emptyList());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class BrokerFacadeTest method testInvokeRpc.
@Test
public void testInvokeRpc() throws Exception {
final DOMRpcResult expResult = mock(DOMRpcResult.class);
doReturn(immediateFluentFuture(expResult)).when(this.mockRpcService).invokeRpc(this.qname, this.dummyNode);
final ListenableFuture<? extends DOMRpcResult> actualFuture = this.brokerFacade.invokeRpc(this.qname, this.dummyNode);
assertNotNull("Future is null", actualFuture);
final DOMRpcResult actualResult = actualFuture.get();
assertSame("invokeRpc", expResult, actualResult);
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class RestconfInvokeOperationsServiceImpl method invokeRpc.
@Override
public void invokeRpc(final String identifier, final NormalizedNodePayload payload, final UriInfo uriInfo, final AsyncResponse ar) {
final SchemaNode schema = payload.getInstanceIdentifierContext().getSchemaNode();
final QName rpcName = schema.getQName();
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final ListenableFuture<? extends DOMRpcResult> future;
final EffectiveModelContext schemaContextRef;
if (mountPoint == null) {
schemaContextRef = schemaContextHandler.get();
// FIXME: this really should be a normal RPC invocation service which has its own interface with JAX-RS
if (SAL_REMOTE_NAMESPACE.equals(rpcName.getNamespace())) {
if (identifier.contains("create-data-change-event-subscription")) {
future = Futures.immediateFuture(CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContextRef));
} else {
future = Futures.immediateFailedFuture(new RestconfDocumentedException("Unsupported operation", ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED));
}
} else {
future = invokeRpc(payload.getData(), rpcName, rpcService);
}
} else {
schemaContextRef = modelContext(mountPoint);
future = invokeRpc(payload.getData(), rpcName, mountPoint);
}
Futures.addCallback(future, new FutureCallback<DOMRpcResult>() {
@Override
public void onSuccess(final DOMRpcResult response) {
final var errors = response.getErrors();
if (!errors.isEmpty()) {
LOG.debug("RpcError message {}", response.getErrors());
ar.resume(new RestconfDocumentedException("RPCerror message ", null, response.getErrors()));
return;
}
final NormalizedNode resultData = response.getResult();
if (resultData == null || ((ContainerNode) resultData).isEmpty()) {
ar.resume(new WebApplicationException(Status.NO_CONTENT));
} else {
ar.resume(NormalizedNodePayload.of(new InstanceIdentifierContext<>(null, (RpcDefinition) schema, mountPoint, schemaContextRef), resultData));
}
}
@Override
public void onFailure(final Throwable failure) {
ar.resume(failure);
}
}, MoreExecutors.directExecutor());
}
Aggregations