diff options
Diffstat (limited to 'appc-adapters/appc-iaas-adapter')
2 files changed, 102 insertions, 1 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java index 218c83ef4..a9014a066 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java @@ -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 index 000000000..037ec53f7 --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServerTest.java @@ -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")); + } +} |