Test coverage for DetachVolumeServer 22/77722/2
authorJoss Armstrong <joss.armstrong@ericsson.com>
Fri, 1 Feb 2019 14:49:12 +0000 (14:49 +0000)
committerTakamune Cho <takamune.cho@att.com>
Fri, 1 Feb 2019 22:28:22 +0000 (22:28 +0000)
Added new test file for untested class

Issue-ID: APPC-1374
Change-Id: I334d53df87efb6a25a6f76a1660dd43c98d143b3
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java
appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServerTest.java [new file with mode: 0644]

index 218c83e..a9014a0 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,7 +36,6 @@ import com.att.cdp.zones.model.Volume;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.att.eelf.i18n.EELFResourceManager;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Iterator;
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServerTest.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServerTest.java
new file mode 100644 (file)
index 0000000..037ec53
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.appc.adapter.iaas.impl.RequestContext;
+import org.onap.appc.adapter.iaas.impl.RequestFailedException;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.TimeoutException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.ComputeService;
+import com.att.cdp.zones.VolumeService;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Volume;
+
+
+
+public class DettachVolumeServerTest {
+
+    @Rule
+    public ExpectedException expectedEx = ExpectedException.none();
+
+    @Test
+    public void detachVolumeTest() throws ZoneException, APPCException {
+        MockGenerator mg = new MockGenerator(Status.RUNNING);
+        Server server = mg.getServer();
+        VolumeService volumeService = mock(VolumeService.class);
+        List<Volume> volumeList = new ArrayList<>();
+        doReturn(volumeList).when(volumeService).getVolumes();
+        doReturn(mg.getContext()).when(server).getContext();
+        doReturn(volumeService).when(mg.getContext()).getVolumeService();
+        DettachVolumeServer rbs = new DettachVolumeServer();
+        rbs.setProviderCache(mg.getProviderCacheMap());
+        assertTrue(rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext()) instanceof ModelObject);
+    }
+
+    @Test
+    public void validateDetachTest() throws RequestFailedException, ZoneException {
+        DettachVolumeServer rbs = Mockito.spy(new DettachVolumeServer());
+        RequestContext rc = Mockito.mock(RequestContext.class);
+        ComputeService ser = Mockito.mock(ComputeService.class);
+        Mockito.doReturn(true).doReturn(false).when(rc).attempt();
+        Map<String, String> attachments = new HashMap<>();
+        attachments.put("VOLUME_ID", "VOLUME_ID");
+        Mockito.doReturn(attachments).when(ser).getAttachments(Mockito.anyString());
+        assertTrue(rbs.validateDetach(rc, ser, "VM", "VOLUME_ID"));
+    }
+
+    @Test
+    public void validateDetachTestTimeoutException() throws RequestFailedException, ZoneException {
+        DettachVolumeServer rbs = Mockito.spy(new DettachVolumeServer());
+        RequestContext rc = Mockito.mock(RequestContext.class);
+        ComputeService ser = Mockito.mock(ComputeService.class);
+        Mockito.doReturn(true).doReturn(false).when(rc).attempt();
+        Mockito.doReturn(30).when(rc).getAttempts();
+        expectedEx.expect(TimeoutException.class);
+        rbs.validateDetach(rc, ser, "VM", "VOLUME_ID");
+    }
+
+    @Test
+    public void validateDetachTest3Arg() throws RequestFailedException, ZoneException {
+        DettachVolumeServer rbs = Mockito.spy(new DettachVolumeServer());
+        ComputeService ser = Mockito.mock(ComputeService.class);
+        Map<String, String> attachments = new HashMap<>();
+        attachments.put("VOLUME_ID", "VOLUME_ID");
+        Mockito.doReturn(attachments).when(ser).getAttachments(Mockito.anyString());
+        assertTrue(rbs.validateDetach(ser, "VM", "VOLUME_ID"));
+    }
+}