import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.sal.common.util.RpcErrors;
-import org.opendaylight.controller.sal.common.util.Rpcs;
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;
import org.opendaylight.controller.sal.restconf.impl.StructuredData;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
CompositeNode payload = preparePayload();
when(mockedBrokerFacade.invokeRpc(any(QName.class), any(CompositeNode.class))).thenReturn(
- Futures.<RpcResult<CompositeNode>> immediateFuture(Rpcs.<CompositeNode> getRpcResult(true)));
+ Futures.<RpcResult<CompositeNode>> immediateFuture(RpcResultBuilder.<CompositeNode>success().build()));
StructuredData structData = restconf.invokeRpc("invoke-rpc-module:rpc-test", payload, uriInfo);
assertTrue(structData == null);
@Test
public void testInvokeRpcWithNoPayloadRpc_FailNoErrors() {
- RpcResult<CompositeNode> rpcResult = Rpcs.<CompositeNode> getRpcResult(false);
+ RpcResult<CompositeNode> rpcResult = RpcResultBuilder.<CompositeNode>failed().build();
BrokerFacade brokerFacade = mock(BrokerFacade.class);
when(
@Test
public void testInvokeRpcWithNoPayloadRpc_FailWithRpcError() {
- List<RpcError> rpcErrors = Arrays.asList(RpcErrors.getRpcError(null, "bogusTag", null, ErrorSeverity.ERROR,
- "foo", RpcError.ErrorType.TRANSPORT, null), RpcErrors.getRpcError("app-tag", "in-use", null,
- ErrorSeverity.WARNING, "bar", RpcError.ErrorType.RPC, null));
+ List<RpcError> rpcErrors = Arrays.asList(
+ RpcResultBuilder.newError( RpcError.ErrorType.TRANSPORT, "bogusTag", "foo" ),
+ RpcResultBuilder.newWarning( RpcError.ErrorType.RPC, "in-use", "bar",
+ "app-tag", null, null ) );
- RpcResult<CompositeNode> rpcResult = Rpcs.<CompositeNode> getRpcResult(false, rpcErrors);
+ RpcResult<CompositeNode> rpcResult = RpcResultBuilder.<CompositeNode>failed()
+ .withRpcErrors(rpcErrors).build();
BrokerFacade brokerFacade = mock(BrokerFacade.class);
when(
@Test
public void testInvokeRpcWithNoPayload_Success() {
- RpcResult<CompositeNode> rpcResult = Rpcs.<CompositeNode> getRpcResult(true);
+ RpcResult<CompositeNode> rpcResult = RpcResultBuilder.<CompositeNode>success().build();
BrokerFacade brokerFacade = mock(BrokerFacade.class);
when(
@Test
public void testInvokeRpcMethodWithInput() {
- RpcResult<CompositeNode> rpcResult = Rpcs.<CompositeNode> getRpcResult(true);
+ RpcResult<CompositeNode> rpcResult = RpcResultBuilder.<CompositeNode>success().build();
CompositeNode payload = mock(CompositeNode.class);
@Test
public void testInvokeRpcWithNoPayloadWithOutput_Success() {
CompositeNode compositeNode = mock(CompositeNode.class);
- RpcResult<CompositeNode> rpcResult = Rpcs.<CompositeNode> getRpcResult(true, compositeNode,
- Collections.<RpcError> emptyList());
+ RpcResult<CompositeNode> rpcResult =
+ RpcResultBuilder.<CompositeNode>success(compositeNode).build();
BrokerFacade brokerFacade = mock(BrokerFacade.class);
when(
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 = Rpcs.<CompositeNode> getRpcResult(true);
+ RpcResult<CompositeNode> rpcResult = RpcResultBuilder.<CompositeNode>success().build();
ListenableFuture<RpcResult<CompositeNode>> mockListener = mock(ListenableFuture.class);
when(mockListener.get()).thenReturn(rpcResult);
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<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.