Enhancements to remote rpc server. Using zmq router-dealer bridge to make the server...
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / implementation / src / test / java / org / opendaylight / controller / sal / connector / remoterpc / ClientImplTest.java
1 package org.opendaylight.controller.sal.connector.remoterpc;
2
3 import com.google.common.base.Optional;
4 import junit.framework.Assert;
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Test;
8 import org.opendaylight.controller.sal.common.util.Rpcs;
9 import org.opendaylight.controller.sal.connector.remoterpc.api.RouteChangeListener;
10 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
11 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException;
12 import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException;
13 import org.opendaylight.controller.sal.connector.remoterpc.dto.Message;
14 import org.opendaylight.controller.sal.connector.remoterpc.utils.MessagingUtil;
15 import org.opendaylight.yangtools.yang.common.RpcError;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
18
19 import java.io.IOException;
20 import java.util.*;
21
22 import static org.mockito.Matchers.any;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25
26 /**
27  *
28  */
29 public class ClientImplTest {
30   RoutingTableProvider routingTableProvider;
31   ClientImpl client;
32   ClientRequestHandler mockHandler;
33
34   @Before
35   public void setUp() throws Exception {
36
37     //mock routing table
38     routingTableProvider = mock(RoutingTableProvider.class);
39     RoutingTable<String, String> mockRoutingTable = new MockRoutingTable<String, String>();
40     Optional<RoutingTable<String, String>> optionalRoutingTable = Optional.fromNullable(mockRoutingTable);
41     when(routingTableProvider.getRoutingTable()).thenReturn(optionalRoutingTable);
42
43     //mock ClientRequestHandler
44     mockHandler = mock(ClientRequestHandler.class);
45
46     client = new ClientImpl(mockHandler);
47     client.setRoutingTableProvider(routingTableProvider);
48
49   }
50
51   @After
52   public void tearDown() throws Exception {
53
54   }
55
56   @Test
57   public void getRoutingTableProvider_Call_ShouldReturnMockProvider() throws Exception {
58     Assert.assertEquals(routingTableProvider, client.getRoutingTableProvider());
59
60   }
61
62   @Test
63   public void testStart() throws Exception {
64
65   }
66
67   @Test
68   public void testStop() throws Exception {
69
70   }
71
72   @Test
73   public void testClose() throws Exception {
74
75   }
76
77   @Test
78   public void invokeRpc_NormalCall_ShouldReturnSuccess() throws Exception {
79
80     when(mockHandler.handle(any(Message.class))).
81             thenReturn(MessagingUtil.createEmptyMessage());
82
83     RpcResult<CompositeNode> result = client.invokeRpc(null, null);
84
85     Assert.assertTrue(result.isSuccessful());
86     Assert.assertTrue(result.getErrors().isEmpty());
87     Assert.assertNull(result.getResult());
88   }
89
90   @Test
91   public void invokeRpc_HandlerThrowsException_ShouldReturnError() throws Exception {
92
93     when(mockHandler.handle(any(Message.class))).
94             thenThrow(new IOException());
95
96     RpcResult<CompositeNode> result = client.invokeRpc(null, null);
97
98     Assert.assertFalse(result.isSuccessful());
99     Assert.assertFalse(result.getErrors().isEmpty());
100     Assert.assertNull(result.getResult());
101   }
102
103 }