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 org.apache.http.HttpStatus;
25 import org.junit.Before;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.ExpectedException;
29 import org.onap.so.adapters.vnf.exceptions.VnfException;
30 import org.onap.so.cloud.CloudConfig;
31 import org.onap.so.db.catalog.beans.CloudifyManager;
32 import org.onap.so.entity.MsoRequest;
33 import org.onap.so.openstack.beans.VnfRollback;
34 import org.springframework.beans.factory.annotation.Autowired;
36 import javax.xml.ws.Holder;
37 import java.util.HashMap;
40 import static com.github.tomakehurst.wiremock.client.WireMock.*;
42 public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils {
45 public ExpectedException expectedException = ExpectedException.none();
48 private MsoVnfCloudifyAdapterImpl instance;
51 private CloudConfig cloudConfig;
54 public void before() throws Exception {
56 CloudifyManager cloudifyManager = new CloudifyManager();
57 cloudifyManager.setId("mtn13");
58 cloudifyManager.setCloudifyUrl("http://localhost:"+wireMockPort+"/v2.0");
59 cloudifyManager.setUsername("m93945");
60 cloudifyManager.setPassword("93937EA01B94A10A49279D4572B48369");
64 public void queryVnfExceptionTest() throws Exception {
66 expectedException.expect(VnfException.class);
67 MsoRequest msoRequest = new MsoRequest();
68 msoRequest.setRequestId("12345");
69 msoRequest.setServiceInstanceId("12345");
71 instance.queryVnf("siteid", "1234", "vfname",
72 msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
77 public void queryVnfTest() throws Exception {
78 MsoRequest msoRequest = new MsoRequest();
79 msoRequest.setRequestId("12345");
80 msoRequest.setServiceInstanceId("12345");
81 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
82 .withBody("{ \"id\": \"123\" }")
83 .withStatus(HttpStatus.SC_OK)));
85 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
86 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
87 .withStatus(HttpStatus.SC_OK)));
89 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 stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
94 .withBodyFile("OpenstackResponse_Access.json")
95 .withStatus(HttpStatus.SC_OK)));
97 instance.queryVnf("mtn13", "1234", "vfname",
98 msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
103 public void deleteVfModuleTest_ExceptionWhileQueryDeployment() throws Exception {
104 expectedException.expect(VnfException.class);
105 MsoRequest msoRequest = new MsoRequest();
106 msoRequest.setRequestId("12345");
107 msoRequest.setServiceInstanceId("12345");
109 instance.deleteVfModule("mtn13", "1234", "vfname", msoRequest, new Holder<>());
113 public void deleteVfModuleTest_ExceptionWhileDeleteDeployment() throws Exception {
114 expectedException.expect(VnfException.class);
115 MsoRequest msoRequest = new MsoRequest();
116 msoRequest.setRequestId("12345");
117 msoRequest.setServiceInstanceId("12345");
118 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
119 .withBody("{ \"id\": \"123\" }")
120 .withStatus(HttpStatus.SC_OK)));
122 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
123 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
124 .withStatus(HttpStatus.SC_OK)));
126 stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
127 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
128 .withStatus(HttpStatus.SC_OK)));
130 stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
131 .withBodyFile("OpenstackResponse_Access.json")
132 .withStatus(HttpStatus.SC_OK)));
134 instance.deleteVfModule("mtn13", "1234", "vfname", msoRequest, new Holder<>());
138 public void deleteVnfVnfExceptionTest() throws Exception {
139 expectedException.expect(VnfException.class);
140 MsoRequest msoRequest = new MsoRequest();
141 msoRequest.setRequestId("12345");
142 msoRequest.setServiceInstanceId("12345");
144 instance.deleteVnf("12344", "234", "vnfname", msoRequest);
149 public void rollbackVnf() throws Exception {
150 MsoRequest msoRequest = new MsoRequest();
151 msoRequest.setRequestId("12345");
152 msoRequest.setServiceInstanceId("12345");
154 VnfRollback vnfRollback = new VnfRollback();
155 vnfRollback.setModelCustomizationUuid("1234");
156 vnfRollback.setVfModuleStackId("2134");
157 vnfRollback.setVnfId("123");
158 vnfRollback.setModelCustomizationUuid("1234");
160 instance.rollbackVnf(vnfRollback);
164 public void rollbackVnf_Created() throws Exception {
165 expectedException.expect(VnfException.class);
166 MsoRequest msoRequest = new MsoRequest();
167 msoRequest.setRequestId("12345");
168 msoRequest.setServiceInstanceId("12345");
170 VnfRollback vnfRollback = new VnfRollback();
171 vnfRollback.setModelCustomizationUuid("1234");
172 vnfRollback.setVfModuleStackId("2134");
173 vnfRollback.setVnfId("123");
174 vnfRollback.setModelCustomizationUuid("1234");
175 vnfRollback.setVnfCreated(true);
177 instance.rollbackVnf(vnfRollback);
181 public void createVfModuleVnfException() throws Exception {
182 expectedException.expect(VnfException.class);
183 MsoRequest msoRequest = new MsoRequest();
184 msoRequest.setRequestId("12345");
185 msoRequest.setServiceInstanceId("12345");
187 instance.createVfModule("123", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", "123", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
191 public void createVfModule_ModelCustUuidIsNull() throws Exception {
192 expectedException.expect(VnfException.class);
193 MsoRequest msoRequest = new MsoRequest();
194 msoRequest.setRequestId("12345");
195 msoRequest.setServiceInstanceId("12345");
197 instance.createVfModule("123", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", null, new
198 HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
202 public void createVfModule_CloudSiteIdNotFound() throws Exception {
203 expectedException.expect(VnfException.class);
204 MsoRequest msoRequest = new MsoRequest();
205 msoRequest.setRequestId("12345");
206 msoRequest.setServiceInstanceId("12345");
208 instance.createVfModule("123", "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<>());
212 public void createVfModule_MsoCloudifyManagerNotFound() throws Exception {
213 expectedException.expect(VnfException.class);
214 MsoRequest msoRequest = new MsoRequest();
215 msoRequest.setRequestId("12345");
216 msoRequest.setServiceInstanceId("12345");
218 instance.createVfModule("mtn13", "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<>());
222 public void createVfModule() throws Exception {
223 expectedException.expect(VnfException.class);
224 MsoRequest msoRequest = new MsoRequest();
225 msoRequest.setRequestId("12345");
226 msoRequest.setServiceInstanceId("12345");
228 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
229 .withBody("{ \"id\": \"123\" }")
230 .withStatus(HttpStatus.SC_OK)));
232 stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
233 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
234 .withStatus(HttpStatus.SC_OK)));
236 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 stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
241 .withBodyFile("OpenstackResponse_Access.json")
242 .withStatus(HttpStatus.SC_OK)));
244 instance.createVfModule("mtn13", "123", "vf", "v1", "", "vfname", "", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
248 public void updateVfModuleVnfException() throws Exception {
249 expectedException.expect(VnfException.class);
250 MsoRequest msoRequest = new MsoRequest();
251 msoRequest.setRequestId("12345");
252 msoRequest.setServiceInstanceId("12345");
254 instance.updateVfModule("123", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234", new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
258 public void healthCheckVNFTest() {
259 instance.healthCheck();
263 public void createVnfTest() {
264 MsoRequest msoRequest = new MsoRequest();
265 msoRequest.setRequestId("12345");
266 msoRequest.setServiceInstanceId("12345");
268 Map<String, Object> map = new HashMap<>();
269 map.put("key1", "value1");
271 instance.createVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
272 "volumeGroupHeatStackId|1", map,
273 Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(),
275 } catch (Exception e) {
280 public void updateVnfTest() {
281 MsoRequest msoRequest = new MsoRequest();
282 msoRequest.setRequestId("12345");
283 msoRequest.setServiceInstanceId("12345");
285 Map<String, Object> map = new HashMap<>();
287 map.put("key1", "value1");
289 instance.updateVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
290 "volumeGroupHeatStackId|1", map, msoRequest, 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", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest);
304 } catch (Exception e) {