Search in sources :

Example 66 with DefaultDOMRpcResult

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());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) WebApplicationException(javax.ws.rs.WebApplicationException) QName(org.opendaylight.yangtools.yang.common.QName) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test)

Example 67 with DefaultDOMRpcResult

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());
}
Also used : ContainerLike(org.opendaylight.yangtools.yang.model.api.ContainerLike) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 68 with DefaultDOMRpcResult

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.
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 69 with DefaultDOMRpcResult

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);
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DataContainerNode(org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 70 with DefaultDOMRpcResult

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());
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)72 Test (org.junit.Test)51 QName (org.opendaylight.yangtools.yang.common.QName)27 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)25 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)25 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)15 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)15 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)12 Before (org.junit.Before)10 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)10 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)10 NetconfBaseOps (org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps)9 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)5 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)5 RpcError (org.opendaylight.yangtools.yang.common.RpcError)5 ArrayList (java.util.ArrayList)4 NormalizedNodeMessage (org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)4