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