0ace6e42499850f82e7d0f8fda64daa43ed605a1
[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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
28 import static org.junit.Assert.assertTrue;
29
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import javax.xml.ws.Holder;
34
35 import org.apache.http.HttpStatus;
36 import org.junit.Before;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.ExpectedException;
40 import org.onap.so.adapters.vnf.exceptions.VnfException;
41 import org.onap.so.cloud.CloudConfig;
42 import org.onap.so.db.catalog.beans.CloudifyManager;
43 import org.onap.so.entity.MsoRequest;
44 import org.onap.so.openstack.beans.VnfRollback;
45 import org.springframework.beans.factory.annotation.Autowired;
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() throws Exception {
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         }
67         
68         @Test 
69     public void queryVnfExceptionTest() throws Exception {
70         MsoRequest msoRequest = new MsoRequest();
71         msoRequest.setRequestId("12345");
72         msoRequest.setServiceInstanceId("12345");
73         Holder <Map <String, String>> outputs = new Holder<>();
74         instance.queryVnf("siteid", "CloudOwner", "1234", "vfname",
75                 msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
76                 outputs);
77         
78         assertTrue(outputs.value.isEmpty());
79     }
80
81         @Test
82         public void queryVnfTest() throws Exception {
83                 MsoRequest msoRequest = new MsoRequest();
84                 msoRequest.setRequestId("12345");
85                 msoRequest.setServiceInstanceId("12345");
86                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
87                                 .withBody("{ \"id\": \"123\" }")
88                                 .withStatus(HttpStatus.SC_OK)));
89                 
90                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
91                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
92                                 .withStatus(HttpStatus.SC_OK)));
93
94                 wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
95                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
96                                 .withStatus(HttpStatus.SC_OK)));
97
98                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
99                                 .withBodyFile("OpenstackResponse_Access.json")
100                                 .withStatus(HttpStatus.SC_OK)));
101                 
102                 instance.queryVnf("mtn13", "CloudOwner", "1234", "vfname",
103                                 msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
104                                 new Holder<>());
105         }
106
107         @Test
108         public void deleteVfModuleTest_ExceptionWhileQueryDeployment() throws Exception {
109                 expectedException.expect(VnfException.class);
110                 MsoRequest msoRequest = new MsoRequest();
111                 msoRequest.setRequestId("12345");
112                 msoRequest.setServiceInstanceId("12345");
113
114                 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>());
115         }
116
117         @Test
118         public void deleteVfModuleTest_ExceptionWhileDeleteDeployment() throws Exception {
119                 expectedException.expect(VnfException.class);
120                 MsoRequest msoRequest = new MsoRequest();
121                 msoRequest.setRequestId("12345");
122                 msoRequest.setServiceInstanceId("12345");
123                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
124                                 .withBody("{ \"id\": \"123\" }")
125                                 .withStatus(HttpStatus.SC_OK)));
126
127                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
128                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
129                                 .withStatus(HttpStatus.SC_OK)));
130
131                 wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
132                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
133                                 .withStatus(HttpStatus.SC_OK)));
134
135                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
136                                 .withBodyFile("OpenstackResponse_Access.json")
137                                 .withStatus(HttpStatus.SC_OK)));
138
139                 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>());
140         }
141         
142         @Test
143     public void deleteVnfVnfExceptionTest() throws Exception {
144                 expectedException.expect(VnfException.class);
145         MsoRequest msoRequest = new MsoRequest();
146         msoRequest.setRequestId("12345");
147         msoRequest.setServiceInstanceId("12345");
148
149         instance.deleteVnf("12344", "CloudOwner", "234", "vnfname", msoRequest);
150
151     }
152
153         @Test
154         public void rollbackVnf() throws Exception {
155                 MsoRequest msoRequest = new MsoRequest();
156                 msoRequest.setRequestId("12345");
157                 msoRequest.setServiceInstanceId("12345");
158
159         VnfRollback vnfRollback = new VnfRollback();
160         vnfRollback.setModelCustomizationUuid("1234");
161         vnfRollback.setVfModuleStackId("2134");
162         vnfRollback.setVnfId("123");
163         vnfRollback.setModelCustomizationUuid("1234");
164
165         instance.rollbackVnf(vnfRollback);
166         }
167
168         @Test
169         public void rollbackVnf_Created() throws Exception {
170                 expectedException.expect(VnfException.class);
171                 MsoRequest msoRequest = new MsoRequest();
172                 msoRequest.setRequestId("12345");
173                 msoRequest.setServiceInstanceId("12345");
174
175                 VnfRollback vnfRollback = new VnfRollback();
176                 vnfRollback.setModelCustomizationUuid("1234");
177                 vnfRollback.setVfModuleStackId("2134");
178                 vnfRollback.setVnfId("123");
179                 vnfRollback.setModelCustomizationUuid("1234");
180                 vnfRollback.setVnfCreated(true);
181
182                 instance.rollbackVnf(vnfRollback);
183         }
184
185         @Test
186         public void createVfModuleVnfException() throws Exception {
187                 expectedException.expect(VnfException.class);
188                 MsoRequest msoRequest = new MsoRequest();
189                 msoRequest.setRequestId("12345");
190                 msoRequest.setServiceInstanceId("12345");
191
192                 instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", "123", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
193         }
194
195         @Test
196         public void createVfModule_ModelCustUuidIsNull() throws Exception {
197                 expectedException.expect(VnfException.class);
198                 MsoRequest msoRequest = new MsoRequest();
199                 msoRequest.setRequestId("12345");
200                 msoRequest.setServiceInstanceId("12345");
201
202                 instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", null, new 
203                                 HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
204         }
205
206         @Test
207         public void createVfModule_CloudSiteIdNotFound() throws Exception {
208                 expectedException.expect(VnfException.class);
209                 MsoRequest msoRequest = new MsoRequest();
210                 msoRequest.setRequestId("12345");
211                 msoRequest.setServiceInstanceId("12345");
212
213                 instance.createVfModule("123", "CloudOwner", "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<>());
214         }
215
216         @Test
217         public void createVfModule_MsoCloudifyManagerNotFound() throws Exception {
218                 expectedException.expect(VnfException.class);
219                 MsoRequest msoRequest = new MsoRequest();
220                 msoRequest.setRequestId("12345");
221                 msoRequest.setServiceInstanceId("12345");
222
223                 instance.createVfModule("mtn13", "CloudOwner", "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<>());
224         }
225
226         @Test
227         public void createVfModule() throws Exception {
228                 expectedException.expect(VnfException.class);
229                 MsoRequest msoRequest = new MsoRequest();
230                 msoRequest.setRequestId("12345");
231                 msoRequest.setServiceInstanceId("12345");
232
233                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
234                                 .withBody("{ \"id\": \"123\" }")
235                                 .withStatus(HttpStatus.SC_OK)));
236
237                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
238                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
239                                 .withStatus(HttpStatus.SC_OK)));
240
241                 wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
242                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
243                                 .withStatus(HttpStatus.SC_OK)));
244
245                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
246                                 .withBodyFile("OpenstackResponse_Access.json")
247                                 .withStatus(HttpStatus.SC_OK)));
248
249                 instance.createVfModule("mtn13", "CloudOwner", "123", "vf", "v1", "", "vfname", "", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
250         }
251
252         @Test
253         public void updateVfModuleVnfException() throws Exception {
254                 expectedException.expect(VnfException.class);
255                 MsoRequest msoRequest = new MsoRequest();
256                 msoRequest.setRequestId("12345");
257                 msoRequest.setServiceInstanceId("12345");
258
259                 instance.updateVfModule("123", "CloudOwner", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234", new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
260         }
261
262         @Test
263         public void healthCheckVNFTest() {
264                 instance.healthCheck();
265         }
266
267         @Test
268         public void createVnfTest() {
269                 MsoRequest msoRequest = new MsoRequest();
270                 msoRequest.setRequestId("12345");
271                 msoRequest.setServiceInstanceId("12345");
272
273                 Map<String, Object> map = new HashMap<>();
274                 map.put("key1", "value1");
275                 try {
276                         instance.createVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
277                                         "volumeGroupHeatStackId|1", map,
278                                         Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(),
279                 new Holder<>());
280                 } catch (Exception e) {
281                 }
282         }
283
284         @Test
285         public void updateVnfTest() {
286                 MsoRequest msoRequest = new MsoRequest();
287                 msoRequest.setRequestId("12345");
288                 msoRequest.setServiceInstanceId("12345");
289
290                 Map<String, Object> map = new HashMap<>();
291                 
292                 map.put("key1", "value1");
293                 try {
294                         instance.updateVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
295                                         "volumeGroupHeatStackId|1",  map, msoRequest, new Holder<>(),
296                 new Holder<>());
297                 } catch (Exception e) {
298
299                 }
300         }
301
302         @Test
303         public void deleteVnfTest() {
304                 MsoRequest msoRequest = new MsoRequest();
305                 msoRequest.setRequestId("12345");
306                 msoRequest.setServiceInstanceId("12345");
307                 try {
308                         instance.deleteVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest);
309                 } catch (Exception e) {
310
311                 }
312         }
313
314 }