Merge "Reorder modifiers"
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / openstack / utils / MsoHeatUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.mso.openstack.utils;
22
23
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;
39
40 import java.util.HashMap;
41 import java.util.Map;
42
43 import static org.junit.Assert.assertNotNull;
44 import static org.junit.Assert.assertNull;
45 import static org.mockito.Mockito.doReturn;
46
47 //@RunWith(PowerMockRunner.class)
48 @PrepareForTest({MsoHeatUtils.class})
49
50
51 public class MsoHeatUtilsTest {
52
53     @Mock
54     StackInfo stackInfo;
55
56     @Mock
57     MsoPropertiesFactory msoPropertiesFactory;
58
59     @Mock
60     CloudConfigFactory cloudConfigFactory;
61
62     @Mock
63     Heat heatClient;
64
65     @Mock
66     CloudSite cloudSite;
67
68     @Test(expected = NullPointerException.class)
69     public void testCreateStack() throws MsoException
70     {
71
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",
76                 "tenantId",
77                 "stackName",
78                 "heatTemplate",
79                  metadata,
80                  true,
81         1);
82            doReturn(mht.createStack("cloudSiteId",
83                    "tenantId",
84                    "stackName",
85                    "heatTemplate",
86                    metadata,
87         true,
88         1,
89         null, null,
90         null,
91         true));
92
93     }
94
95     @Test(expected = NullPointerException.class)
96     public void testCreateStackOne() throws MsoException
97     {
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",
102                 "tenantId",
103                 "stackName",
104                 "heatTemplate",
105                  metadata,
106                 true,
107                 1,
108                 "env");
109         doReturn(mht.createStack("cloudSiteId",
110                 "tenantId",
111                 "stackName",
112                 "heatTemplate",
113                 metadata,
114                 true,
115                 1,
116                 "env", null,
117                 null,
118                 true));
119     }
120
121     @Test(expected = NullPointerException.class)
122     public void testCreateStackTwo() throws MsoException
123     {
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",
130                 "tenantId",
131                 "stackName",
132                 "heatTemplate",
133                  metadata,
134                 true,
135                 1,
136                 "env",
137                  fileMap);
138         doReturn(mht.createStack("cloudSiteId",
139                 "tenantId",
140                 "stackName",
141                 "heatTemplate",
142                 metadata,
143                 true,
144                 1,
145                 "env", fileMap,
146                 null,
147                 true));
148     }
149
150     @Test(expected = NullPointerException.class)
151     public void testCreateStackThree() throws MsoException
152     {
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",
161                 "tenantId",
162                 "stackName",
163                 "heatTemplate",
164                 metadata,
165                 true,
166                 1,
167                 "env",
168                 fileMap,
169                 heatFileMap);
170         doReturn(mht.createStack("cloudSiteId",
171                 "tenantId",
172                 "stackName",
173                 "heatTemplate",
174                 metadata,
175                 true,
176                 1,
177                 "env", fileMap,
178                 heatFileMap,
179                 true));
180     }
181
182     @Test(expected = NullPointerException.class)
183
184
185     public void testqueryStack() throws MsoException
186     {
187         MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory));
188
189         mht.queryStack("cloudSiteId","tenantId","stackName");
190
191         try {
192             heatClient = mht.getHeatClient (cloudSite, "tenantId");
193             assertNotNull(heatClient);
194
195         } catch (MsoTenantNotFound e) {
196             doReturn(new StackInfo ("stackName", HeatStatus.NOTFOUND));
197         } catch (MsoException me) {
198
199             me.addContext ("QueryStack");
200             throw me;
201         }
202
203         Stack heatStack = mht.queryHeatStack (heatClient, "stackName");
204
205         assertNull(heatStack);
206         StackInfo stackInfo = new StackInfo ("stackName", HeatStatus.NOTFOUND);
207         doReturn(stackInfo);
208
209         assertNotNull(heatStack);
210         doReturn(new StackInfo (heatStack));
211
212
213
214     }
215
216 }