aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java14
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/MockGenerator.java144
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestCreateSnapshot.java43
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestEvacuateServer.java29
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestLookupServer.java34
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestMigrateServer.java30
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebuildServer.java109
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRestartServer.java44
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestStartServer.java43
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestStopServer.java43
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestTerminateServer.java45
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestTerminateStack.java51
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestVmStatuschecker.java62
13 files changed, 690 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/RebuildServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
index bbb4e2c5d..c87dc7e85 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
@@ -69,6 +69,8 @@ public class RebuildServer extends ProviderServerOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(RebuildServer.class);
private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private static final Configuration configuration = ConfigurationFactory.getConfiguration();
+ //the sleep time used by thread.sleep to give "some time for OpenStack to start processing the request"
+ private long rebuildSleepTime = 10L * 1000L;
/**
* Rebuild the indicated server with the indicated image. This method assumes the server has been determined to be
@@ -113,7 +115,7 @@ public class RebuildServer extends ProviderServerOperation {
* We need to provide some time for OpenStack to start processing the request.
*/
try {
- Thread.sleep(10L * 1000L);
+ Thread.sleep(rebuildSleepTime);
} catch (InterruptedException e) {
logger.trace("Sleep threw interrupted exception, should never occur");
metricsLogger.trace("Sleep threw interrupted exception, should never occur");
@@ -431,4 +433,14 @@ public class RebuildServer extends ProviderServerOperation {
MDC.put("TargetServiceName", "rebuild server");
MDC.put("ClassName", "org.onap.appc.adapter.iaas.provider.operation.impl.RebuildServer");
}
+
+ /**
+ * Sets the sleep time used by thread.sleep to give
+ * "some time for OpenStack to start processing the request".
+ *
+ * @param millis Time to sleep in milliseconds
+ */
+ public void setRebuildSleepTime(long millis){
+ this.rebuildSleepTime = millis;
+ }
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/MockGenerator.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/MockGenerator.java
new file mode 100644
index 000000000..e34c3da1f
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/MockGenerator.java
@@ -0,0 +1,144 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import org.onap.appc.Constants;
+import org.onap.appc.adapter.iaas.ProviderAdapter;
+import org.onap.appc.adapter.iaas.impl.ProviderCache;
+import org.onap.appc.adapter.iaas.impl.RequestContext;
+import org.onap.appc.adapter.iaas.impl.TenantCache;
+import org.onap.appc.adapter.iaas.impl.VMURL;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import com.att.cdp.zones.model.Hypervisor;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.Provider;
+import com.att.cdp.zones.ImageService;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.openstack.OpenStackContext;
+import com.att.cdp.zones.ComputeService;
+import org.onap.appc.pool.Pool;
+import org.onap.appc.pool.PoolDrainedException;
+import org.onap.appc.pool.PoolExtensionException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+public class MockGenerator {
+
+ private Map<String, ProviderCache> providerCacheMap;
+ private Map<String, String> params;
+ private SvcLogicContext ctx;
+ private Server server;
+ private ImageService imageService;
+ private OpenStackContext context;
+ private ComputeService computeService;
+
+ public static final String SERVER_ID = "12442";
+ public static final String SERVER_NAME = "Server1";
+ private final Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ /**
+ * This method created a mocked up object representing the OpenStack objects which would be
+ * gathered from remote systems during runtime, but which are not available during a unit test.
+ *
+ * @param serverStatus Most of the classes in the package we are testing have different actions
+ * depending on the status of the server. This allows a different set of mock data to be
+ * created depending on which status is being tested.
+ */
+ public MockGenerator(Status serverStatus) {
+ configuration.setProperty(Constants.PROPERTY_STACK_STATE_CHANGE_TIMEOUT, "2");
+ configuration.setProperty(Constants.PROPERTY_RETRY_LIMIT, "10");
+ ctx = mock(SvcLogicContext.class);
+ RequestContext requestContext = mock(RequestContext.class);
+ server = mock(Server.class);
+ doReturn(SERVER_NAME).when(server).getName();
+ doReturn(SERVER_ID).when(server).getId();
+ Status status = serverStatus;
+ doReturn(status).when(server).getStatus();
+ // the example base image that our fake server was built off of
+ doReturn("linuxBase").when(server).getImage();
+ Hypervisor hypervisor = mock(Hypervisor.class);
+ com.att.cdp.zones.model.Hypervisor.Status hypervisorStatus =
+ com.att.cdp.zones.model.Hypervisor.Status.ENABLED;
+ doReturn(hypervisorStatus).when(hypervisor).getStatus();
+ com.att.cdp.zones.model.Hypervisor.State hypervisorState =
+ com.att.cdp.zones.model.Hypervisor.State.UP;
+ doReturn(hypervisorState).when(hypervisor).getState();
+ doReturn(hypervisor).when(server).getHypervisor();
+ context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ imageService = mock(ImageService.class);
+ computeService = mock(ComputeService.class);
+ try {
+ doReturn(server).when(computeService).getServer("abc12345-1234-5678-890a-abcdefb12345");
+ } catch (ZoneException e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ }
+ doReturn(context).when(server).getContext();
+ doReturn(provider).when(context).getProvider();
+ doReturn(imageService).when(context).getImageService();
+ doReturn(computeService).when(context).getComputeService();
+ doReturn(false).when(requestContext).attempt();
+ doReturn(true).when(requestContext).isFailed();
+ params = new HashMap<String, String>();
+ params.put(ProviderAdapter.PROPERTY_INSTANCE_URL,
+ "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/abc12345-1234-5678-890a-abcdefb12345");
+ params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, "provider1");
+ params.put(ProviderAdapter.PROPERTY_IDENTITY_URL,
+ "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3");
+ ProviderCache providerCache = mock(ProviderCache.class);
+ TenantCache tenantCache = mock(TenantCache.class);
+ doReturn("cloudowner_region").when(tenantCache).determineRegion(any(VMURL.class));
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantId();
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantName();
+ Pool pool = mock(Pool.class);
+ try {
+ doReturn(context).when(pool).reserve();
+ } catch (PoolExtensionException | PoolDrainedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ Map<String, Pool> tenantCachePools = new HashMap<String, Pool>();
+ tenantCachePools.put("cloudowner_region", pool);
+ doReturn(tenantCachePools).when(tenantCache).getPools();
+ doReturn(tenantCache).when(providerCache).getTenant("abc12345-1234-5678-890a-abcdefb12345");
+ providerCacheMap = new HashMap<String, ProviderCache>();
+ providerCacheMap.put(
+ "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3",
+ providerCache);
+ }
+
+ public Map<String, String> getParams() {
+ return params;
+ }
+
+ public Map<String, ProviderCache> getProviderCacheMap() {
+ return providerCacheMap;
+ }
+
+ public SvcLogicContext getSvcLogicContext() {
+ return ctx;
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+ public ImageService getImageService() {
+ return imageService;
+ }
+
+ public OpenStackContext getContext() {
+ return context;
+ }
+
+ public ComputeService getComputeService() {
+ return computeService;
+ }
+
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestCreateSnapshot.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestCreateSnapshot.java
new file mode 100644
index 000000000..3da8d2b06
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestCreateSnapshot.java
@@ -0,0 +1,43 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.onap.appc.exceptions.APPCException;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.atLeastOnce;
+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;
+
+public class TestCreateSnapshot {
+
+ @Test
+ public void createSnapshotRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ Image image = mock(Image.class);
+ doReturn("1234567").when(image).getId();
+ doReturn(mg.getContext()).when(image).getContext();
+ doReturn("wrong image name").when(image).getName();
+ doReturn(com.att.cdp.zones.model.Image.Status.ACTIVE).when(image).getStatus();
+ doReturn(image).when(mg.getImageService()).getImageByName(any());
+ CreateSnapshot rbs = new CreateSnapshot();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during CreateSnapshot.executeProviderOperation");
+ }
+ ArgumentCaptor<String> createSnapshotCaptor = ArgumentCaptor.forClass(String.class);
+ verify(server).createSnapshot(createSnapshotCaptor.capture());
+ ArgumentCaptor<String> getImageNameCaptor = ArgumentCaptor.forClass(String.class);
+ verify(mg.getImageService(), atLeastOnce()).getImageByName(getImageNameCaptor.capture());
+ assertEquals(createSnapshotCaptor.getValue(), getImageNameCaptor.getValue());
+ }
+}
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
new file mode 100644
index 000000000..977911120
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestEvacuateServer.java
@@ -0,0 +1,29 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.appc.adapter.iaas.ProviderAdapter;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import static org.mockito.Mockito.verify;
+
+public class TestEvacuateServer {
+
+ @Test
+ public void evacuateServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ EvacuateServer rbs = new EvacuateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ mg.getParams().put(ProviderAdapter.PROPERTY_TARGETHOST_ID, "newServer1");
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during EvacuateServer.executeProviderOperation");
+ }
+ verify(mg.getComputeService()).moveServer(server.getId(), "newServer1");
+ }
+
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestLookupServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestLookupServer.java
new file mode 100644
index 000000000..273c9a734
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestLookupServer.java
@@ -0,0 +1,34 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import static org.junit.Assert.assertTrue;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+
+public class TestLookupServer {
+
+ @Test
+ public void lookupServer() {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ LookupServer rbs = new LookupServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = null;
+ try {
+ mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during LookupServer.executeProviderOperation");
+ }
+ boolean correctServerReturned = false;
+ try {
+ Server returnedServer = (Server) mo;
+ correctServerReturned = returnedServer == server;
+ } catch (Exception e) {
+ Assert.fail();
+ }
+ assertTrue(correctServerReturned);
+ }
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestMigrateServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestMigrateServer.java
new file mode 100644
index 000000000..38d11951a
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestMigrateServer.java
@@ -0,0 +1,30 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.anyInt;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+
+public class TestMigrateServer {
+
+ @Test
+ public void migrateServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ MigrateServer rbs = new MigrateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during MigrateServer.executeProviderOperation");
+ }
+ verify(mg.getComputeService()).migrateServer(mg.SERVER_ID);
+ verify(server, atLeastOnce()).waitForStateChange(anyInt(), anyInt(), Matchers.anyVararg());
+ }
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebuildServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebuildServer.java
new file mode 100644
index 000000000..5e16c00ed
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebuildServer.java
@@ -0,0 +1,109 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.inOrder;
+import org.mockito.InOrder;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.exceptions.ZoneException;
+import org.onap.appc.adapter.iaas.provider.operation.impl.RebuildServer;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+
+
+public class TestRebuildServer {
+ protected static final Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ @Test
+ public void rebuildServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).rebuild("linuxBase");
+ inOrderTest.verify(server).start();
+
+ }
+
+ @Test
+ public void rebuildServerReady() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.READY);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).rebuild("linuxBase");
+ inOrderTest.verify(server).start();
+ }
+
+ @Test
+ public void rebuildServerPause() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.PAUSED);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).unpause();
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).rebuild("linuxBase");
+ inOrderTest.verify(server).start();
+ }
+
+ @Test
+ public void rebuildServerError() {
+ MockGenerator mg = new MockGenerator(Status.ERROR);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ verify(mg.getSvcLogicContext()).setAttribute(org.onap.appc.Constants.ATTRIBUTE_ERROR_CODE,
+ "405");
+ }
+
+ @Test
+ public void rebuildServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).resume();
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).rebuild("linuxBase");
+ inOrderTest.verify(server).start();
+ }
+
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRestartServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRestartServer.java
new file mode 100644
index 000000000..202c09a5e
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRestartServer.java
@@ -0,0 +1,44 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import static org.mockito.Mockito.inOrder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+
+public class TestRestartServer {
+
+ @Test
+ public void restartServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ RestartServer rbs = new RestartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during RestartServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).resume();
+ }
+
+ @Test
+ public void restartServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ RestartServer rbs = new RestartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during RestartServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).start();
+ }
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestStartServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestStartServer.java
new file mode 100644
index 000000000..f6c188319
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestStartServer.java
@@ -0,0 +1,43 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import static org.mockito.Mockito.inOrder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+
+public class TestStartServer {
+
+ @Test
+ public void startServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ StartServer rbs = new StartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during StartServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).resume();
+ }
+
+ @Test
+ public void startServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.PAUSED);
+ Server server = mg.getServer();
+ StartServer rbs = new StartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during StartServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).unpause();
+ }
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestStopServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestStopServer.java
new file mode 100644
index 000000000..4a35a2bbe
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestStopServer.java
@@ -0,0 +1,43 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import static org.mockito.Mockito.inOrder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+
+public class TestStopServer {
+
+ @Test
+ public void stopServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ StopServer rbs = new StopServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during StopServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).resume();
+ }
+
+ @Test
+ public void stopServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.PAUSED);
+ Server server = mg.getServer();
+ StopServer rbs = new StopServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during StopServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).unpause();
+ }
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestTerminateServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestTerminateServer.java
new file mode 100644
index 000000000..2cce04fe4
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestTerminateServer.java
@@ -0,0 +1,45 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import static org.mockito.Mockito.inOrder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+
+public class TestTerminateServer {
+
+ @Test
+ public void terminateServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ TerminateServer rbs = new TerminateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during TerminateServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).delete();
+ }
+
+ @Test
+ public void terminateServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ TerminateServer rbs = new TerminateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ int i = 5;
+ } catch (APPCException e) {
+ Assert.fail("Exception during TerminateServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).delete();
+ }
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestTerminateStack.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestTerminateStack.java
new file mode 100644
index 000000000..6bc8f4631
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestTerminateStack.java
@@ -0,0 +1,51 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.appc.Constants;
+import org.onap.appc.adapter.iaas.ProviderAdapter;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.StackService;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Stack;
+import com.att.cdp.zones.model.Server.Status;
+
+public class TestTerminateStack {
+
+ @Test
+ public void terminateStack() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ StackService stackService = mock(StackService.class);
+ Stack stack1 = mock(Stack.class);
+ doReturn("stack1").when(stack1).getId();
+ doReturn("stack1").when(stack1).getName();
+ com.att.cdp.zones.model.Stack.Status stackStatus =
+ com.att.cdp.zones.model.Stack.Status.DELETED;
+ doReturn(stackStatus).when(stack1).getStatus();
+ doReturn(mg.getContext()).when(stack1).getContext();
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ doReturn(stackList).when(stackService).getStacks();
+ doReturn(stack1).when(stackService).getStack("stack1", "stack1");
+ doReturn(stackService).when(mg.getContext()).getStackService();
+ mg.getParams().put(ProviderAdapter.PROPERTY_STACK_ID, "stack1");
+
+ TerminateStack rbs = new TerminateStack();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during TerminateStack.executeProviderOperation");
+ }
+ verify(stackService).deleteStack(stack1);
+ }
+}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestVmStatuschecker.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestVmStatuschecker.java
new file mode 100644
index 000000000..cdf3b7fe2
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestVmStatuschecker.java
@@ -0,0 +1,62 @@
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.appc.Constants;
+import org.onap.appc.exceptions.APPCException;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.atLeastOnce;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+
+public class TestVmStatuschecker {
+
+ @Test
+ public void vmStatuscheckerSuspended() {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = null;
+ try {
+ mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
+ }
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM,
+ "suspended");
+ }
+
+ @Test
+ public void vmStatuscheckerRunning() {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = null;
+ try {
+ mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
+ }
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM,
+ "running");
+ }
+
+ @Test
+ public void vmStatuscheckerError() {
+ MockGenerator mg = new MockGenerator(Status.ERROR);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = null;
+ try {
+ mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (APPCException e) {
+ Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
+ }
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM,
+ "error");
+ }
+}