Added test case for Attach volume class 88/79188/2
authorLathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>
Tue, 26 Feb 2019 14:13:30 +0000 (09:13 -0500)
committerTakamune Cho <takamune.cho@att.com>
Tue, 26 Feb 2019 17:44:11 +0000 (17:44 +0000)
Issue-ID: APPC-1467
Change-Id: Ifc902979c955df03ab847b4dd770bf737ff69eb9
Signed-off-by: Lathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>
appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServerTest.java

index 4ccbffd..6a88be9 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/*-
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
 
 package org.onap.appc.adapter.iaas.provider.operation.impl;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 import java.util.ArrayList;
 import java.util.List;
 import org.junit.Test;
 import org.onap.appc.exceptions.APPCException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import com.att.cdp.exceptions.ZoneException;
 import com.att.cdp.zones.VolumeService;
 import com.att.cdp.zones.model.ModelObject;
@@ -35,7 +38,6 @@ import com.att.cdp.zones.model.Server;
 import com.att.cdp.zones.model.Server.Status;
 import com.att.cdp.zones.model.Volume;
 
-
 public class AttachVolumeServerTest {
 
     @Test
@@ -52,4 +54,18 @@ public class AttachVolumeServerTest {
         assertTrue(rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext()) instanceof ModelObject);
     }
 
+    @Test
+    public void attachVolumeTestException() throws ZoneException, APPCException {
+        SvcLogicContext context = new SvcLogicContext();
+        MockGenerator mg = new MockGenerator(Status.RUNNING);
+        Server server = mg.getServer();
+        VolumeService volumeService = mock(VolumeService.class);
+        when(volumeService.getVolumes()).thenThrow(new ZoneException("Zone Exception"));
+        doReturn(mg.getContext()).when(server).getContext();
+        doReturn(volumeService).when(mg.getContext()).getVolumeService();
+        AttachVolumeServer attachVolumeServer = new AttachVolumeServer();
+        attachVolumeServer.setProviderCache(mg.getProviderCacheMap());
+        attachVolumeServer.executeProviderOperation(mg.getParams(), context);
+        assertEquals("FAILURE", context.getAttribute("VOLUME_STATUS"));
+    }
 }