Sync Common folder
[transportpce.git] / olm / src / test / java / org / opendaylight / transportpce / olm / power / PowerMgmtTest.java
index 8c57f8608b8b8645b60a1eecaf71bd632729e5fe..03041193da40859bbdc27005508bc63e926c93ba 100644 (file)
@@ -9,19 +9,30 @@
 package org.opendaylight.transportpce.olm.power;
 
 import java.util.List;
+
 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.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
+import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
+import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl22;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
+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.PortMappingVersion22;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
+import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
+import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl22;
 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
 import org.opendaylight.transportpce.olm.stub.MountPointStub;
 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
@@ -39,16 +50,35 @@ public class PowerMgmtTest extends AbstractTest {
     private OpenRoadmInterfaces openRoadmInterfaces;
     private PortMapping portMapping;
     private PowerMgmt powerMgmt;
+    private MappingUtils mappingUtils;
+    private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
+    private OpenRoadmInterfacesImpl22 openRoadmInterfacesImpl22;
+    private PortMappingVersion22 portMappingVersion22;
+    private PortMappingVersion121 portMappingVersion121;
+    private CrossConnectImpl121 crossConnectImpl121;
+    private CrossConnectImpl22 crossConnectImpl22;
 
     @Before
     public void setUp() {
         this.mountPoint = new MountPointStub(this.getDataBroker());
         this.mountPointService = new MountPointServiceStub(mountPoint);
         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
-        this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
-        this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager));
-        this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
-            this.openRoadmInterfaces);
+        this.mappingUtils = new MappingUtilsImpl(getDataBroker());
+        this.mappingUtils = Mockito.spy(this.mappingUtils);
+        this.crossConnectImpl121 = new CrossConnectImpl121(this.deviceTransactionManager);
+        this.crossConnectImpl22 = new CrossConnectImpl22(this.deviceTransactionManager);
+        this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager, this.mappingUtils,
+                this.crossConnectImpl121, this.crossConnectImpl22);
+        this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(this.deviceTransactionManager);
+        this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl22(this.deviceTransactionManager);
+        this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
+                openRoadmInterfacesImpl121, openRoadmInterfacesImpl22);
+        this.portMappingVersion22 =
+                new PortMappingVersion22(getDataBroker(), this.deviceTransactionManager, this.openRoadmInterfaces);
+        this.portMappingVersion121 =
+                new PortMappingVersion121(getDataBroker(), this.deviceTransactionManager, this.openRoadmInterfaces);
+        this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
+                this.portMappingVersion121);
         this.powerMgmt = new PowerMgmt(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
             this.deviceTransactionManager);
     }
@@ -133,6 +163,8 @@ public class PowerMgmtTest extends AbstractTest {
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
+        Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
+                .getOpenRoadmVersion("node 1");
         boolean output = this.powerMgmt.setPower(input);
         Assert.assertEquals(false, output);
     }
@@ -145,6 +177,8 @@ public class PowerMgmtTest extends AbstractTest {
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
+        Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
+                .getOpenRoadmVersion("node 1");
         boolean output = this.powerMgmt.setPower(input);
         Assert.assertEquals(true, output);
     }
@@ -169,6 +203,8 @@ public class PowerMgmtTest extends AbstractTest {
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
+        Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
+                .getOpenRoadmVersion("node 1");
         boolean output = this.powerMgmt.setPower(input);
         Assert.assertEquals(true, output);
     }