Bump upstreams
[openflowplugin.git] / applications / forwardingrules-manager / src / test / java / org / opendaylight / openflowplugin / applications / frm / impl / DeviceMastershipManagerTest.java
index 31a83f605c175b375b5eeafc6a58632a6bec9822..e3efc8e0755328baa186516428efe20c0ced04cb 100644 (file)
@@ -1,89 +1,86 @@
-/**
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
+/*
+ * Copyright (c) 2016, 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.applications.frm.impl;
 
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
+import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
+import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemovedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdatedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.concepts.Registration;
 
 /**
  * Test for {@link DeviceMastershipManager}.
  */
 @RunWith(MockitoJUnitRunner.class)
 public class DeviceMastershipManagerTest {
-    private static final NodeId NODE_ID = new NodeId("testNode");
     private DeviceMastershipManager deviceMastershipManager;
     @Mock
-    private ClusterSingletonServiceRegistration registration;
+    private Registration registration;
     @Mock
     private ClusterSingletonServiceProvider clusterSingletonService;
     @Mock
-    private NotificationProviderService notificationService;
+    private FlowNodeReconciliation reconciliationAgent;
+    @Mock
+    private DataBroker dataBroker;
+    @Mock
+    private MastershipChangeServiceManager mastershipChangeServiceManager;
+    @Mock
+    private DeviceInfo deviceInfo;
+    @Mock
+    private NodeId nodeId;
+    @Mock
+    private RpcProviderService rpcProviderService;
 
     @Before
-    public void setUp() throws Exception {
-        deviceMastershipManager = new DeviceMastershipManager(clusterSingletonService,
-                notificationService);
-        Mockito.when(clusterSingletonService.registerClusterSingletonService(Matchers.<ClusterSingletonService>any()))
+    public void setUp() {
+        deviceMastershipManager = new DeviceMastershipManager(reconciliationAgent, dataBroker,
+                mastershipChangeServiceManager, rpcProviderService);
+        Mockito.lenient().when(clusterSingletonService
+                .registerClusterSingletonService(ArgumentMatchers.any()))
                 .thenReturn(registration);
+        Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
+        Mockito.when(nodeId.getValue()).thenReturn("dummyValue");
     }
 
     @Test
-    public void testOnDeviceConnectedAndDisconnected() throws Exception {
+    public void testOnDeviceConnectedAndDisconnected() {
         // no context
-        Assert.assertNull(deviceMastershipManager.getDeviceMasterships().get(NODE_ID));
-        NodeUpdatedBuilder nodeUpdatedBuilder = new NodeUpdatedBuilder();
-        nodeUpdatedBuilder.setId(NODE_ID);
-        deviceMastershipManager.onNodeUpdated(nodeUpdatedBuilder.build());
-        DeviceMastership serviceInstance = deviceMastershipManager.getDeviceMasterships().get(NODE_ID);
+        Assert.assertNull(deviceMastershipManager.getDeviceMasterships().get(deviceInfo.getNodeId()));
+        deviceMastershipManager.onBecomeOwner(deviceInfo);
+        DeviceMastership serviceInstance = deviceMastershipManager.getDeviceMasterships().get(deviceInfo.getNodeId());
         Assert.assertNotNull(serviceInstance);
         // destroy context - unregister
-        deviceMastershipManager.onDeviceDisconnected(NODE_ID);
-        Assert.assertNotNull(deviceMastershipManager.getDeviceMasterships().get(NODE_ID));
-        NodeRemovedBuilder nodeRemovedBuilder = new NodeRemovedBuilder();
-        InstanceIdentifier<Node> nodeIId = InstanceIdentifier.create(Nodes.class).
-                child(Node.class, new NodeKey(NODE_ID));
-        nodeRemovedBuilder.setNodeRef(new NodeRef(nodeIId));
-        deviceMastershipManager.onNodeRemoved(nodeRemovedBuilder.build());
-        Assert.assertNull(deviceMastershipManager.getDeviceMasterships().get(NODE_ID));
+        Assert.assertNotNull(deviceMastershipManager.getDeviceMasterships().get(deviceInfo.getNodeId()));
+        deviceMastershipManager.onLoseOwnership(deviceInfo);
+        Assert.assertNull(deviceMastershipManager.getDeviceMasterships().get(deviceInfo.getNodeId()));
     }
 
     @Test
     public void testIsDeviceMasteredOrSlaved() {
         // no context
-        Assert.assertFalse(deviceMastershipManager.isDeviceMastered(NODE_ID));
-        NodeUpdatedBuilder nodeUpdatedBuilder = new NodeUpdatedBuilder();
-        nodeUpdatedBuilder.setId(NODE_ID);
-        deviceMastershipManager.onNodeUpdated(nodeUpdatedBuilder.build());
+        Assert.assertFalse(deviceMastershipManager.isDeviceMastered(deviceInfo.getNodeId()));
+        deviceMastershipManager.onBecomeOwner(deviceInfo);
         // is master
-        deviceMastershipManager.getDeviceMasterships().get(NODE_ID).instantiateServiceInstance();
-        Assert.assertTrue(deviceMastershipManager.isDeviceMastered(NODE_ID));
+        deviceMastershipManager.getDeviceMasterships().get(deviceInfo.getNodeId()).instantiateServiceInstance();
+        Assert.assertTrue(deviceMastershipManager.isDeviceMastered(deviceInfo.getNodeId()));
         // is not master
-        deviceMastershipManager.getDeviceMasterships().get(NODE_ID).closeServiceInstance();
-        Assert.assertFalse(deviceMastershipManager.isDeviceMastered(NODE_ID));
+        deviceMastershipManager.getDeviceMasterships().get(deviceInfo.getNodeId()).closeServiceInstance();
+        Assert.assertFalse(deviceMastershipManager.isDeviceMastered(deviceInfo.getNodeId()));
     }
-
-}
\ No newline at end of file
+}