use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult 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.spi.DefaultDOMRpcResult 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.spi.DefaultDOMRpcResult 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.
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult 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.spi.DefaultDOMRpcResult 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());
}
Aggregations