Search in sources :

Example 51 with DOMRpcResult

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());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) Test(org.junit.Test)

Example 52 with DOMRpcResult

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());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) RpcError(org.opendaylight.yangtools.yang.common.RpcError) DOMRpcException(org.opendaylight.mdsal.dom.api.DOMRpcException) Test(org.junit.Test)

Example 53 with DOMRpcResult

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());
}
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 54 with DOMRpcResult

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());
}
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 55 with DOMRpcResult

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.
}
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)

Aggregations

DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)61 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)39 Test (org.junit.Test)38 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 QName (org.opendaylight.yangtools.yang.common.QName)18 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)10 RpcError (org.opendaylight.yangtools.yang.common.RpcError)8 ExecutionException (java.util.concurrent.ExecutionException)7 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)7 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)7 ClusteringRpcException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException)6 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)5 InvokeRpcMessageReply (org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)5 DOMRpcImplementationNotAvailableException (org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException)4 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3