*/
package org.opendaylight.openflowplugin.impl.services.sal;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import com.google.common.util.concurrent.Futures;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
@Before
public void initialization() {
- when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
- when(mockedFeaturesOutput.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
- when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
- when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
when(mockedPrimConnectionContext.getOutboundQueueProvider()).thenReturn(outboundQueue);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success().buildFuture());
when(mockedRequestContextStack.createRequestContext()).thenReturn(requestContext);
- when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_II);
when(mockedDeviceInfo.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
- when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
}
@Test
public void testAddFlow() throws Exception {
- addFlow(null, OFConstants.OFP_VERSION_1_0);
- addFlow(null, OFConstants.OFP_VERSION_1_3);
+ addFlow(OFConstants.OFP_VERSION_1_0);
+ addFlow(OFConstants.OFP_VERSION_1_3);
}
@Test
@Test
public void testAddFlowWithItemLifecycle() throws Exception {
- addFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_0);
- addFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_3);
+ addFlow(OFConstants.OFP_VERSION_1_0);
+ addFlow(OFConstants.OFP_VERSION_1_3);
}
- private void addFlow(final ItemLifecycleListener itemLifecycleListener, short version) throws ExecutionException,
+ private void addFlow(short version) throws ExecutionException,
InterruptedException {
AddFlowInput mockedAddFlowInput = new AddFlowInputBuilder()
.setMatch(match)
.setTableId((short)1)
.build();
SalFlowServiceImpl salFlowService = mockSalFlowService(version);
- salFlowService.setItemLifecycleListener(itemLifecycleListener);
mockingFlowRegistryLookup();
verifyOutput(salFlowService.addFlow(mockedAddFlowInput));
- if (itemLifecycleListener != null) {
- Mockito.verify(itemLifecycleListener)
- .onAdded(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
- }
}
@Test
public void testRemoveFlow() throws Exception {
- removeFlow(null, OFConstants.OFP_VERSION_1_0);
- removeFlow(null, OFConstants.OFP_VERSION_1_3);
+ removeFlow(OFConstants.OFP_VERSION_1_0);
+ removeFlow(OFConstants.OFP_VERSION_1_3);
}
@Test
public void testRemoveFlowWithItemLifecycle() throws Exception {
- removeFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_0);
- removeFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_3);
+ removeFlow(OFConstants.OFP_VERSION_1_0);
+ removeFlow(OFConstants.OFP_VERSION_1_3);
}
- private void removeFlow(final ItemLifecycleListener itemLifecycleListener, short version) throws Exception {
+ private void removeFlow(short version) throws Exception {
RemoveFlowInput mockedRemoveFlowInput = new RemoveFlowInputBuilder()
.setMatch(match)
.setTableId((short)1)
.build();
SalFlowServiceImpl salFlowService = mockSalFlowService(version);
- if (itemLifecycleListener != null) {
- salFlowService.setItemLifecycleListener(itemLifecycleListener);
- mockingFlowRegistryLookup();
-
- }
-
verifyOutput(salFlowService.removeFlow(mockedRemoveFlowInput));
- if (itemLifecycleListener != null) {
- Mockito.verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any());
- }
-
}
@Test
public void testUpdateFlow() throws Exception {
- updateFlow(null, OFConstants.OFP_VERSION_1_0);
- updateFlow(null, OFConstants.OFP_VERSION_1_3);
+ updateFlow(OFConstants.OFP_VERSION_1_0);
+ updateFlow(OFConstants.OFP_VERSION_1_3);
}
@Test
public void testUpdateFlowWithItemLifecycle() throws Exception {
- updateFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_0);
- updateFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_3);
+ updateFlow(OFConstants.OFP_VERSION_1_0);
+ updateFlow(OFConstants.OFP_VERSION_1_3);
}
- private void updateFlow(final ItemLifecycleListener itemLifecycleListener, short version) throws Exception {
+ private void updateFlow(short version) throws Exception {
UpdateFlowInput mockedUpdateFlowInput = mock(UpdateFlowInput.class);
UpdateFlowInput mockedUpdateFlowInput1 = mock(UpdateFlowInput.class);
UpdatedFlow mockedUpdateFlow1 = new UpdatedFlowBuilder()
.setMatch(match)
.setTableId((short)1)
- .setPriority(Integer.valueOf(1))
+ .setPriority(1)
.build();
when(mockedUpdateFlowInput.getUpdatedFlow()).thenReturn(mockedUpdateFlow);
OriginalFlow mockedOriginalFlow1 = new OriginalFlowBuilder()
.setMatch(match)
.setTableId((short)1)
- .setPriority(Integer.valueOf(2))
+ .setPriority(2)
.build();
when(mockedUpdateFlowInput.getOriginalFlow()).thenReturn(mockedOriginalFlow);
when(mockedUpdateFlowInput1.getOriginalFlow()).thenReturn(mockedOriginalFlow1);
SalFlowServiceImpl salFlowService = mockSalFlowService(version);
- if (itemLifecycleListener != null) {
- salFlowService.setItemLifecycleListener(itemLifecycleListener);
- mockingFlowRegistryLookup();
- }
verifyOutput(salFlowService.updateFlow(mockedUpdateFlowInput));
verifyOutput(salFlowService.updateFlow(mockedUpdateFlowInput1));
-
- if (itemLifecycleListener != null) {
- Mockito.verify(itemLifecycleListener, times(2))
- .onUpdated(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
- }
-
}
private void mockingFlowRegistryLookup() {
FlowDescriptor mockedFlowDescriptor = mock(FlowDescriptor.class);
FlowId flowId = new FlowId(DUMMY_FLOW_ID);
when(mockedFlowDescriptor.getFlowId()).thenReturn(flowId);
- when(mockedFlowDescriptor.getTableKey()).thenReturn(new TableKey(DUMMY_TABLE_ID));
when(deviceFlowRegistry
- .retrieveDescriptor(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
+ .retrieveDescriptor(any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
}
private <T extends DataObject> void verifyOutput(Future<RpcResult<T>> rpcResultFuture) throws ExecutionException,