From 44a2c9c2eebf99d1118b24ab472764c2d1e31147 Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Mon, 4 Feb 2019 13:27:18 +0000 Subject: Increase coverage of EvacuateServer Increased line coverage of class Issue-ID: APPC-1374 Change-Id: Ica44ff92a446e8b380162675d0f0f79e30ad6e73 Signed-off-by: Joss Armstrong --- .../provider/operation/impl/EvacuateServer.java | 5 +- .../operation/impl/TestEvacuateServer.java | 61 ++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) (limited to 'appc-adapters/appc-iaas-adapter') diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/EvacuateServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/EvacuateServer.java index 0d342461a..4715860de 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/EvacuateServer.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/EvacuateServer.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. @@ -57,13 +59,10 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.glassfish.grizzly.http.util.HttpStatus; import org.slf4j.MDC; import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.TimeZone; import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME; public class EvacuateServer extends ProviderServerOperation { diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestEvacuateServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestEvacuateServer.java index 701ed11c7..268102072 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestEvacuateServer.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestEvacuateServer.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. @@ -22,13 +24,21 @@ */ package org.onap.appc.adapter.iaas.provider.operation.impl; +import java.util.ArrayList; +import java.util.List; import org.junit.Assert; import org.junit.Test; +import org.mockito.Mockito; import org.onap.appc.adapter.iaas.ProviderAdapter; +import org.onap.appc.adapter.iaas.impl.ProviderAdapterImpl; import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.powermock.reflect.Whitebox; import com.att.cdp.exceptions.ZoneException; +import com.att.cdp.zones.model.Image; import com.att.cdp.zones.model.Server; import com.att.cdp.zones.model.Server.Status; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.verify; public class TestEvacuateServer { @@ -48,4 +58,55 @@ public class TestEvacuateServer { verify(mg.getComputeService()).moveServer(server.getId(), "newServer1"); } + @Test + public void evacuateServerPaImpl() throws ZoneException, APPCException { + MockGenerator mg = new MockGenerator(Status.RUNNING); + EvacuateServer rbs = new EvacuateServer(); + rbs.setProviderCache(mg.getProviderCacheMap()); + mg.getParams().put(ProviderAdapter.PROPERTY_TARGETHOST_ID, "newServer1"); + List images = new ArrayList<>(); + images.add(Mockito.mock(Image.class)); + Mockito.doReturn(images).when(mg.getServer()).getSnapshots(); + ProviderAdapterImpl paImpl = Mockito.mock(ProviderAdapterImpl.class); + Whitebox.setInternalState(rbs, "paImpl", paImpl); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("error_code", "300"); + rbs.executeProviderOperation(mg.getParams(), ctx); + verify(mg.getComputeService()).moveServer("12442", "newServer1"); + } + + @Test + public void evacuateServerAppcException() throws ZoneException, APPCException { + MockGenerator mg = new MockGenerator(Status.RUNNING); + EvacuateServer rbs = new EvacuateServer(); + rbs.setProviderCache(mg.getProviderCacheMap()); + mg.getParams().put(ProviderAdapter.PROPERTY_TARGETHOST_ID, "newServer1"); + List images = new ArrayList<>(); + images.add(Mockito.mock(Image.class)); + Mockito.doReturn(images).when(mg.getServer()).getSnapshots(); + ProviderAdapterImpl paImpl = Mockito.mock(ProviderAdapterImpl.class); + Mockito.doThrow(new APPCException()).when(paImpl).rebuildServer(Mockito.anyMap(), + Mockito.any(SvcLogicContext.class)); + Whitebox.setInternalState(rbs, "paImpl", paImpl); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("error_code", "300"); + rbs.executeProviderOperation(mg.getParams(), ctx); + assertEquals("Internal Server Error", ctx.getAttribute(org.onap.appc.Constants.ATTRIBUTE_ERROR_MESSAGE)); + } + + @Test + public void evacuateServerZoneException() throws ZoneException, APPCException { + MockGenerator mg = new MockGenerator(Status.RUNNING); + EvacuateServer rbs = new EvacuateServer(); + rbs.setProviderCache(mg.getProviderCacheMap()); + mg.getParams().put(ProviderAdapter.PROPERTY_TARGETHOST_ID, "newServer1"); + List images = new ArrayList<>(); + images.add(Mockito.mock(Image.class)); + Mockito.doReturn(images).when(mg.getServer()).getSnapshots(); + Mockito.doThrow(new ZoneException("TEST")).when(mg.getServer()).refreshAll(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("error_code", "300"); + rbs.executeProviderOperation(mg.getParams(), ctx); + assertEquals("TEST", ctx.getAttribute(org.onap.appc.Constants.ATTRIBUTE_ERROR_MESSAGE)); + } } \ No newline at end of file -- cgit 1.2.3-korg