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