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", "5aae1e49-805c-4f9f-bd78-055bf7451157",
105 "11420693-3f69-4c61-b3ee-9787c744e760", "customizationId", msoRequest, new Holder<>());
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)));
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)));
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)));
125 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens"))
126 .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK)));
128 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", "5aae1e49-805c-4f9f-bd78-055bf7451157",
129 "11420693-3f69-4c61-b3ee-9787c744e760", "customizationId", msoRequest, new Holder<>());
133 public void deleteVnfVnfExceptionTest() throws Exception {
134 expectedException.expect(VnfException.class);
135 MsoRequest msoRequest = new MsoRequest();
136 msoRequest.setRequestId("12345");
137 msoRequest.setServiceInstanceId("12345");
139 instance.deleteVnf("12344", "CloudOwner", "234", "vnfname", msoRequest);
144 public void rollbackVnf() throws Exception {
145 MsoRequest msoRequest = new MsoRequest();
146 msoRequest.setRequestId("12345");
147 msoRequest.setServiceInstanceId("12345");
149 VnfRollback vnfRollback = new VnfRollback();
150 vnfRollback.setModelCustomizationUuid("1234");
151 vnfRollback.setVfModuleStackId("2134");
152 vnfRollback.setVnfId("123");
153 vnfRollback.setModelCustomizationUuid("1234");
155 instance.rollbackVnf(vnfRollback);
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");
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);
172 instance.rollbackVnf(vnfRollback);
176 public void createVfModuleVnfException() throws Exception {
177 expectedException.expect(VnfException.class);
178 MsoRequest msoRequest = new MsoRequest();
179 msoRequest.setRequestId("12345");
180 msoRequest.setServiceInstanceId("12345");
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<>());
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");
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<>());
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");
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<>());
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");
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<>());
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 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname"))
229 .willReturn(aResponse().withBody("{ \"id\": \"123\" }").withStatus(HttpStatus.SC_OK)));
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)));
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)));
239 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens"))
240 .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK)));
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<>());
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", "CloudOwner", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234",
255 new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
259 public void healthCheckVNFTest() {
260 instance.healthCheck();
264 public void createVnfTest() {
265 MsoRequest msoRequest = new MsoRequest();
266 msoRequest.setRequestId("12345");
267 msoRequest.setServiceInstanceId("12345");
269 Map<String, Object> map = new HashMap<>();
270 map.put("key1", "value1");
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) {
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", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
290 "volumeGroupHeatStackId|1", map, msoRequest, new Holder<>(), new Holder<>());
291 } catch (Exception e) {
297 public void deleteVnfTest() {
298 MsoRequest msoRequest = new MsoRequest();
299 msoRequest.setRequestId("12345");
300 msoRequest.setServiceInstanceId("12345");
302 instance.deleteVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest);
303 } catch (Exception e) {