aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-01 17:00:51 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-01 22:27:23 +0000
commite1aaf581480a3b9deb6ebd5e436470b283eae305 (patch)
tree36fdd560622a657d26cb9e2d3f49aa0c4827c606 /appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle
parent47e8eed7c3b402827c7a62e0c2ec9489d6dfabc5 (diff)
Test coverage for RestoreStack
Added new test file for untested class Issue-ID: APPC-1374 Change-Id: Ie180b5a8f10aaa8aa7ea8b83b403a2eab1885818 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle')
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRestoreStack.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRestoreStack.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRestoreStack.java
new file mode 100644
index 000000000..604c2085b
--- /dev/null
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRestoreStack.java
@@ -0,0 +1,92 @@
+/*
+ * ============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.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import java.util.LinkedList;
+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.ProviderAdapter;
+import org.onap.appc.adapter.iaas.impl.RequestContext;
+import org.onap.appc.exceptions.APPCException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.openstack.connectors.HeatConnector;
+import com.att.cdp.zones.StackService;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Stack;
+import com.att.cdp.zones.Context;
+
+
+public class TestRestoreStack {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void restoreStackTest() throws ZoneException, APPCException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ HeatConnector heatConnector = Mockito.mock(HeatConnector.class);
+ StackService stackService = mock(StackService.class);
+ Stack stack1 = mock(Stack.class);
+ doReturn("stack1").when(stack1).getId();
+ doReturn("stack1").when(stack1).getName();
+ doReturn(heatConnector).when(mg.getContext()).getHeatConnector();
+ 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");
+ mg.getParams().put(ProviderAdapter.PROPERTY_INSTANCE_URL, "URL");
+ mg.getParams().put(ProviderAdapter.PROPERTY_PROVIDER_NAME, "NAME");
+ mg.getParams().put(ProviderAdapter.PROPERTY_INPUT_SNAPSHOT_ID, "SNAPSHOT_ID");
+ SubclassRestoreStack rbs = Mockito.spy(new SubclassRestoreStack());
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ Mockito.doReturn(stack1).when(rbs).lookupStack(Mockito.any(RequestContext.class), Mockito.any(Context.class),
+ Mockito.anyString());
+ Mockito.doReturn(mg.getContext()).when(rbs).resolveContext(Mockito.any(RequestContext.class), Mockito.anyMap(),
+ Mockito.anyString(), Mockito.anyString());
+ expectedEx.expect(APPCException.class);
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ }
+
+ class SubclassRestoreStack extends RestoreStack {
+ @Override
+ protected Context resolveContext(RequestContext rc, Map<String, String> params, String appName, String vmUrl) {
+ return Mockito.mock(Context.class);
+ }
+ @Override
+ protected Stack lookupStack(RequestContext rc, Context context, String id) {
+ Stack stack = Mockito.mock(Stack.class);
+ return stack;
+ }
+ }
+}