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.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
-import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.controller.sal.restconf.impl.RestconfError;
import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
* string - first argument).
*/
@Test
- public void invokeRpcMtethodTest() {
+ public void invokeRpcMethodTest() {
ControllerContext contContext = controllerContext;
try {
contContext.findModuleNameByNamespace(new URI("invoke:rpc:module"));
restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
fail("Expected an exception to be thrown.");
} catch (RestconfDocumentedException e) {
- verifyRestconfDocumentedException(e, 0, ErrorType.RPC, ErrorTag.OPERATION_FAILED,
+ verifyRestconfDocumentedException(e, 0, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED,
Optional.<String> absent(), Optional.<String> absent());
}
}
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<CompositeNode> rpcResult = RpcResultBuilder.<CompositeNode>success().build();
RpcDefinition mockRpc = mock(RpcDefinition.class);
when(mockRpc.getQName()).thenReturn(cancelToastQName);
- MountInstance mockMountPoint = mock(MountInstance.class);
- when(mockMountPoint.rpc(eq(cancelToastQName), any(CompositeNode.class))).thenReturn(mockListener);
+ DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
+ RpcProvisionRegistry mockedRpcProvisionRegistry = mock(RpcProvisionRegistry.class);
+ when(mockedRpcProvisionRegistry.invokeRpc(eq(cancelToastQName), any(CompositeNode.class))).thenReturn(mockListener);
+ when(mockMountPoint.getService(eq(RpcProvisionRegistry.class))).thenReturn(Optional.of(mockedRpcProvisionRegistry));
+ when(mockMountPoint.getSchemaContext()).thenReturn(TestUtils.loadSchemaContext("/invoke-rpc"));
- InstanceIdWithSchemaNode mockedInstanceId = mock(InstanceIdWithSchemaNode.class);
+ InstanceIdentifierContext mockedInstanceId = mock(InstanceIdentifierContext.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<RestconfError> 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.