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