1 package org.opendaylight.openflowplugin.impl.services;
3 import junit.framework.TestCase;
4 import org.junit.Before;
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;
29 import java.math.BigInteger;
30 import java.util.Collections;
31 import java.util.concurrent.ExecutionException;
32 import java.util.concurrent.Future;
34 import static org.mockito.Mockito.when;
36 @RunWith(MockitoJUnitRunner.class)
37 public class SalTableServiceImplTest extends TestCase {
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;
44 RequestContextStack mockedRequestContextStack;
46 DeviceContext mockedDeviceContext;
48 ConnectionContext mockedPrimConnectionContext;
50 FeaturesReply mockedFeatures;
52 ConnectionAdapter mockedConnectionAdapter;
54 MessageSpy mockedMessagSpy;
56 RpcProviderRegistry mockedRpcProviderRegistry;
58 OutboundQueue mockedOutboundQueue;
61 public void initialization() {
62 when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
63 when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION);
65 when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
66 when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
67 when(mockedPrimConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
69 when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
71 when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
72 when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
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);
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();