Strengthens independence between UTs in OLM
[transportpce.git] / olm / src / test / java / org / opendaylight / transportpce / olm / power / PowerMgmtTest.java
index e6f3c49ba7cd5847b87b01503af7538cc84a2635..21ffdcfba91b97e690e1147946591b92e60a1fe3 100644 (file)
@@ -13,8 +13,9 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.opendaylight.controller.md.sal.binding.api.MountPoint;
-import org.opendaylight.controller.md.sal.binding.api.MountPointService;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.MountPoint;
+import org.opendaylight.mdsal.binding.api.MountPointService;
 import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
@@ -22,7 +23,12 @@ import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
-import org.opendaylight.transportpce.common.mapping.*;
+import org.opendaylight.transportpce.common.mapping.MappingUtils;
+import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
+import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
+import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
+import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
@@ -33,10 +39,10 @@ import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
 import org.opendaylight.transportpce.olm.util.TransactionUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownInput;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 
 public class PowerMgmtTest extends AbstractTest {
-
     private MountPoint mountPoint;
     private MountPointService mountPointService;
     private DeviceTransactionManager deviceTransactionManager;
@@ -51,13 +57,15 @@ public class PowerMgmtTest extends AbstractTest {
     private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
     private PortMappingVersion221 portMappingVersion22;
     private PortMappingVersion121 portMappingVersion121;
+    private DataBroker dataBroker;
 
     @Before
     public void setUp() {
-        this.mountPoint = new MountPointStub(this.getDataBroker());
+        dataBroker = this.getNewDataBroker();
+        this.mountPoint = new MountPointStub(dataBroker);
         this.mountPointService = new MountPointServiceStub(mountPoint);
-        this.mappingUtils = new MappingUtilsImpl(getDataBroker());
-        this.mappingUtils = Mockito.spy(MappingUtils.class);
+        // this.mappingUtils = new MappingUtilsImpl(getDataBroker());
+        this.mappingUtils = Mockito.spy(new MappingUtilsImpl(dataBroker));
         Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
                 .getOpenRoadmVersion(Mockito.anyString());
         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
@@ -71,58 +79,78 @@ public class PowerMgmtTest extends AbstractTest {
                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
         this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
         this.portMappingVersion22 =
-                new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
+                new PortMappingVersion221(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
         this.portMappingVersion121 =
-                new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
-        this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
-                this.portMappingVersion121);
+                new PortMappingVersion121(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
+        this.portMapping = new PortMappingImpl(dataBroker,
+                this.portMappingVersion22, this.portMappingVersion121);
         this.portMapping = Mockito.spy(this.portMapping);
-        this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
-            this.deviceTransactionManager);
+        this.powerMgmt = new PowerMgmtImpl(this.dataBroker, this.openRoadmInterfaces, this.crossConnect,
+                this.deviceTransactionManager);
     }
 
     @Test
     public void testSetPower() {
-
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
         boolean output = this.powerMgmt.setPower(input);
         Assert.assertEquals(true, output);
-
     }
 
     @Test
     public void testSetPower2() {
-
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
         boolean output = this.powerMgmt.setPower(input);
         Assert.assertEquals(true, output);
-
     }
 
     @Test
     public void testSetPower3() {
-
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
         boolean output = this.powerMgmt.setPower(input);
         Assert.assertEquals(true, output);
-
     }
 
     @Test
     public void testSetPower4() {
-
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
         boolean output = this.powerMgmt.setPower(input);
         Assert.assertEquals(true, output);
+    }
 
+    @Test
+    public void testPowerTurnDown() {
+        ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
+        boolean output = this.powerMgmt.powerTurnDown(input);
+        Assert.assertEquals(true, output);
+    }
+
+    @Test
+    public void testPowerTurnDown2() {
+        ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
+        boolean output = this.powerMgmt.powerTurnDown(input);
+        Assert.assertEquals(false, output);
+    }
+
+    @Test
+    public void testPowerTurnDown3() {
+        ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
+        boolean output = this.powerMgmt.powerTurnDown(input);
+        Assert.assertEquals(true, output);
+    }
+
+    @Test
+    public void testPowerTurnDown4() {
+        ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
+        boolean output = this.powerMgmt.powerTurnDown(input);
+        Assert.assertEquals(false, output);
     }
 
     @Test
     public void testSetPowerPresentNodes() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
-            Thread.sleep(500);
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
+            Thread.sleep(1000);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
         boolean output = this.powerMgmt.setPower(input);
@@ -133,7 +161,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes2() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
@@ -145,7 +173,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes3() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
@@ -169,7 +197,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes312() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
+            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, "deg");
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
@@ -181,7 +209,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes32() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
@@ -193,7 +221,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes4() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "network");
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
@@ -218,7 +246,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes42() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
@@ -230,7 +258,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes422() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
@@ -242,7 +270,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes43() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();