Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / bpmn / mock / StubOpenStack.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.mock;
22
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;
37
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";
43
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)));
49     }
50
51     public static void mockOpenStackResponseAccessMulticloud(WireMockServer wireMockServer, int port)
52             throws IOException {
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)));
57     }
58
59     public static void mockOpenStackResponseAccessQueryNetwork(WireMockServer wireMockServer, int port)
60             throws IOException {
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)));
65     }
66
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)));
72     }
73
74     public static void mockOpenStackPublicUrlStackByName_200(WireMockServer wireMockServer, int port)
75             throws IOException {
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)));
82     }
83
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)));
91     }
92
93     public static void mockOpenStackGetPublicUrlStackByNameAndID_200(WireMockServer wireMockServer, int port)
94             throws IOException {
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)));
101     }
102
103     public static void mockOpenStackGetPublicUrlStackByNameAndID_204(WireMockServer wireMockServer, int port)
104             throws IOException {
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)));
112     }
113
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)));
117     }
118
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)));
122     }
123
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)));
128     }
129
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)));
134     }
135
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)));
141     }
142
143     public static void mockOpenStackGetStackAppC_404(WireMockServer wireMockServer) {
144         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)));
147     }
148
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)));
154     }
155
156     public static void mockOpenStackGetStackVUSP_404(WireMockServer wireMockServer) {
157         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)));
160     }
161
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)));
165     }
166
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)));
170     }
171
172     public static void mockOpenStackPutNeutronNetwork_200(WireMockServer wireMockServer, String filename,
173             String networkId) {
174         wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)).willReturn(aResponse()
175                 .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
176     }
177
178     public static void mockOpenStackPutNeutronNetwork(WireMockServer wireMockServer, String networkId,
179             int responseCode) {
180         wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
181                 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode)));
182     }
183
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)));
187     }
188
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)));
192     }
193
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)));
197     }
198
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)));
203     }
204
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)));
209     }
210
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)));
214     }
215
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)));
219     }
220
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)));
227     }
228
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)));
234     }
235
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)));
240     }
241
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)));
245     }
246
247     public static void mockOpenStackGetStacksWithBody_200(WireMockServer wireMockServer, String replaceWith)
248             throws IOException {
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)));
253     }
254
255     public static void mockOpenStackGetStackWithBody_200(WireMockServer wireMockServer, String replaceWith)
256             throws IOException {
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)));
261     }
262
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)));
268     }
269
270     public static void mockOpenStackGetStacksStackId_404(WireMockServer wireMockServer) {
271         wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/stackId"))
272                 .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
273     }
274
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)));
282     }
283
284     public static void mockOpenStackGetStacksVfModuleWithLocationHeader_200(WireMockServer wireMockServer, int port)
285             throws IOException {
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)));
294     }
295
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")
300                 .withBody(
301                         getBodyFromFile("OpenstackResponse_VnfBaseStackId.json", port, "/mockPublicUrl/stacks/stackId"))
302                 .withStatus(HttpStatus.SC_OK)));
303     }
304
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)));
310     }
311
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)));
315     }
316
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)));
323     }
324
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")));
329     }
330
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)));
336     }
337
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)));
342     }
343
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)));
347     }
348
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)));
352     }
353
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)));
358     }
359
360     public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String filename, String networkId,
361             int status) {
362         wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)).willReturn(
363                 aResponse().withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(status)));
364     }
365
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)));
369     }
370
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)));
374     }
375
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)));
379     }
380
381     public static void mockOpenStackDeleteNeutronNetwork(WireMockServer wireMockServer, String networkId,
382             int responseCode) {
383         wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
384                 .willReturn(aResponse().withStatus(responseCode)));
385     }
386
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)));
391     }
392
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)));
397     }
398
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)));
404     }
405
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)));
409     }
410
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)));
415     }
416
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)));
420     }
421
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)));
426     }
427
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)));
431     }
432
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)));
436     }
437
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)));
442     }
443
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)));
448     }
449
450     public static void mockOpenStackPutRolesAdmin_200(WireMockServer wireMockServer, String roleFor) {
451         wireMockServer
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)));
455     }
456
457     public static void mockValetCreatePostResponse_200(WireMockServer wireMockServer, String requestId, String body) {
458         wireMockServer
459                 .stubFor(post(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)).willReturn(aResponse()
460                         .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK)));
461     }
462
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)));
466     }
467
468     public static void mockValetDeleteDeleteResponse_200(WireMockServer wireMockServer, String requestId, String body) {
469         wireMockServer
470                 .stubFor(delete(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)).willReturn(aResponse()
471                         .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK)));
472     }
473
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)));
478     }
479
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)));
484     }
485
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) {
489             return temp;
490         }
491         return temp.replaceAll("CREATE_COMPLETE", replaceWith);
492     }
493
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();
498
499             while (line != null) {
500                 sb.append(line);
501                 sb.append("\n");
502                 line = br.readLine();
503             }
504             return sb.toString();
505         }
506     }
507
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);
511     }
512 }