Bug 5596 Created lifecycle service
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / role / RoleContextImplTest.java
index a427fbbe0bb3ee90cc72309599f3ad20e74a3b36..0f3ec3c5c151934c659a593dd36895de10857062 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlready
 import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
@@ -42,6 +43,9 @@ public class RoleContextImplTest {
     @Mock
     private LifecycleConductor conductor;
 
+    @Mock
+    private DeviceInfo deviceInfo;
+
     private final NodeId nodeId = NodeId.getDefaultInstance("openflow:1");
     private final Entity entity = new Entity(RoleManager.ENTITY_TYPE, nodeId.getValue());
     private final Entity txEntity = new Entity(RoleManager.TX_ENTITY_TYPE, nodeId.getValue());
@@ -49,9 +53,10 @@ public class RoleContextImplTest {
 
     @Before
     public void setup() throws CandidateAlreadyRegisteredException {
-        roleContext = new RoleContextImpl(nodeId, entityOwnershipService, entity, txEntity, conductor);
+        roleContext = new RoleContextImpl(deviceInfo, entityOwnershipService, entity, txEntity, conductor);
         Mockito.when(entityOwnershipService.registerCandidate(entity)).thenReturn(entityOwnershipCandidateRegistration);
         Mockito.when(entityOwnershipService.registerCandidate(txEntity)).thenReturn(entityOwnershipCandidateRegistration);
+        Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
     }
 
     //@Test
@@ -68,20 +73,14 @@ public class RoleContextImplTest {
             }
         });
 
-        Thread t1 = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                LOG.info("Starting thread 1");
-                Assert.assertTrue(roleContext.initialization());
-            }
+        Thread t1 = new Thread(() -> {
+            LOG.info("Starting thread 1");
+            Assert.assertTrue(roleContext.initialization());
         });
 
-        Thread t2 = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                LOG.info("Starting thread 2");
-                Assert.assertFalse(roleContext.initialization());
-            }
+        Thread t2 = new Thread(() -> {
+            LOG.info("Starting thread 2");
+            Assert.assertFalse(roleContext.initialization());
         });
 
         t1.start();
@@ -108,7 +107,7 @@ public class RoleContextImplTest {
     @Test
     public void testCreateRequestContext() throws Exception {
         roleContext.createRequestContext();
-        Mockito.verify(conductor).reserveXidForDeviceMessage(nodeId);
+        Mockito.verify(conductor).reserveXidForDeviceMessage(deviceInfo);
     }
 
     @Test(expected = NullPointerException.class)
@@ -128,7 +127,7 @@ public class RoleContextImplTest {
 
     @Test
     public void testGetNodeId() throws Exception {
-        Assert.assertTrue(roleContext.getNodeId().equals(nodeId));
+        Assert.assertTrue(roleContext.getDeviceInfo().getNodeId().equals(nodeId));
     }
 
     @Test