2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.so.adapters.vnf;
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;
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;
44 public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils {
47 public ExpectedException expectedException = ExpectedException.none();
50 private MsoVnfCloudifyAdapterImpl instance;
53 private CloudConfig cloudConfig;
56 public void before() throws Exception {
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");
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);
74 assertTrue(outputs.value.isEmpty());
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)));
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)));
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)));
93 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens"))
94 .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK)));
96 instance.queryVnf("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>(), new Holder<>(),
97 new Holder<>(), new Holder<>());
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");
107 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>());
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)));
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)));
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)));
127 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens"))
128 .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK)));
130 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>());
134 public void deleteVnfVnfExceptionTest() throws Exception {
135 expectedException.expect(VnfException.class);
136 MsoRequest msoRequest = new MsoRequest();
137 msoRequest.setRequestId("12345");
138 msoRequest.setServiceInstanceId("12345");
140 instance.deleteVnf("12344", "CloudOwner", "234", "vnfname", msoRequest);
145 public void rollbackVnf() throws Exception {
146 MsoRequest msoRequest = new MsoRequest();
147 msoRequest.setRequestId("12345");
148 msoRequest.setServiceInstanceId("12345");
150 VnfRollback vnfRollback = new VnfRollback();
151 vnfRollback.setModelCustomizationUuid("1234");
152 vnfRollback.setVfModuleStackId("2134");
153 vnfRollback.setVnfId("123");
154 vnfRollback.setModelCustomizationUuid("1234");
156 instance.rollbackVnf(vnfRollback);
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");
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);
173 instance.rollbackVnf(vnfRollback);
177 public void createVfModuleVnfException() throws Exception {
178 expectedException.expect(VnfException.class);
179 MsoRequest msoRequest = new MsoRequest();
180 msoRequest.setRequestId("12345");
181 msoRequest.setServiceInstanceId("12345");
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<>());
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");
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<>());
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");
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<>());
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");
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<>());
223 public void createVfModule() throws Exception {
224 expectedException.expect(VnfException.class);
225 MsoRequest msoRequest = new MsoRequest();
226 msoRequest.setRequestId("12345");
227 msoRequest.setServiceInstanceId("12345");
229 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname"))
230 .willReturn(aResponse().withBody("{ \"id\": \"123\" }").withStatus(HttpStatus.SC_OK)));
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)));
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)));
240 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens"))
241 .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK)));
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<>());
249 public void updateVfModuleVnfException() throws Exception {
250 expectedException.expect(VnfException.class);
251 MsoRequest msoRequest = new MsoRequest();
252 msoRequest.setRequestId("12345");
253 msoRequest.setServiceInstanceId("12345");
255 instance.updateVfModule("123", "CloudOwner", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234",
256 new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
260 public void healthCheckVNFTest() {
261 instance.healthCheck();
265 public void createVnfTest() {
266 MsoRequest msoRequest = new MsoRequest();
267 msoRequest.setRequestId("12345");
268 msoRequest.setServiceInstanceId("12345");
270 Map<String, Object> map = new HashMap<>();
271 map.put("key1", "value1");
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) {
281 public void updateVnfTest() {
282 MsoRequest msoRequest = new MsoRequest();
283 msoRequest.setRequestId("12345");
284 msoRequest.setServiceInstanceId("12345");
286 Map<String, Object> map = new HashMap<>();
288 map.put("key1", "value1");
290 instance.updateVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
291 "volumeGroupHeatStackId|1", map, msoRequest, new Holder<>(), new Holder<>());
292 } catch (Exception e) {
298 public void deleteVnfTest() {
299 MsoRequest msoRequest = new MsoRequest();
300 msoRequest.setRequestId("12345");
301 msoRequest.setServiceInstanceId("12345");
303 instance.deleteVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest);
304 } catch (Exception e) {