add some unit test for omlpowerservice 12/84212/2
authorShaaban Ebrahim <shaaban.altanany@gmail.com>
Thu, 5 Sep 2019 07:47:14 +0000 (09:47 +0200)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Mon, 9 Sep 2019 07:36:19 +0000 (07:36 +0000)
Signed-off-by: Shaaban Ebrahim <shaaban.altanany@gmail.com>
Change-Id: I6423aa73bbabfa7eb1956cae6f1dddcef1170522

olm/src/test/java/org/opendaylight/transportpce/olm/service/OlmPowerServiceImplTest.java

index c5b5ee059e1e5f78061e1b17786fbcfa52506119..ca5180547b0d033cd8c254f30267c9065f2e0f59 100644 (file)
@@ -14,9 +14,11 @@ import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
+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.NetworkUtils;
+import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
@@ -84,6 +86,7 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
     private PortMappingVersion221 portMappingVersion22;
     private PortMappingVersion121 portMappingVersion121;
     private OlmPowerService olmPowerService;
+    private DataBroker dataBroker;
     private PowerMgmt powerMgmtMock;
     @InjectMocks
     private OlmPowerService olmPowerServiceMock;
@@ -117,6 +120,7 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
             this.deviceTransactionManager);
         this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
             this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
+        this.dataBroker =  Mockito.mock(DataBroker.class);
         this.powerMgmtMock = Mockito.mock(PowerMgmt.class);
         this.olmPowerServiceMock = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmtMock,
             this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
@@ -388,4 +392,41 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
         ServicePowerResetOutput output = this.olmPowerService.servicePowerReset(input);
         Assert.assertEquals(null, output);
     }
+
+    @Test
+    public void testServicePowerTurndownSuccessResult() {
+        ServicePowerTurndownInput servicePowerTurndownInput = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
+        ServicePowerTurndownOutput servicePowerTurndownOutput =
+                this.olmPowerService.servicePowerTurndown(servicePowerTurndownInput);
+        Assert.assertEquals(ResponseCodes.SUCCESS_RESULT, servicePowerTurndownOutput.getResult());
+    }
+
+    @Test
+    public void testServicePowerTurndownFailResult() {
+        ServicePowerTurndownInput servicePowerTurndownInput =
+                OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
+        ServicePowerTurndownOutput servicePowerTurndownOutput =
+                this.olmPowerService.servicePowerTurndown(servicePowerTurndownInput);
+        Assert.assertEquals(ResponseCodes.FAILED_RESULT, servicePowerTurndownOutput.getResult());
+    }
+
+    @Test
+    public void testServicePowerSetupSuccessResult() {
+        ServicePowerSetupInput servicePowerSetupInput =
+                OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
+        ServicePowerSetupOutput servicePowerSetupOutput =
+                this.olmPowerService.servicePowerSetup(servicePowerSetupInput);
+        Assert.assertEquals(ResponseCodes.SUCCESS_RESULT, servicePowerSetupOutput.getResult());
+    }
+
+    @Test
+    public void testServicePowerSetupFailResult() {
+        ServicePowerSetupInput servicePowerSetupInput = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
+        Mockito.when(powerMgmtMock.setPower(servicePowerSetupInput)).thenReturn(Boolean.FALSE);
+        OlmPowerService olmPowerServiceWithMock = new OlmPowerServiceImpl(dataBroker, powerMgmtMock,
+                this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
+        ServicePowerSetupOutput servicePowerSetupOutput =
+                olmPowerServiceWithMock.servicePowerSetup(servicePowerSetupInput);
+        Assert.assertEquals(ResponseCodes.FAILED_RESULT, servicePowerSetupOutput.getResult());
+    }
 }