OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / sal / SalFlowServiceImplTest.java
index 8865220bccdc8e9f5c827b2bc5b286f27d4ab500..af67ef1b5882c11f5e081b55c30f1d52244ed787 100644 (file)
@@ -7,8 +7,8 @@
  */
 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;
@@ -19,7 +19,6 @@ import junit.framework.TestCase;
 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;
@@ -36,7 +35,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 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;
@@ -115,11 +113,7 @@ public class SalFlowServiceImplTest extends TestCase {
 
     @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);
@@ -130,10 +124,8 @@ public class SalFlowServiceImplTest extends TestCase {
         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);
     }
 
@@ -148,8 +140,8 @@ public class SalFlowServiceImplTest extends TestCase {
 
     @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
@@ -211,72 +203,57 @@ public class SalFlowServiceImplTest extends TestCase {
 
     @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);
 
@@ -288,7 +265,7 @@ public class SalFlowServiceImplTest extends TestCase {
         UpdatedFlow mockedUpdateFlow1 = new UpdatedFlowBuilder()
                 .setMatch(match)
                 .setTableId((short)1)
-                .setPriority(Integer.valueOf(1))
+                .setPriority(1)
                 .build();
 
         when(mockedUpdateFlowInput.getUpdatedFlow()).thenReturn(mockedUpdateFlow);
@@ -308,36 +285,25 @@ public class SalFlowServiceImplTest extends TestCase {
         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,