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.bpmn.mock;
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.delete;
26 import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
27 import static com.github.tomakehurst.wiremock.client.WireMock.get;
28 import static com.github.tomakehurst.wiremock.client.WireMock.post;
29 import static com.github.tomakehurst.wiremock.client.WireMock.put;
30 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
31 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
32 import java.io.BufferedReader;
33 import java.io.FileReader;
34 import java.io.IOException;
35 import org.apache.http.HttpStatus;
36 import com.github.tomakehurst.wiremock.WireMockServer;
38 public class StubOpenStack {
39 private static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0";
40 private static final String NETWORK_ID = "da886914-efb2-4917-b335-c8381528d90b";
41 private static final String NETWORK_NAME_2 = "stackname";
42 private static final String NETWORK_ID_2 = "stackId";
44 public static void mockOpenStackResponseAccess(WireMockServer wireMockServer, int port) throws IOException {
45 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens"))
46 .willReturn(aResponse().withHeader("Content-Type", "application/json")
47 .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl"))
48 .withStatus(HttpStatus.SC_OK)));
51 public static void mockOpenStackResponseAccessMulticloud(WireMockServer wireMockServer, int port)
53 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens"))
54 .willReturn(aResponse().withHeader("Content-Type", "application/json")
55 .withBody(getBodyFromFile("OpenstackResponse_AccessMulticloud.json", port, "/mockPublicUrl"))
56 .withStatus(HttpStatus.SC_OK)));
59 public static void mockOpenStackResponseAccessQueryNetwork(WireMockServer wireMockServer, int port)
61 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId"))
62 .willReturn(aResponse().withHeader("Content-Type", "application/json")
63 .withBody(getBodyFromFile("OpenstackResponse_Access_queryNetwork.json", port, "/mockPublicUrl"))
64 .withStatus(HttpStatus.SC_OK)));
67 public static void mockOpenStackResponseAccessAdmin(WireMockServer wireMockServer, int port) throws IOException {
68 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens"))
69 .willReturn(aResponse().withHeader("Content-Type", "application/json")
70 .withBody(getBodyFromFile("OpenstackResponse_Access_Admin.json", port, "/mockPublicUrl"))
71 .withStatus(HttpStatus.SC_OK)));
74 public static void mockOpenStackPublicUrlStackByName_200(WireMockServer wireMockServer, int port)
76 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME))
77 .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")
78 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/" + NETWORK_NAME)
79 .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port,
80 "/mockPublicUrl/stacks/" + NETWORK_NAME))
81 .withStatus(HttpStatus.SC_OK)));
84 public static void mockOpenStackPublicUrlStackByID_200(WireMockServer wireMockServer, int port) throws IOException {
85 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_ID))
86 .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")
87 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/" + NETWORK_NAME)
88 .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port,
89 "/mockPublicUrl/stacks/" + NETWORK_NAME))
90 .withStatus(HttpStatus.SC_OK)));
93 public static void mockOpenStackGetPublicUrlStackByNameAndID_200(WireMockServer wireMockServer, int port)
95 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID))
96 .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")
97 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/" + NETWORK_NAME)
98 .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port,
99 "/mockPublicUrl/stacks/" + NETWORK_NAME))
100 .withStatus(HttpStatus.SC_OK)));
103 public static void mockOpenStackGetPublicUrlStackByNameAndID_204(WireMockServer wireMockServer, int port)
105 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID))
106 .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")
107 .withHeader("location",
108 "http://localhost:" + port + "/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID)
109 .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port,
110 "/mockPublicUrl/stacks/" + NETWORK_NAME))
111 .withStatus(HttpStatus.SC_NOT_FOUND)));
114 public static void mockOpenStackPutPublicUrlStackByNameAndID_200(WireMockServer wireMockServer) {
115 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID))
116 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
119 public static void mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(WireMockServer wireMockServer) {
120 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
121 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
124 public static void mockOpenStackDeletePublicUrlStackByNameAndID_204(WireMockServer wireMockServer) {
125 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID))
126 .willReturn(aResponse().withHeader("Content-Type", "application/json")
127 .withStatus(HttpStatus.SC_NO_CONTENT)));
130 public static void mockOpenStackPostPublicUrlWithBodyFile_200(WireMockServer wireMockServer) {
131 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks"))
132 .willReturn(aResponse().withHeader("Content-Type", "application/json")
133 .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK)));
136 public static void mockOpenStackGetStackCreatedAppC_200(WireMockServer wireMockServer) {
137 wireMockServer.stubFor(
138 get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3/stackId"))
139 .willReturn(aResponse().withHeader("Content-Type", "application/json")
140 .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK)));
143 public static void mockOpenStackGetStackAppC_404(WireMockServer wireMockServer) {
145 .stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3"))
146 .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
149 public static void mockOpenStackGetStackCreatedVUSP_200(WireMockServer wireMockServer) {
150 wireMockServer.stubFor(
151 get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/stackId"))
152 .willReturn(aResponse().withHeader("Content-Type", "application/json")
153 .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK)));
156 public static void mockOpenStackGetStackVUSP_404(WireMockServer wireMockServer) {
158 .stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"))
159 .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
162 public static void mockOpenStackPostStack_200(WireMockServer wireMockServer, String filename) {
163 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse()
164 .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
167 public static void mockOpenStackPostNeutronNetwork_200(WireMockServer wireMockServer, String filename) {
168 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
169 .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
172 public static void mockOpenStackPutNeutronNetwork_200(WireMockServer wireMockServer, String filename,
174 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)).willReturn(aResponse()
175 .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
178 public static void mockOpenStackPutNeutronNetwork(WireMockServer wireMockServer, String networkId,
180 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
181 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode)));
184 public static void mockOpenStackGetAllNeutronNetworks_200(WireMockServer wireMockServer, String filename) {
185 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
186 .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
189 public static void mockOpenStackGetNeutronNetwork_404(WireMockServer wireMockServer, String networkName) {
190 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkName)).willReturn(
191 aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
194 public static void mockOpenStackGetAllNeutronNetworks_404(WireMockServer wireMockServer) {
195 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(
196 aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
199 public static void mockOpenstackGetWithResponse(WireMockServer wireMockServer, String url, int responseCode,
200 String responseFile) {
201 wireMockServer.stubFor(get(urlPathEqualTo(url)).willReturn(aResponse()
202 .withHeader("Content-Type", "application/json").withBodyFile(responseFile).withStatus(responseCode)));
205 public static void mockOpenstackPostWithResponse(WireMockServer wireMockServer, String url, int responseCode,
206 String responseFile) {
207 wireMockServer.stubFor(post(urlPathEqualTo(url)).willReturn(aResponse()
208 .withHeader("Content-Type", "application/json").withBodyFile(responseFile).withStatus(responseCode)));
211 public static void mockOpenstackGet(WireMockServer wireMockServer, String url, int responseCode) {
212 wireMockServer.stubFor(get(urlPathEqualTo(url))
213 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode)));
216 public static void mockOpenstackPost(WireMockServer wireMockServer, String url, int responseCode) {
217 wireMockServer.stubFor(post(urlPathEqualTo(url))
218 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode)));
221 public static void mockOpenStackGetStackVfModule_200(WireMockServer wireMockServer) {
222 wireMockServer.stubFor(get(
223 urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
224 .willReturn(aResponse().withHeader("Content-Type", "application/json")
225 .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
226 .withStatus(HttpStatus.SC_OK)));
229 public static void mockOpenStackGetStackVfModule_404(WireMockServer wireMockServer) {
230 wireMockServer.stubFor(
231 get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
232 .willReturn(aResponse().withHeader("Content-Type", "application/json")
233 .withStatus(HttpStatus.SC_NOT_FOUND)));
236 public static void mockOpenStackPostStacks_200(WireMockServer wireMockServer) {
237 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks"))
238 .willReturn(aResponse().withHeader("Content-Type", "application/json")
239 .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK)));
242 public static void mockOpenStackGetStacks_404(WireMockServer wireMockServer) {
243 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/3d7ff7b4-720b-4604-be0a-1974fc58ed96"))
244 .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
247 public static void mockOpenStackGetStacksWithBody_200(WireMockServer wireMockServer, String replaceWith)
249 wireMockServer.stubFor(
250 get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
251 .willReturn(aResponse().withHeader("Content-Type", "application/json")
252 .withBody(getBodyFromFileVnfAdapter(replaceWith)).withStatus(HttpStatus.SC_OK)));
255 public static void mockOpenStackGetStackWithBody_200(WireMockServer wireMockServer, String replaceWith)
257 wireMockServer.stubFor(get(
258 urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
259 .willReturn(aResponse().withHeader("Content-Type", "application/json")
260 .withBody(getBodyFromFileVnfAdapter(replaceWith)).withStatus(HttpStatus.SC_OK)));
263 public static void mockOpenStackGetStacksWithBody_404(WireMockServer wireMockServer) throws IOException {
264 wireMockServer.stubFor(
265 get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
266 .willReturn(aResponse().withHeader("Content-Type", "application/json")
267 .withBody(getBodyFromFileVnfAdapter(null)).withStatus(HttpStatus.SC_NOT_FOUND)));
270 public static void mockOpenStackGetStacksStackId_404(WireMockServer wireMockServer) {
271 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/stackId"))
272 .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
275 public static void mockOpenStackGetStacksVfModule_200(WireMockServer wireMockServer, int port) throws IOException {
276 wireMockServer.stubFor(get(urlPathEqualTo(
277 "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
278 .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")
279 .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port,
280 "/mockPublicUrl/stacks/stackId"))
281 .withStatus(HttpStatus.SC_OK)));
284 public static void mockOpenStackGetStacksVfModuleWithLocationHeader_200(WireMockServer wireMockServer, int port)
286 wireMockServer.stubFor(
287 get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
288 .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")
289 .withHeader("location", "http://localhost:" + port
290 + "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")
291 .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port,
292 "/mockPublicUrl/stacks/stackId"))
293 .withStatus(HttpStatus.SC_OK)));
296 public static void mockOpenStackGetStacksBaseStack_200(WireMockServer wireMockServer, int port) throws IOException {
297 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfModuleStackId")).willReturn(aResponse()
298 .withHeader("X-Openstack-Request-Id", "openstackRquest")
299 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/baseVfModuleStackId")
301 getBodyFromFile("OpenstackResponse_VnfBaseStackId.json", port, "/mockPublicUrl/stacks/stackId"))
302 .withStatus(HttpStatus.SC_OK)));
305 public static void mockOpenStackPutStacks_200(WireMockServer wireMockServer) {
306 wireMockServer.stubFor(put(urlPathEqualTo(
307 "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
308 .willReturn(aResponse().withHeader("Content-Type", "application/json")
309 .withStatus(HttpStatus.SC_OK)));
312 public static void mockOpenStackPutStack(WireMockServer wireMockServer, String networkId, int responseCode) {
313 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/" + networkId))
314 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode)));
317 public static void mockOpenStackGetStacksStackId_200(WireMockServer wireMockServer, int port) throws IOException {
318 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/StackId")).willReturn(aResponse()
319 .withHeader("X-Openstack-Request-Id", "openstackRquest")
320 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/stackId")
321 .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/stackId"))
322 .withStatus(HttpStatus.SC_OK)));
325 public static void mockOpenStackDeleteStacks(WireMockServer wireMockServer) {
326 wireMockServer.stubFor(delete(urlPathEqualTo(
327 "/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b"))
328 .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")));
331 public static void mockOpenStackGetStacksVUSP_404(WireMockServer wireMockServer) {
332 wireMockServer.stubFor(get(urlPathEqualTo(
333 "/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b"))
334 .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")
335 .withStatus(HttpStatus.SC_NOT_FOUND)));
338 public static void mockOpenStackGetStackCreated_200(WireMockServer wireMockServer, String filename,
339 String networkName) {
340 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)).willReturn(aResponse()
341 .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
344 public static void mockOpenStackGetStack_404(WireMockServer wireMockServer, String networkName) {
345 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)).willReturn(
346 aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
349 public static void mockOpenStackGetStack_500(WireMockServer wireMockServer, String networkName) {
350 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)).willReturn(aResponse()
351 .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
354 public static void mockOpenStackGetStackDeleteOrUpdateComplete_200(WireMockServer wireMockServer, String filename) {
355 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
356 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile(filename)
357 .withStatus(HttpStatus.SC_OK)));
360 public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String filename, String networkId,
362 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)).willReturn(
363 aResponse().withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(status)));
366 public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String networkId, int status) {
367 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
368 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(status)));
371 public static void mockOpenStackDeleteStack_200(WireMockServer wireMockServer) {
372 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
373 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
376 public static void mockOpenStackDeleteStack_500(WireMockServer wireMockServer) {
377 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
378 .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
381 public static void mockOpenStackDeleteNeutronNetwork(WireMockServer wireMockServer, String networkId,
383 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
384 .willReturn(aResponse().withStatus(responseCode)));
387 public static void mockOpenStackPostMetadata_200(WireMockServer wireMockServer) {
388 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata"))
389 .willReturn(aResponse().withHeader("Content-Type", "application/json")
390 .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK)));
393 public static void mockOpenStackGetMetadata_200(WireMockServer wireMockServer) {
394 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata"))
395 .willReturn(aResponse().withHeader("Content-Type", "application/json")
396 .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK)));
399 public static void mockOpenStackPostTenantWithBodyFile_200(WireMockServer wireMockServer) throws IOException {
400 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants"))
401 .withRequestBody(equalToJson(readFile("src/test/resources/__files/OpenstackRequest_Tenant.json")))
402 .willReturn(aResponse().withHeader("Content-Type", "application/json")
403 .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
406 public static void mockOpenStackPostTenant_200(WireMockServer wireMockServer) throws IOException {
407 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants"))
408 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
411 public static void mockOpenStackGetTenantByName_200(WireMockServer wireMockServer, String tenantName) {
412 wireMockServer.stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName))
413 .willReturn(aResponse().withHeader("Content-Type", "application/json")
414 .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
417 public static void mockOpenStackGetTenantByName_404(WireMockServer wireMockServer, String tenantName) {
418 wireMockServer.stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)).willReturn(
419 aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
422 public static void mockOpenStackGetTenantById_200(WireMockServer wireMockServer, String tenantId) {
423 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId))
424 .willReturn(aResponse().withHeader("Content-Type", "application/json")
425 .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
428 public static void mockOpenStackGetTenantById_404(WireMockServer wireMockServer, String tenantId) {
429 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(
430 aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
433 public static void mockOpenStackDeleteTenantById_200(WireMockServer wireMockServer, String tenantId) {
434 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId))
435 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
438 public static void mockOpenStackGetUser_200(WireMockServer wireMockServer, String user) {
439 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user))
440 .willReturn(aResponse().withHeader("Content-Type", "application/json")
441 .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK)));
444 public static void mockOpenStackGetRoles_200(WireMockServer wireMockServer, String roleFor) {
445 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles"))
446 .willReturn(aResponse().withHeader("Content-Type", "application/json")
447 .withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK)));
450 public static void mockOpenStackPutRolesAdmin_200(WireMockServer wireMockServer, String roleFor) {
452 .stubFor(put(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/users/msoId/roles/" + roleFor + "/admin"))
453 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("")
454 .withStatus(HttpStatus.SC_OK)));
457 public static void mockValetCreatePostResponse_200(WireMockServer wireMockServer, String requestId, String body) {
459 .stubFor(post(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)).willReturn(aResponse()
460 .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK)));
463 public static void mockValetCreatePutResponse_200(WireMockServer wireMockServer, String requestId, String body) {
464 wireMockServer.stubFor(put(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)).willReturn(aResponse()
465 .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK)));
468 public static void mockValetDeleteDeleteResponse_200(WireMockServer wireMockServer, String requestId, String body) {
470 .stubFor(delete(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)).willReturn(aResponse()
471 .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK)));
474 public static void mockValetConfirmPutRequest_200(WireMockServer wireMockServer, String requestId, String body) {
475 wireMockServer.stubFor(
476 put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/confirm/")).willReturn(aResponse()
477 .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK)));
480 public static void mockValetRollbackPutRequest_200(WireMockServer wireMockServer, String requestId, String body) {
481 wireMockServer.stubFor(
482 put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/rollback/")).willReturn(aResponse()
483 .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK)));
486 private static String getBodyFromFileVnfAdapter(String replaceWith) throws IOException {
487 String temp = readFile("src/test/resources/__files/OpenstackResponse_Stack_Created_VfModule.json");
488 if (replaceWith == null) {
491 return temp.replaceAll("CREATE_COMPLETE", replaceWith);
494 private static String readFile(String fileName) throws IOException {
495 try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
496 StringBuilder sb = new StringBuilder();
497 String line = br.readLine();
499 while (line != null) {
502 line = br.readLine();
504 return sb.toString();
508 public static String getBodyFromFile(String fileName, int port, String urlPath) throws IOException {
509 return readFile("src/test/resources/__files/" + fileName).replaceAll("port",
510 "http://localhost:" + port + urlPath);