X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FInvokeRpcMethodTest.java;h=9aab841546016a5cb09f669c168307b2aaf0f725;hp=313b766ed3312bad6cb5f74a542e84893226aa54;hb=79db355d656708bcaf66940627c4adc935ecb36d;hpb=6500c7a216b78417e65cdf882d2b78de27736a97 diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java index 313b766ed3..9aab841546 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java @@ -36,7 +36,6 @@ import javax.ws.rs.core.UriInfo; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; - import org.opendaylight.controller.sal.core.api.mount.MountInstance; import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; import org.opendaylight.controller.sal.restconf.impl.ControllerContext; @@ -94,7 +93,7 @@ public class InvokeRpcMethodTest { * string - first argument). */ @Test - public void invokeRpcMtethodTest() { + public void invokeRpcMethodTest() { ControllerContext contContext = controllerContext; try { contContext.findModuleNameByNamespace(new URI("invoke:rpc:module")); @@ -298,6 +297,14 @@ public class InvokeRpcMethodTest { assertNotNull(output.getSchema()); } + /** + * + * Tests calling of RestConfImpl method invokeRpc. In the method there is searched rpc in remote schema context. + * This rpc is then executed. + * + * I wasn't able to simulate calling of rpc on remote device therefore this testing method raise method when rpc is + * invoked. + */ @Test public void testMountedRpcCallNoPayload_Success() throws Exception { RpcResult rpcResult = RpcResultBuilder.success().build(); @@ -313,21 +320,32 @@ public class InvokeRpcMethodTest { MountInstance mockMountPoint = mock(MountInstance.class); when(mockMountPoint.rpc(eq(cancelToastQName), any(CompositeNode.class))).thenReturn(mockListener); + when(mockMountPoint.getSchemaContext()).thenReturn(TestUtils.loadSchemaContext("/invoke-rpc")); + InstanceIdWithSchemaNode mockedInstanceId = mock(InstanceIdWithSchemaNode.class); when(mockedInstanceId.getMountPoint()).thenReturn(mockMountPoint); ControllerContext mockedContext = mock(ControllerContext.class); - String cancelToastStr = "toaster:cancel-toast"; - when(mockedContext.urlPathArgDecode(cancelToastStr)).thenReturn(cancelToastStr); - when(mockedContext.getRpcDefinition(cancelToastStr)).thenReturn(mockRpc); + String rpcNoop = "invoke-rpc-module:rpc-noop"; + when(mockedContext.urlPathArgDecode(rpcNoop)).thenReturn(rpcNoop); + when(mockedContext.getRpcDefinition(rpcNoop)).thenReturn(mockRpc); when( - mockedContext.toMountPointIdentifier("opendaylight-inventory:nodes/node/" - + "REMOTE_HOST/yang-ext:mount/toaster:cancel-toast")).thenReturn(mockedInstanceId); + mockedContext.toMountPointIdentifier(eq("opendaylight-inventory:nodes/node/" + + "REMOTE_HOST/yang-ext:mount/invoke-rpc-module:rpc-noop"))).thenReturn(mockedInstanceId); restconfImpl.setControllerContext(mockedContext); - StructuredData output = restconfImpl.invokeRpc( - "opendaylight-inventory:nodes/node/REMOTE_HOST/yang-ext:mount/toaster:cancel-toast", "", uriInfo); - assertEquals(null, output); + try { + restconfImpl.invokeRpc( + "opendaylight-inventory:nodes/node/REMOTE_HOST/yang-ext:mount/invoke-rpc-module:rpc-noop", "", + uriInfo); + fail("RestconfDocumentedException wasn't raised"); + } catch (RestconfDocumentedException e) { + List errors = e.getErrors(); + assertNotNull(errors); + assertEquals(1, errors.size()); + assertEquals(ErrorType.APPLICATION, errors.iterator().next().getErrorType()); + assertEquals(ErrorTag.OPERATION_FAILED, errors.iterator().next().getErrorTag()); + } // additional validation in the fact that the restconfImpl does not // throw an exception.