Coverage - SalTableServiceImpl.
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / SalTableServiceImplTest.java
1 package org.opendaylight.openflowplugin.impl.services;
2
3 import junit.framework.TestCase;
4 import org.junit.Before;
5 import org.junit.Test;
6 import org.junit.runner.RunWith;
7 import org.mockito.Mock;
8 import org.mockito.runners.MockitoJUnitRunner;
9 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
10 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
11 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
12 import org.opendaylight.openflowplugin.api.OFConstants;
13 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
15 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
16 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
18 import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
19 import org.opendaylight.openflowplugin.impl.rpc.RpcContextImpl;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTable;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28
29 import java.math.BigInteger;
30 import java.util.Collections;
31 import java.util.concurrent.ExecutionException;
32 import java.util.concurrent.Future;
33
34 import static org.mockito.Mockito.when;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class SalTableServiceImplTest extends TestCase {
38
39     private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444");
40     private static final Short DUMMY_VERSION = OFConstants.OFP_VERSION_1_3;
41     private static final int DUMMY_MAX_REQUEST = 88;
42
43     @Mock
44     RequestContextStack mockedRequestContextStack;
45     @Mock
46     DeviceContext mockedDeviceContext;
47     @Mock
48     ConnectionContext mockedPrimConnectionContext;
49     @Mock
50     FeaturesReply mockedFeatures;
51     @Mock
52     ConnectionAdapter mockedConnectionAdapter;
53     @Mock
54     MessageSpy mockedMessagSpy;
55     @Mock
56     RpcProviderRegistry mockedRpcProviderRegistry;
57     @Mock
58     OutboundQueue mockedOutboundQueue;
59
60     @Before
61     public void initialization() {
62         when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
63         when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION);
64
65         when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
66         when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
67         when(mockedPrimConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
68
69         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
70
71         when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
72         when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
73     }
74
75     @Test
76     public void testUpdateTable() throws ExecutionException, InterruptedException {
77         final RpcContextImpl rpcContext = new RpcContextImpl(mockedMessagSpy,
78                 mockedRpcProviderRegistry, mockedDeviceContext, DUMMY_MAX_REQUEST);
79         final SalTableServiceImpl salTableService = new SalTableServiceImpl(rpcContext, mockedDeviceContext);
80         final Future<RpcResult<UpdateTableOutput>> rpcResultFuture = salTableService.updateTable(prepareUpdateTable());
81         assertNotNull(rpcResultFuture);
82     }
83
84     private UpdateTableInput prepareUpdateTable() {
85         UpdateTableInputBuilder updateTableInputBuilder = new UpdateTableInputBuilder();
86         UpdatedTableBuilder updatedTableBuilder = new UpdatedTableBuilder();
87         updatedTableBuilder.setTableFeatures(Collections.<TableFeatures>emptyList());
88         updateTableInputBuilder.setUpdatedTable(updatedTableBuilder.build());
89         return updateTableInputBuilder.build();
90     }
91
92 }