116ea1cc03847c40cde5c2eb3df3451caedf7915
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / onap / appc / adapter / iaas / provider / operation / impl / TestTerminateStack.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * ============LICENSE_END=========================================================
22  */
23 package org.onap.appc.adapter.iaas.provider.operation.impl;
24
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.verify;
28 import java.util.LinkedList;
29 import java.util.List;
30 import org.junit.Assert;
31 import org.junit.Test;
32 import org.onap.appc.Constants;
33 import org.onap.appc.adapter.iaas.ProviderAdapter;
34 import org.onap.appc.configuration.Configuration;
35 import org.onap.appc.configuration.ConfigurationFactory;
36 import org.onap.appc.exceptions.APPCException;
37 import com.att.cdp.exceptions.ZoneException;
38 import com.att.cdp.zones.StackService;
39 import com.att.cdp.zones.model.Server;
40 import com.att.cdp.zones.model.Stack;
41 import com.att.cdp.zones.model.Server.Status;
42
43 public class TestTerminateStack {
44
45     @Test
46     public void terminateStack() throws ZoneException {
47         MockGenerator mg = new MockGenerator(Status.SUSPENDED);
48         Server server = mg.getServer();
49         StackService stackService = mock(StackService.class);
50         Stack stack1 = mock(Stack.class);
51         doReturn("stack1").when(stack1).getId();
52         doReturn("stack1").when(stack1).getName();
53         com.att.cdp.zones.model.Stack.Status stackStatus =
54                 com.att.cdp.zones.model.Stack.Status.DELETED;
55         doReturn(stackStatus).when(stack1).getStatus();
56         doReturn(mg.getContext()).when(stack1).getContext();
57         List<Stack> stackList = new LinkedList<Stack>();
58         stackList.add(stack1);
59         doReturn(stackList).when(stackService).getStacks();
60         doReturn(stack1).when(stackService).getStack("stack1", "stack1");
61         doReturn(stackService).when(mg.getContext()).getStackService();
62         mg.getParams().put(ProviderAdapter.PROPERTY_STACK_ID, "stack1");
63
64         TerminateStack rbs = new TerminateStack();
65         rbs.setProviderCache(mg.getProviderCacheMap());
66         try {
67             rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
68         } catch (APPCException e) {
69             Assert.fail("Exception during TerminateStack.executeProviderOperation");
70         }
71         verify(stackService).deleteStack(stack1);
72     }
73 }