Containerization feature of SO
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / adapters / vnf / MsoVnfCloudifyAdapterImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.so.adapters.vnf;
23
24 import org.apache.http.HttpStatus;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.rules.ExpectedException;
30 import org.onap.so.adapters.vnf.exceptions.VnfException;
31 import org.onap.so.cloud.CloudConfig;
32 import org.onap.so.cloud.CloudifyManager;
33 import org.onap.so.entity.MsoRequest;
34 import org.onap.so.openstack.beans.VnfRollback;
35 import org.springframework.beans.factory.annotation.Autowired;
36
37 import javax.xml.ws.Holder;
38 import java.util.HashMap;
39 import java.util.Map;
40
41 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
42 import static com.github.tomakehurst.wiremock.client.WireMock.get;
43 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
44 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
45 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
46
47 public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils {
48
49         @Rule
50         public ExpectedException expectedException = ExpectedException.none();
51         
52         @Autowired
53         private MsoVnfCloudifyAdapterImpl instance;
54
55         @Autowired
56         private CloudConfig cloudConfig;
57
58         @Before
59         public void before(){
60                 super.setUp();
61                 CloudifyManager cloudifyManager = new CloudifyManager();
62                 cloudifyManager.setId("mtn13");
63                 cloudifyManager.setCloudifyUrl("http://localhost:"+wireMockPort+"/v2.0");
64                 cloudifyManager.setUsername("m93945");
65                 cloudifyManager.setPassword("93937EA01B94A10A49279D4572B48369");
66                 cloudConfig.getCloudifyManagers().put("mtn13",cloudifyManager);
67         }
68         
69         @After
70         public void after(){
71                 cloudConfig.getCloudifyManagers().clear();
72         }
73         
74         @Test
75     public void queryVnfNullPointerExceptionTest() throws Exception {
76                 expectedException.expect(VnfException.class);
77         MsoRequest msoRequest = new MsoRequest();
78         msoRequest.setRequestId("12345");
79         msoRequest.setServiceInstanceId("12345");
80
81         instance.queryVnf("siteid", "1234", "vfname",
82                 msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
83                 new Holder<>());
84     }
85
86         @Test
87         public void queryVnfTest() throws Exception {
88                 MsoRequest msoRequest = new MsoRequest();
89                 msoRequest.setRequestId("12345");
90                 msoRequest.setServiceInstanceId("12345");
91                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
92                                 .withBody("{ \"id\": \"123\" }")
93                                 .withStatus(HttpStatus.SC_OK)));
94                 
95                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
96                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
97                                 .withStatus(HttpStatus.SC_OK)));
98
99                 stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
100                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
101                                 .withStatus(HttpStatus.SC_OK)));
102
103                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
104                                 .withBodyFile("OpenstackResponse_Access.json")
105                                 .withStatus(HttpStatus.SC_OK)));
106                 
107                 instance.queryVnf("mtn13", "1234", "vfname",
108                                 msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
109                                 new Holder<>());
110         }
111
112         @Test
113         public void deleteVfModuleTest_ExceptionWhileQueryDeployment() throws Exception {
114                 expectedException.expect(VnfException.class);
115                 MsoRequest msoRequest = new MsoRequest();
116                 msoRequest.setRequestId("12345");
117                 msoRequest.setServiceInstanceId("12345");
118
119                 instance.deleteVfModule("mtn13", "1234", "vfname", msoRequest, new Holder<>());
120         }
121
122         @Test
123         public void deleteVfModuleTest_ExceptionWhileDeleteDeployment() throws Exception {
124                 expectedException.expect(VnfException.class);
125                 MsoRequest msoRequest = new MsoRequest();
126                 msoRequest.setRequestId("12345");
127                 msoRequest.setServiceInstanceId("12345");
128                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
129                                 .withBody("{ \"id\": \"123\" }")
130                                 .withStatus(HttpStatus.SC_OK)));
131
132                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
133                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
134                                 .withStatus(HttpStatus.SC_OK)));
135
136                 stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
137                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
138                                 .withStatus(HttpStatus.SC_OK)));
139
140                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
141                                 .withBodyFile("OpenstackResponse_Access.json")
142                                 .withStatus(HttpStatus.SC_OK)));
143
144                 instance.deleteVfModule("mtn13", "1234", "vfname", msoRequest, new Holder<>());
145         }
146         
147         @Test
148     public void deleteVnfVnfExceptionTest() throws Exception {
149                 expectedException.expect(VnfException.class);
150         MsoRequest msoRequest = new MsoRequest();
151         msoRequest.setRequestId("12345");
152         msoRequest.setServiceInstanceId("12345");
153
154         instance.deleteVnf("12344", "234", "vnfname", msoRequest);
155
156     }
157
158         @Test
159         public void rollbackVnf() throws Exception {
160                 MsoRequest msoRequest = new MsoRequest();
161                 msoRequest.setRequestId("12345");
162                 msoRequest.setServiceInstanceId("12345");
163
164         VnfRollback vnfRollback = new VnfRollback();
165         vnfRollback.setModelCustomizationUuid("1234");
166         vnfRollback.setVfModuleStackId("2134");
167         vnfRollback.setVnfId("123");
168         vnfRollback.setModelCustomizationUuid("1234");
169
170         instance.rollbackVnf(vnfRollback);
171         }
172
173         @Test
174         public void rollbackVnf_Created() throws Exception {
175                 expectedException.expect(VnfException.class);
176                 MsoRequest msoRequest = new MsoRequest();
177                 msoRequest.setRequestId("12345");
178                 msoRequest.setServiceInstanceId("12345");
179
180                 VnfRollback vnfRollback = new VnfRollback();
181                 vnfRollback.setModelCustomizationUuid("1234");
182                 vnfRollback.setVfModuleStackId("2134");
183                 vnfRollback.setVnfId("123");
184                 vnfRollback.setModelCustomizationUuid("1234");
185                 vnfRollback.setVnfCreated(true);
186
187                 instance.rollbackVnf(vnfRollback);
188         }
189
190         @Test
191         public void createVfModuleVnfException() throws Exception {
192                 expectedException.expect(VnfException.class);
193                 MsoRequest msoRequest = new MsoRequest();
194                 msoRequest.setRequestId("12345");
195                 msoRequest.setServiceInstanceId("12345");
196
197                 instance.createVfModule("123", "123", "vf", "v1", "module-005", "create", "3245", "234", "123", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
198         }
199
200         @Test
201         public void createVfModule_ModelCustUuidIsNull() throws Exception {
202                 expectedException.expect(VnfException.class);
203                 MsoRequest msoRequest = new MsoRequest();
204                 msoRequest.setRequestId("12345");
205                 msoRequest.setServiceInstanceId("12345");
206
207                 instance.createVfModule("123", "123", "vf", "v1", "module-005", "create", "3245", "234", null, new 
208                                 HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
209         }
210
211         @Test
212         public void createVfModule_CloudSiteIdNotFound() throws Exception {
213                 expectedException.expect(VnfException.class);
214                 MsoRequest msoRequest = new MsoRequest();
215                 msoRequest.setRequestId("12345");
216                 msoRequest.setServiceInstanceId("12345");
217
218                 instance.createVfModule("123", "123", "vf", "v1", "module-005", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
219         }
220
221         @Test
222         public void createVfModule_MsoCloudifyManagerNotFound() throws Exception {
223                 expectedException.expect(VnfException.class);
224                 MsoRequest msoRequest = new MsoRequest();
225                 msoRequest.setRequestId("12345");
226                 msoRequest.setServiceInstanceId("12345");
227
228                 instance.createVfModule("mtn13", "123", "vf", "v1", "module-005", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
229         }
230
231         @Test
232         public void createVfModule() throws Exception {
233                 expectedException.expect(VnfException.class);
234                 MsoRequest msoRequest = new MsoRequest();
235                 msoRequest.setRequestId("12345");
236                 msoRequest.setServiceInstanceId("12345");
237
238                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
239                                 .withBody("{ \"id\": \"123\" }")
240                                 .withStatus(HttpStatus.SC_OK)));
241
242                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
243                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
244                                 .withStatus(HttpStatus.SC_OK)));
245
246                 stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
247                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
248                                 .withStatus(HttpStatus.SC_OK)));
249
250                 stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
251                                 .withBodyFile("OpenstackResponse_Access.json")
252                                 .withStatus(HttpStatus.SC_OK)));
253
254                 instance.createVfModule("mtn13", "123", "vf", "v1", "vfname", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
255         }
256
257         @Test
258         public void updateVfModuleVnfException() throws Exception {
259                 expectedException.expect(VnfException.class);
260                 MsoRequest msoRequest = new MsoRequest();
261                 msoRequest.setRequestId("12345");
262                 msoRequest.setServiceInstanceId("12345");
263
264                 instance.updateVfModule("123", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234", new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
265         }
266
267         @Test
268         public void healthCheckVNFTest() {
269                 instance.healthCheck();
270         }
271
272         @Test
273         public void createVnfTest() {
274                 MsoRequest msoRequest = new MsoRequest();
275                 msoRequest.setRequestId("12345");
276                 msoRequest.setServiceInstanceId("12345");
277
278                 Map<String, String> map = new HashMap<>();
279                 map.put("key1", "value1");
280                 try {
281                         instance.createVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
282                                         "volumeGroupHeatStackId|1", map,
283                                         Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(),
284                 new Holder<>());
285                 } catch (Exception e) {
286                 }
287         }
288
289         @Test
290         public void updateVnfTest() {
291                 MsoRequest msoRequest = new MsoRequest();
292                 msoRequest.setRequestId("12345");
293                 msoRequest.setServiceInstanceId("12345");
294
295                 Map<String, String> map = new HashMap<>();
296                 
297                 map.put("key1", "value1");
298                 try {
299                         instance.updateVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
300                                         "volumeGroupHeatStackId|1",  map, msoRequest, new Holder<>(),
301                 new Holder<>());
302                 } catch (Exception e) {
303
304                 }
305         }
306
307         @Test
308         public void deleteVnfTest() {
309                 MsoRequest msoRequest = new MsoRequest();
310                 msoRequest.setRequestId("12345");
311                 msoRequest.setServiceInstanceId("12345");
312                 try {
313                         instance.deleteVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest);
314                 } catch (Exception e) {
315
316                 }
317         }
318
319 }