use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class RestconfInvokeOperationsServiceImplTest method checkResponseTest.
@Test
public void checkResponseTest() throws InterruptedException, ExecutionException {
doReturn(immediateFluentFuture(new DefaultDOMRpcResult(OUTPUT, List.of()))).when(rpcService).invokeRpc(RPC, INPUT);
final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, RPC, rpcService).get();
assertTrue(rpcResult.getErrors().isEmpty());
assertEquals(OUTPUT, rpcResult.getResult());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class RestconfInvokeOperationsServiceImplTest method invokeRpcErrorsAndCheckTestTest.
@Test
public void invokeRpcErrorsAndCheckTestTest() throws InterruptedException, ExecutionException {
final QName errorRpc = QName.create(RPC, "error-rpc");
final DOMRpcException exception = new DOMRpcImplementationNotAvailableException("No implementation of RPC " + errorRpc + " available.");
doReturn(immediateFailedFluentFuture(exception)).when(rpcService).invokeRpc(errorRpc, INPUT);
final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, errorRpc, rpcService).get();
assertNull(rpcResult.getResult());
final Collection<? extends RpcError> errorList = rpcResult.getErrors();
assertEquals(1, errorList.size());
final RpcError actual = errorList.iterator().next();
assertEquals("No implementation of RPC " + errorRpc + " available.", actual.getMessage());
assertEquals("operation-failed", actual.getTag());
assertEquals(RpcError.ErrorType.RPC, actual.getErrorType());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class InvokeRpcMethodTest method testInvokeRpcWithEmptyOutput.
@Test
public void testInvokeRpcWithEmptyOutput() {
final ContainerNode resultObj = mock(ContainerNode.class);
doReturn(Set.of()).when(resultObj).body();
doCallRealMethod().when(resultObj).isEmpty();
final DOMRpcResult expResult = new DefaultDOMRpcResult(resultObj);
final QName qname = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(eq(qname), any());
WebApplicationException exceptionToBeThrown = assertThrows(WebApplicationException.class, () -> this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo));
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), exceptionToBeThrown.getResponse().getStatus());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class InvokeRpcMethodTest method testInvokeRpcWithNoPayloadWithOutput_Success.
@Test
public void testInvokeRpcWithNoPayloadWithOutput_Success() {
final SchemaContext schema = controllerContext.getGlobalSchema();
final Module rpcModule = schema.findModules("toaster").iterator().next();
assertNotNull(rpcModule);
final QName rpcQName = QName.create(rpcModule.getQNameModule(), "testOutput");
final QName rpcOutputQName = QName.create(rpcModule.getQNameModule(), "output");
RpcDefinition rpcDef = null;
ContainerLike rpcOutputSchemaNode = null;
for (final RpcDefinition rpc : rpcModule.getRpcs()) {
if (rpcQName.isEqualWithoutRevision(rpc.getQName())) {
rpcOutputSchemaNode = rpc.getOutput();
rpcDef = rpc;
break;
}
}
assertNotNull(rpcDef);
assertNotNull(rpcOutputSchemaNode);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = SchemaAwareBuilders.containerBuilder(rpcOutputSchemaNode);
final DataSchemaNode leafSchema = rpcOutputSchemaNode.getDataChildByName(QName.create(rpcModule.getQNameModule(), "textOut"));
assertTrue(leafSchema instanceof LeafSchemaNode);
final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) leafSchema);
leafBuilder.withValue("brm");
containerBuilder.withChild(leafBuilder.build());
final ContainerNode container = containerBuilder.build();
final DOMRpcResult result = new DefaultDOMRpcResult(container);
doReturn(immediateFluentFuture(result)).when(brokerFacade).invokeRpc(eq(rpcDef.getQName()), any());
final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:testOutput", null, uriInfo);
assertNotNull(output);
assertNotNull(output.getData());
assertSame(container, output.getData());
assertNotNull(output.getInstanceIdentifierContext());
assertNotNull(output.getInstanceIdentifierContext().getSchemaContext());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class InvokeRpcMethodTest method testInvokeRpcWithNoPayload_Success.
@Test
public void testInvokeRpcWithNoPayload_Success() {
final NormalizedNode resultObj = null;
final DOMRpcResult expResult = new DefaultDOMRpcResult(resultObj);
final QName qname = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(eq(qname), any());
final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo);
assertNotNull(output);
assertEquals(null, output.getData());
// additional validation in the fact that the restconfImpl does not
// throw an exception.
}
Aggregations