2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vnf;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
27 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
28 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_404;
29 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
30 import java.util.HashMap;
32 import javax.xml.ws.Holder;
33 import org.apache.http.HttpStatus;
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.entity.MsoRequest;
39 import org.onap.so.openstack.beans.VnfRollback;
40 import org.springframework.beans.factory.annotation.Autowired;
42 public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils {
45 public ExpectedException expectedException = ExpectedException.none();
48 MsoVnfPluginAdapterImpl msoVnfPluginAdapter;
50 String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
53 public void createVfModule_ModelCustUuidIsNull() throws Exception {
54 expectedException.expect(VnfException.class);
55 MsoRequest msoRequest = getMsoRequest();
56 Map<String, Object> map = new HashMap<>();
57 map.put("key1", "value1");
58 msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "",
59 vnfName, "", "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", null, map, Boolean.FALSE,
60 Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
61 new Holder<VnfRollback>());
65 public void createVfModule_ModelCustUuidIsNotFound() throws Exception {
66 expectedException.expect(VnfException.class);
67 MsoRequest msoRequest = getMsoRequest();
68 Map<String, Object> map = new HashMap<>();
69 map.put("key1", "value1");
70 msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "",
71 vnfName, "", "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId",
72 "88a6ca3ee0394ade9403f075db23167e", map, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest,
73 new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>());
77 public void createVfModule_VduException() throws Exception {
78 expectedException.expect(VnfException.class);
79 MsoRequest msoRequest = getMsoRequest();
80 Map<String, Object> map = new HashMap<>();
81 map.put("key1", "value1");
82 msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "",
83 vnfName, "", "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId",
84 "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest,
85 new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>());
89 public void createVfModule_INSTANTIATED() throws Exception {
90 mockOpenStackResponseAccess(wireMockServer, wireMockPort);
91 mockOpenStackGetStackVfModule_200(wireMockServer);
93 MsoRequest msoRequest = getMsoRequest();
94 Map<String, Object> map = new HashMap<>();
95 map.put("key1", "value1");
96 msoVnfPluginAdapter.createVfModule("MTN13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "",
97 vnfName, "", "VFMOD", null, "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
98 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(),
99 new Holder<Map<String, String>>(), new Holder<VnfRollback>());
103 public void createVfModule_queryVduNotFoundWithVolumeGroupId() throws Exception {
104 expectedException.expect(VnfException.class);
105 mockOpenStackResponseAccess(wireMockServer, wireMockPort);
106 MsoRequest msoRequest = getMsoRequest();
107 Map<String, Object> map = new HashMap<>();
108 map.put("key1", "value1");
109 msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "",
110 vnfName, "", "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId",
111 "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest,
112 new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>());
116 public void createVfModule_CreateVduException() throws Exception {
117 expectedException.expect(VnfException.class);
118 mockOpenStackResponseAccess(wireMockServer, wireMockPort);
119 mockOpenStackGetStackVfModule_404(wireMockServer);
120 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId"))
121 .willReturn(aResponse().withHeader("Content-Type", "application/json")
122 .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
123 MsoRequest msoRequest = getMsoRequest();
124 Map<String, Object> map = new HashMap<>();
125 map.put("key1", "value1");
126 msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "",
127 vnfName, "", "VFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId",
128 "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest,
129 new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>());
133 public void deleteVfModule_QueryVduException() throws Exception {
134 expectedException.expect(VnfException.class);
135 MsoRequest msoRequest = getMsoRequest();
136 msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12",
137 msoRequest, new Holder<Map<String, String>>());
141 public void deleteVfModule_DeleteVduException() throws Exception {
142 expectedException.expect(VnfException.class);
143 mockOpenStackResponseAccess(wireMockServer, wireMockPort);
144 mockOpenStackGetStackVfModule_200(wireMockServer);
145 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vSAMP12"))
146 .willReturn(aResponse().withHeader("Content-Type", "application/json")
147 .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
148 wireMockServer.stubFor(delete(
149 urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
150 .willReturn(aResponse().withHeader("Content-Type", "application/json")
151 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
152 MsoRequest msoRequest = getMsoRequest();
153 msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12",
154 msoRequest, new Holder<Map<String, String>>());
157 private MsoRequest getMsoRequest() {
158 MsoRequest msoRequest = new MsoRequest();
159 msoRequest.setRequestId("12345");
160 msoRequest.setServiceInstanceId("12345");