CSC to provide a view of DPN re-sync
[openflowplugin.git] / applications / forwardingrules-manager / src / test / java / test / mock / FlowListenerTest.java
index 84ded26c0543359921168f0a38723a3f5eabac9c..1e49669077f1a025a3186b22c23b0f42478f5f48 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -13,19 +13,18 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.Collections;
 import java.util.List;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.openflowplugin.api.openflow.FlowGroupCacheManager;
+import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
 import org.opendaylight.openflowplugin.applications.frm.impl.DeviceMastershipManager;
 import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl;
 import org.opendaylight.openflowplugin.applications.frm.recovery.OpenflowServiceRecoveryHandler;
@@ -64,28 +63,29 @@ public class FlowListenerTest extends FRMTest {
     private ForwardingRulesManagerImpl forwardingRulesManager;
     private static final NodeId NODE_ID = new NodeId("testnode:1");
     private static final NodeKey NODE_KEY = new NodeKey(NODE_ID);
-    RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock();
+    RpcProviderRegistryMock rpcProviderRegistryMock = new RpcProviderRegistryMock();
     TableKey tableKey = new TableKey((short) 2);
     @Mock
     ClusterSingletonServiceProvider clusterSingletonService;
     @Mock
     DeviceMastershipManager deviceMastershipManager;
     @Mock
-    private NotificationProviderService notificationService;
-    @Mock
     private ReconciliationManager reconciliationManager;
     @Mock
     private OpenflowServiceRecoveryHandler openflowServiceRecoveryHandler;
     @Mock
     private ServiceRecoveryRegistry serviceRecoveryRegistry;
-
+    @Mock
+    private MastershipChangeServiceManager mastershipChangeServiceManager;
+    @Mock
+    private FlowGroupCacheManager flowGroupCacheManager;
 
     @Before
     public void setUp() {
-        forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock, getConfig(),
-                clusterSingletonService, notificationService, getConfigurationService(), reconciliationManager,
-                openflowServiceRecoveryHandler, serviceRecoveryRegistry);
-
+        forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock,
+                rpcProviderRegistryMock, getConfig(), mastershipChangeServiceManager, clusterSingletonService,
+                getConfigurationService(), reconciliationManager, openflowServiceRecoveryHandler,
+                serviceRecoveryRegistry, flowGroupCacheManager);
         forwardingRulesManager.start();
         // TODO consider tests rewrite (added because of complicated access)
         forwardingRulesManager.setDeviceMastershipManager(deviceMastershipManager);
@@ -93,7 +93,7 @@ public class FlowListenerTest extends FRMTest {
     }
 
     @Test
-    public void addTwoFlowsTest() throws Exception {
+    public void addTwoFlowsTest() {
         addFlowCapableNode(NODE_KEY);
 
         FlowKey flowKey = new FlowKey(new FlowId("test_Flow"));
@@ -101,13 +101,13 @@ public class FlowListenerTest extends FRMTest {
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
         InstanceIdentifier<Flow> flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
-        Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
+        Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.emptyList()).build();
         Flow flow = new FlowBuilder().withKey(flowKey).setTableId((short) 2).build();
 
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
         SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
         await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(1));
         List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
@@ -120,7 +120,7 @@ public class FlowListenerTest extends FRMTest {
         flow = new FlowBuilder().withKey(flowKey).setTableId((short) 2).build();
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
         salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
         await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(2));
         addFlowCalls = salFlowService.getAddFlowCalls();
@@ -131,7 +131,7 @@ public class FlowListenerTest extends FRMTest {
     }
 
     @Test
-    public void updateFlowTest() throws Exception {
+    public void updateFlowTest() {
         addFlowCapableNode(NODE_KEY);
 
         FlowKey flowKey = new FlowKey(new FlowId("test_Flow"));
@@ -139,13 +139,13 @@ public class FlowListenerTest extends FRMTest {
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
         InstanceIdentifier<Flow> flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
-        Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
+        Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.emptyList()).build();
         Flow flow = new FlowBuilder().withKey(flowKey).setTableId((short) 2).build();
 
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
         SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
         await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(1));
 
@@ -159,7 +159,7 @@ public class FlowListenerTest extends FRMTest {
         flow = new FlowBuilder().withKey(flowKey).setTableId((short) 2).setOutGroup((long) 5).build();
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
         salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
         await().until(listSize(salFlowService.getUpdateFlowCalls()), equalTo(1));
         List<UpdateFlowInput> updateFlowCalls = salFlowService.getUpdateFlowCalls();
@@ -171,7 +171,7 @@ public class FlowListenerTest extends FRMTest {
     }
 
     @Test
-    public void updateFlowScopeTest() throws Exception {
+    public void updateFlowScopeTest() {
         addFlowCapableNode(NODE_KEY);
 
         FlowKey flowKey = new FlowKey(new FlowId("test_Flow"));
@@ -179,7 +179,7 @@ public class FlowListenerTest extends FRMTest {
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
         InstanceIdentifier<Flow> flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
-        Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
+        Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.emptyList()).build();
         IpMatch ipMatch = new IpMatchBuilder().setIpDscp(new Dscp((short) 4)).build();
         Match match = new MatchBuilder().setIpMatch(ipMatch).build();
         Flow flow = new FlowBuilder().setMatch(match).withKey(flowKey).setTableId((short) 2).build();
@@ -187,7 +187,7 @@ public class FlowListenerTest extends FRMTest {
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
         SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
         await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(1));
         List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
@@ -202,7 +202,7 @@ public class FlowListenerTest extends FRMTest {
         flow = new FlowBuilder().setMatch(match).withKey(flowKey).setTableId((short) 2).build();
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
         salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
         await().until(listSize(salFlowService.getUpdateFlowCalls()), equalTo(1));
         List<UpdateFlowInput> updateFlowCalls = salFlowService.getUpdateFlowCalls();
@@ -213,7 +213,7 @@ public class FlowListenerTest extends FRMTest {
     }
 
     @Test
-    public void deleteFlowTest() throws Exception {
+    public void deleteFlowTest() {
         addFlowCapableNode(NODE_KEY);
 
         FlowKey flowKey = new FlowKey(new FlowId("test_Flow"));
@@ -221,13 +221,13 @@ public class FlowListenerTest extends FRMTest {
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
         InstanceIdentifier<Flow> flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
-        Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
+        Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.emptyList()).build();
         Flow flow = new FlowBuilder().withKey(flowKey).setTableId((short) 2).build();
 
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
         SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
         await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(1));
         List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
@@ -236,7 +236,7 @@ public class FlowListenerTest extends FRMTest {
 
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.delete(LogicalDatastoreType.CONFIGURATION, flowII);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
         salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
         await().until(listSize(salFlowService.getRemoveFlowCalls()), equalTo(1));
         List<RemoveFlowInput> removeFlowCalls = salFlowService.getRemoveFlowCalls();
@@ -247,7 +247,7 @@ public class FlowListenerTest extends FRMTest {
     }
 
     @Test
-    public void staleMarkedFlowCreationTest() throws Exception {
+    public void staleMarkedFlowCreationTest() {
 
         addFlowCapableNode(NODE_KEY);
 
@@ -256,13 +256,13 @@ public class FlowListenerTest extends FRMTest {
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
         InstanceIdentifier<StaleFlow> flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(StaleFlow.class, flowKey);
-        Table table = new TableBuilder().withKey(tableKey).setStaleFlow(Collections.<StaleFlow>emptyList()).build();
+        Table table = new TableBuilder().withKey(tableKey).setStaleFlow(Collections.emptyList()).build();
         StaleFlow flow = new StaleFlowBuilder().withKey(flowKey).setTableId((short) 2).build();
 
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
-        assertCommit(writeTx.submit());
+        assertCommit(writeTx.commit());
     }
 
     @After