Increase coverage of EvacuateServer 84/77784/3
authorJoss Armstrong <joss.armstrong@ericsson.com>
Mon, 4 Feb 2019 13:27:18 +0000 (13:27 +0000)
committerPatrick Brady <patrick.brady@att.com>
Tue, 5 Feb 2019 21:11:04 +0000 (21:11 +0000)
Increased line coverage of class

Issue-ID: APPC-1374
Change-Id: Ica44ff92a446e8b380162675d0f0f79e30ad6e73
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/EvacuateServer.java
appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestEvacuateServer.java

index 0d34246..4715860 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.
@@ -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 {
index 701ed11..2681020 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.
  */
 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<Image> 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<Image> 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<Image> 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