2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.network;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.containing;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
27 import static org.onap.so.bpmn.mock.StubOpenStack.getBodyFromFile;
28 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackCreatedVUSP_200;
29 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackCreated_200;
30 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackDeleteOrUpdateComplete_200;
31 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostStacks_200;
32 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200;
33 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccessQueryNetwork;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import org.apache.http.HttpStatus;
38 import org.junit.Test;
39 import org.onap.so.adapters.vnf.BaseRestTestUtils;
40 import org.onap.so.entity.MsoRequest;
41 import org.onap.so.openstack.beans.NetworkRollback;
42 import org.onap.so.openstack.beans.Subnet;
43 import org.springframework.beans.factory.annotation.Autowired;
45 public class MsoNetworkAdapterAsyncImplTest extends BaseRestTestUtils {
47 MsoNetworkAdapterAsyncImpl impl;
50 public void healthCheckATest() {
51 MsoNetworkAdapterAsyncImpl mNAAimpl = new MsoNetworkAdapterAsyncImpl();
52 mNAAimpl.healthCheckA();
56 public void rollbackNetworkATest() throws IOException {
57 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
58 .willReturn(aResponse().withHeader("Content-Type", "application/json")
59 .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
60 .withStatus(HttpStatus.SC_OK)));
61 wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl"))
62 .withRequestBody(containing("<completed>true</completed>"))
63 .willReturn(aResponse().withBody(
64 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n"
65 + " <soapenv:Header/>\n" + " <soapenv:Body>\n"
66 + " <net:rollbackNetworkNotificationResponse>\n"
67 + " </net:rollbackNetworkNotificationResponse>\n" + " </soapenv:Body>\n"
68 + "</soapenv:Envelope>")
69 .withStatus(HttpStatus.SC_OK)));
70 NetworkRollback nrb = getNetworkRollback("mtn13");
71 impl.rollbackNetworkA(nrb, "messageId", "http://localhost:" + wireMockPort + "/notificationUrl");
75 public void rollbackNetworkATest_NotifyException() throws IOException {
76 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
77 .willReturn(aResponse().withHeader("Content-Type", "application/json")
78 .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
79 .withStatus(HttpStatus.SC_OK)));
80 wireMockServer.stubFor(
81 post(urlPathEqualTo("/notificationUrl")).withRequestBody(containing("<completed>true</completed>"))
82 .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
83 NetworkRollback nrb = getNetworkRollback("mtn13");
84 impl.rollbackNetworkA(nrb, "messageId", "http://localhost:" + wireMockPort + "/notificationUrl");
87 private NetworkRollback getNetworkRollback(String cloudId) {
88 NetworkRollback nrb = new NetworkRollback();
89 nrb.setCloudId(cloudId);
90 nrb.setMsoRequest(new MsoRequest());
91 nrb.setModelCustomizationUuid("3bdbb104-476c-483e-9f8b-c095b3d3068c");
92 nrb.setNetworkCreated(true);
93 nrb.setNetworkId("networkId");
94 nrb.setNetworkName("networkName");
95 nrb.setNetworkStackId("networkStackId");
96 nrb.setNetworkType("networkType");
97 nrb.setNeutronNetworkId("neutronNetworkId");
98 nrb.setPhysicalNetwork("physicalNetwork");
99 nrb.setTenantId("tenantId");
100 nrb.setVlans(new ArrayList<>());
105 public void rollbackNetworkATestNetworkException() {
106 NetworkRollback nrb = getNetworkRollback("cloudId");
108 impl.rollbackNetworkA(nrb, "messageId", "http://localhost");
112 public void noRollbackNetworkATest() {
113 impl.rollbackNetworkA(null, "messageId", "http://localhost");
118 public void deleteNetworkATest() throws IOException {
119 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
120 .willReturn(aResponse().withHeader("Content-Type", "application/json")
121 .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
122 .withStatus(HttpStatus.SC_OK)));
123 wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl"))
124 .withRequestBody(containing("<completed>true</completed>"))
125 .willReturn(aResponse().withBody(
126 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n"
127 + " <soapenv:Header/>\n" + " <soapenv:Body>\n"
128 + " <net:deleteNetworkNotificationResponse>\n"
129 + " </net:deleteNetworkNotificationResponse>\n" + " </soapenv:Body>\n"
130 + "</soapenv:Envelope>")
131 .withStatus(HttpStatus.SC_OK)));
132 impl.deleteNetworkA("mtn13", "tenantId", "networkType", "modelCustomizationUuid", "networkId", "messageId",
133 new MsoRequest(), "http://localhost:" + wireMockPort + "/notificationUrl");
137 public void deleteNetworkATest_NotifyException() throws IOException {
138 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
139 .willReturn(aResponse().withHeader("Content-Type", "application/json")
140 .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
141 .withStatus(HttpStatus.SC_OK)));
142 wireMockServer.stubFor(
143 post(urlPathEqualTo("/notificationUrl")).withRequestBody(containing("<completed>true</completed>"))
144 .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
145 impl.deleteNetworkA("mtn13", "tenantId", "networkType", "modelCustomizationUuid", "networkId", "messageId",
146 new MsoRequest(), "http://localhost:" + wireMockPort + "/notificationUrl");
150 public void deleteNetworkATest_NetworkException() {
151 impl.deleteNetworkA("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
152 "messageId", new MsoRequest(), "http://localhost:" + wireMockPort + "/notificationUrl");
156 public void updateNetworkATest() throws IOException {
157 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
158 .willReturn(aResponse().withHeader("Content-Type", "application/json")
159 .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
160 .withStatus(HttpStatus.SC_OK)));
161 mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json",
162 "dvspg-VCE_VPE-mtjnj40avbc");
163 mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_UpdateComplete.json");
164 mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(wireMockServer);
165 wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl"))
166 .withRequestBody(containing("updateNetworkNotification"))
167 .willReturn(aResponse().withBody(
168 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n"
169 + " <soapenv:Header/>\n" + " <soapenv:Body>\n"
170 + " <net:updateNetworkNotificationResponse>\n"
171 + " </net:updateNetworkNotificationResponse>\n" + " </soapenv:Body>\n"
172 + "</soapenv:Envelope>")
173 .withStatus(HttpStatus.SC_OK)));
174 HashMap<String, String> networkParams = new HashMap<String, String>();
175 networkParams.put("shared", "true");
176 networkParams.put("external", "false");
177 impl.updateNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c",
178 "dvspg-VCE_VPE-mtjnj40avbc", "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(),
179 new ArrayList<Subnet>(), networkParams, "messageId", new MsoRequest(),
180 "http://localhost:" + wireMockPort + "/notificationUrl");
184 public void updateNetworkATest_NotifyExcpetion() throws IOException {
185 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
186 .willReturn(aResponse().withHeader("Content-Type", "application/json")
187 .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
188 .withStatus(HttpStatus.SC_OK)));
189 mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json",
190 "dvspg-VCE_VPE-mtjnj40avbc");
191 mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_UpdateComplete.json");
192 mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(wireMockServer);
193 HashMap<String, String> networkParams = new HashMap<String, String>();
194 networkParams.put("shared", "true");
195 networkParams.put("external", "false");
196 impl.updateNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c",
197 "dvspg-VCE_VPE-mtjnj40avbc", "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(),
198 new ArrayList<>(), networkParams, "messageId", new MsoRequest(),
199 "http://localhost:" + wireMockPort + "/notificationUrl");
203 public void updateNetworkATest_NetworkException() {
204 impl.updateNetworkA("cloudSiteId", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c",
205 "networkId", "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), new ArrayList<>(),
206 new HashMap<String, String>(), "messageId", new MsoRequest(),
207 "http://localhost:" + wireMockPort + "/notificationUrl");
211 public void queryNetworkATest() throws IOException {
212 mockOpenStackResponseAccessQueryNetwork(wireMockServer, wireMockPort);
213 impl.queryNetworkA("mtn13", "tenantId", "networkId", "messageId", new MsoRequest(),
214 "http://localhost:" + wireMockPort + "/notificationUrl");
218 public void createNetworkATest() throws IOException {
219 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
220 .willReturn(aResponse().withHeader("Content-Type", "application/json")
221 .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
222 .withStatus(HttpStatus.SC_OK)));
223 wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl"))
224 .withRequestBody(containing("createNetworkNotification"))
225 .willReturn(aResponse().withBody(
226 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n"
227 + " <soapenv:Header/>\n" + " <soapenv:Body>\n"
228 + " <net:createNetworkNotificationResponse>\n"
229 + " </net:createNetworkNotificationResponse>\n" + " </soapenv:Body>\n"
230 + "</soapenv:Envelope>")
231 .withStatus(HttpStatus.SC_OK)));
232 mockOpenStackGetStackCreatedVUSP_200(wireMockServer);
233 mockOpenStackPostStacks_200(wireMockServer);
234 mockOpenStackPostStacks_200(wireMockServer);
235 HashMap<String, String> networkParams = new HashMap<String, String>();
236 impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c",
237 "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", "physicalNetworkName", new ArrayList<>(), false,
238 false, new ArrayList<>(), networkParams, "messageId", new MsoRequest(),
239 "http://localhost:" + wireMockPort + "/notificationUrl");
243 public void createNetworkATest_NotifyException() throws IOException {
244 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
245 .willReturn(aResponse().withHeader("Content-Type", "application/json")
246 .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
247 .withStatus(HttpStatus.SC_OK)));
248 mockOpenStackGetStackCreatedVUSP_200(wireMockServer);
249 mockOpenStackPostStacks_200(wireMockServer);
250 HashMap<String, String> networkParams = new HashMap<String, String>();
251 networkParams.put("shared", "true");
252 networkParams.put("external", "false");
253 impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c",
254 "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", "physicalNetworkName", new ArrayList<>(), false,
255 false, new ArrayList<>(), networkParams, "messageId", new MsoRequest(),
256 "http://localhost:" + wireMockPort + "/notificationUrl");
260 public void createNetworkATest_NetworkException() {
261 impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c",
262 "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", "physicalNetworkName", new ArrayList<>(), false,
263 false, new ArrayList<>(), new HashMap<String, String>(), "messageId", new MsoRequest(),
264 "http://localhost:" + wireMockPort + "/notificationUrl");