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 * @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);
71 * assertTrue(outputs.value.isEmpty()); }
75 * @Test public void queryVnfTest() throws Exception {
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)));
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)));
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)));
91 * instance.queryVnf("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>(), new Holder<>(), new
92 * Holder<>(), new Holder<>());
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");
104 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>());
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)));
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)));
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)));
124 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens"))
125 .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK)));
127 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>());
131 public void deleteVnfVnfExceptionTest() throws Exception {
132 expectedException.expect(VnfException.class);
133 MsoRequest msoRequest = new MsoRequest();
134 msoRequest.setRequestId("12345");
135 msoRequest.setServiceInstanceId("12345");
137 instance.deleteVnf("12344", "CloudOwner", "234", "vnfname", msoRequest);
142 public void rollbackVnf() throws Exception {
143 MsoRequest msoRequest = new MsoRequest();
144 msoRequest.setRequestId("12345");
145 msoRequest.setServiceInstanceId("12345");
147 VnfRollback vnfRollback = new VnfRollback();
148 vnfRollback.setModelCustomizationUuid("1234");
149 vnfRollback.setVfModuleStackId("2134");
150 vnfRollback.setVnfId("123");
151 vnfRollback.setModelCustomizationUuid("1234");
153 instance.rollbackVnf(vnfRollback);
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");
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);
170 instance.rollbackVnf(vnfRollback);
174 public void createVfModuleVnfException() throws Exception {
175 expectedException.expect(VnfException.class);
176 MsoRequest msoRequest = new MsoRequest();
177 msoRequest.setRequestId("12345");
178 msoRequest.setServiceInstanceId("12345");
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<>());
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");
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<>());
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");
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<>());
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");
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<>());
220 public void createVfModule() throws Exception {
221 expectedException.expect(VnfException.class);
222 MsoRequest msoRequest = new MsoRequest();
223 msoRequest.setRequestId("12345");
224 msoRequest.setServiceInstanceId("12345");
226 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname"))
227 .willReturn(aResponse().withBody("{ \"id\": \"123\" }").withStatus(HttpStatus.SC_OK)));
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)));
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)));
237 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens"))
238 .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK)));
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<>());
246 public void updateVfModuleVnfException() throws Exception {
247 expectedException.expect(VnfException.class);
248 MsoRequest msoRequest = new MsoRequest();
249 msoRequest.setRequestId("12345");
250 msoRequest.setServiceInstanceId("12345");
252 instance.updateVfModule("123", "CloudOwner", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234",
253 new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
257 public void healthCheckVNFTest() {
258 instance.healthCheck();
262 public void createVnfTest() {
263 MsoRequest msoRequest = new MsoRequest();
264 msoRequest.setRequestId("12345");
265 msoRequest.setServiceInstanceId("12345");
267 Map<String, Object> map = new HashMap<>();
268 map.put("key1", "value1");
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) {
278 public void updateVnfTest() {
279 MsoRequest msoRequest = new MsoRequest();
280 msoRequest.setRequestId("12345");
281 msoRequest.setServiceInstanceId("12345");
283 Map<String, Object> map = new HashMap<>();
285 map.put("key1", "value1");
287 instance.updateVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
288 "volumeGroupHeatStackId|1", map, msoRequest, new Holder<>(), new Holder<>());
289 } catch (Exception e) {
295 public void deleteVnfTest() {
296 MsoRequest msoRequest = new MsoRequest();
297 msoRequest.setRequestId("12345");
298 msoRequest.setServiceInstanceId("12345");
300 instance.deleteVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest);
301 } catch (Exception e) {