2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.openstack.utils;
24 import com.woorea.openstack.heat.Heat;
25 import com.woorea.openstack.heat.model.Stack;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.Mock;
29 import org.openecomp.mso.cloud.CloudConfigFactory;
30 import org.openecomp.mso.cloud.CloudSite;
31 import org.openecomp.mso.openstack.beans.HeatStatus;
32 import org.openecomp.mso.openstack.beans.StackInfo;
33 import org.openecomp.mso.openstack.exceptions.MsoException;
34 import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound;
35 import org.openecomp.mso.properties.MsoPropertiesFactory;
36 import org.powermock.api.mockito.PowerMockito;
37 import org.powermock.core.classloader.annotations.PrepareForTest;
38 import org.powermock.modules.junit4.PowerMockRunner;
40 import java.util.HashMap;
43 import static org.junit.Assert.assertNotNull;
44 import static org.junit.Assert.assertNull;
45 import static org.mockito.Mockito.doReturn;
47 //@RunWith(PowerMockRunner.class)
48 @PrepareForTest({MsoHeatUtils.class})
51 public class MsoHeatUtilsTest {
57 MsoPropertiesFactory msoPropertiesFactory;
60 CloudConfigFactory cloudConfigFactory;
68 @Test(expected = NullPointerException.class)
69 public void testCreateStack() throws MsoException
72 MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory));
73 Map<String,String>metadata=new HashMap<>();
74 metadata.put("1", "value");
75 mht.createStack("cloudSiteId",
82 doReturn(mht.createStack("cloudSiteId",
95 @Test(expected = NullPointerException.class)
96 public void testCreateStackOne() throws MsoException
98 MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory));
99 Map<String,String>metadata=new HashMap<>();
100 metadata.put("1", "value");
101 mht.createStack("cloudSiteId",
109 doReturn(mht.createStack("cloudSiteId",
121 @Test(expected = NullPointerException.class)
122 public void testCreateStackTwo() throws MsoException
124 MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory));
125 Map<String,String>metadata=new HashMap<>();
126 metadata.put("1", "value");
127 Map<String,Object>fileMap=new HashMap<>();
128 fileMap.put("2", "value");
129 mht.createStack("cloudSiteId",
138 doReturn(mht.createStack("cloudSiteId",
150 @Test(expected = NullPointerException.class)
151 public void testCreateStackThree() throws MsoException
153 MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory));
154 Map<String,String>metadata=new HashMap<>();
155 metadata.put("1", "value");
156 Map<String,Object>fileMap=new HashMap<>();
157 fileMap.put("2", "value");
158 Map<String,Object>heatFileMap=new HashMap<>();
159 heatFileMap.put("3", "value");
160 mht.createStack("cloudSiteId",
170 doReturn(mht.createStack("cloudSiteId",
182 @Test(expected = NullPointerException.class)
185 public void testqueryStack() throws MsoException
187 MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory));
189 mht.queryStack("cloudSiteId","tenantId","stackName");
192 heatClient = mht.getHeatClient (cloudSite, "tenantId");
193 assertNotNull(heatClient);
195 } catch (MsoTenantNotFound e) {
196 doReturn(new StackInfo ("stackName", HeatStatus.NOTFOUND));
197 } catch (MsoException me) {
199 me.addContext ("QueryStack");
203 Stack heatStack = mht.queryHeatStack (heatClient, "stackName");
205 assertNull(heatStack);
206 StackInfo stackInfo = new StackInfo ("stackName", HeatStatus.NOTFOUND);
209 assertNotNull(heatStack);
210 doReturn(new StackInfo (heatStack));