replace all fixed wiremock ports
[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
33 import java.io.BufferedReader;
34 import java.io.FileReader;
35 import java.io.IOException;
36
37 import org.apache.http.HttpStatus;
38
39 import com.github.tomakehurst.wiremock.WireMockServer;
40
41 public class StubOpenStack {
42         private static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0";
43         private static final String NETWORK_ID = "da886914-efb2-4917-b335-c8381528d90b";
44         private static final String NETWORK_NAME_2 = "stackname";
45         private static final String NETWORK_ID_2 = "stackId";
46         
47         public static void mockOpenStackResponseAccess(WireMockServer wireMockServer, int port) throws IOException {
48                 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json")
49                         .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl"))
50                                 .withStatus(HttpStatus.SC_OK)));
51         }
52
53         public static void mockOpenStackResponseAccessMulticloud(WireMockServer wireMockServer, int port) throws IOException {
54                 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).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) throws IOException {
60                 wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens"))
61                                 .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")).willReturn(aResponse().withHeader("Content-Type", "application/json")
69                                 .withBody(getBodyFromFile("OpenstackResponse_Access_Admin.json", port, "/mockPublicUrl"))
70                                         .withStatus(HttpStatus.SC_OK)));
71         }
72         
73         public static void mockOpenStackPublicUrlStackByName_200(WireMockServer wireMockServer, int port) throws IOException {
74                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME)).willReturn(aResponse()
75                         .withHeader("X-Openstack-Request-Id", "openstackRquest")
76                                 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME)
77                                         .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME))
78                                                 .withStatus(HttpStatus.SC_OK)));
79         }
80         
81         public static void mockOpenStackPublicUrlStackByID_200(WireMockServer wireMockServer, int port) throws IOException {
82                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_ID)).willReturn(aResponse()
83                         .withHeader("X-Openstack-Request-Id", "openstackRquest")
84                                 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME)
85                                         .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME))
86                                                 .withStatus(HttpStatus.SC_OK)));
87         }
88         
89         public static void mockOpenStackGetPublicUrlStackByNameAndID_200(WireMockServer wireMockServer, int port) throws IOException {
90                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse()
91                         .withHeader("X-Openstack-Request-Id", "openstackRquest")
92                                 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME)
93                                         .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME))
94                                                 .withStatus(HttpStatus.SC_OK)));
95         }
96         
97         public static void mockOpenStackGetPublicUrlStackByNameAndID_204(WireMockServer wireMockServer, int port) throws IOException {
98                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse()
99                         .withHeader("X-Openstack-Request-Id", "openstackRquest")
100                                 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)
101                                         .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME))
102                                                 .withStatus(HttpStatus.SC_NOT_FOUND)));
103         }
104         
105         public static void mockOpenStackPutPublicUrlStackByNameAndID_200(WireMockServer wireMockServer) {
106                 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse()
107                         .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
108         }
109
110         public static void mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(WireMockServer wireMockServer) {
111                 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME_2+"/"+NETWORK_ID_2)).willReturn(aResponse()
112                                 .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
113         }
114         
115         public static void mockOpenStackDeletePublicUrlStackByNameAndID_204(WireMockServer wireMockServer) {
116                 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse()
117                         .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NO_CONTENT)));
118         }
119         
120         public static void mockOpenStackPostPublicUrlWithBodyFile_200(WireMockServer wireMockServer) {
121                 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks"))
122                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
123                                 .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK)));
124         }
125         
126         public static void mockOpenStackGetStackCreatedAppC_200(WireMockServer wireMockServer) {
127                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3/stackId"))
128                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
129                                 .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK)));
130         }
131         
132         public static void mockOpenStackGetStackAppC_404(WireMockServer wireMockServer) {
133                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3"))
134                         .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
135         }
136         
137         public static void mockOpenStackGetStackCreatedVUSP_200(WireMockServer wireMockServer) {
138                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/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 mockOpenStackGetStackVUSP_404(WireMockServer wireMockServer) {
144                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"))
145                         .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
146         }
147         
148         public static void mockOpenStackPostStack_200(WireMockServer wireMockServer, String filename) {
149                 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse()
150                                 .withHeader("Content-Type", "application/json")
151                                 .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
152         }
153
154         public static void mockOpenStackPostNeutronNetwork_200(WireMockServer wireMockServer, String filename) {
155                 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
156                                 .withHeader("Content-Type", "application/json")
157                                 .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
158         }
159
160         public static void mockOpenStackPutNeutronNetwork_200(WireMockServer wireMockServer, String filename,String networkId) {
161                 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse()
162                                 .withHeader("Content-Type", "application/json")
163                                 .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
164         }
165
166         public static void mockOpenStackPutNeutronNetwork(WireMockServer wireMockServer, String networkId, int responseCode) {
167                 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse()
168                                 .withHeader("Content-Type", "application/json")
169                                 .withStatus(responseCode)));
170         }
171
172         public static void mockOpenStackGetAllNeutronNetworks_200(WireMockServer wireMockServer, String filename){
173                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
174                                 .withHeader("Content-Type", "application/json")
175                                 .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
176         }
177         
178         public static void mockOpenStackGetNeutronNetwork_404(WireMockServer wireMockServer, String networkName) {
179                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkName)).willReturn(aResponse()
180                                 .withHeader("Content-Type", "application/json")
181                                 .withStatus(HttpStatus.SC_NOT_FOUND)));
182         }
183
184         public static void mockOpenStackGetAllNeutronNetworks_404(WireMockServer wireMockServer) {
185                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
186                                 .withHeader("Content-Type", "application/json")
187                                 .withStatus(HttpStatus.SC_NOT_FOUND)));
188         }
189
190         public static void mockOpenstackGetWithResponse(WireMockServer wireMockServer, String url,int responseCode, String responseFile) {
191                 wireMockServer.stubFor(get(urlPathEqualTo(url)).willReturn(aResponse()
192                                 .withHeader("Content-Type", "application/json")
193                                 .withBodyFile(responseFile)
194                                 .withStatus(responseCode)));
195         }
196         
197         public static void mockOpenstackPostWithResponse(WireMockServer wireMockServer, String url,int responseCode, String responseFile) {
198                 wireMockServer.stubFor(post(urlPathEqualTo(url)).willReturn(aResponse()
199                                 .withHeader("Content-Type", "application/json")
200                                 .withBodyFile(responseFile)
201                                 .withStatus(responseCode)));
202         }
203
204         public static void mockOpenstackGet(WireMockServer wireMockServer, String url,int responseCode) {
205                 wireMockServer.stubFor(get(urlPathEqualTo(url)).willReturn(aResponse()
206                                 .withHeader("Content-Type", "application/json")
207                                 .withStatus(responseCode)));
208         }
209
210         public static void mockOpenstackPost(WireMockServer wireMockServer, String url,int responseCode) {
211                 wireMockServer.stubFor(post(urlPathEqualTo(url)).willReturn(aResponse()
212                                 .withHeader("Content-Type", "application/json")
213                                 .withStatus(responseCode)));
214         }
215
216         public static void mockOpenStackGetStackVfModule_200(WireMockServer wireMockServer) {
217                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
218                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
219                                 .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
220                                         .withStatus(HttpStatus.SC_OK)));
221         }
222         
223         public static void mockOpenStackGetStackVfModule_404(WireMockServer wireMockServer) {
224                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
225                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
226                                 .withStatus(HttpStatus.SC_NOT_FOUND)));
227         }
228         
229         public static void mockOpenStackPostStacks_200(WireMockServer wireMockServer) {
230                 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks"))
231                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
232                                 .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK)));
233         }
234         
235         public static void mockOpenStackGetStacks_404(WireMockServer wireMockServer) {
236                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/3d7ff7b4-720b-4604-be0a-1974fc58ed96"))
237                         .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
238         }
239         
240         public static void mockOpenStackGetStacksWithBody_200(WireMockServer wireMockServer, String replaceWith) throws IOException {
241                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
242                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
243                                 .withBody(getBodyFromFileVnfAdapter(replaceWith))
244                                         .withStatus(HttpStatus.SC_OK)));
245         }
246
247         public static void mockOpenStackGetStackWithBody_200(WireMockServer wireMockServer, String replaceWith) throws IOException {
248                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
249                                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
250                                                 .withBody(getBodyFromFileVnfAdapter(replaceWith))
251                                                 .withStatus(HttpStatus.SC_OK)));
252         }
253         
254         public static void mockOpenStackGetStacksWithBody_404(WireMockServer wireMockServer) throws IOException {
255                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
256                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
257                                 .withBody(getBodyFromFileVnfAdapter(null))
258                                         .withStatus(HttpStatus.SC_NOT_FOUND)));
259         }
260         
261         public static void mockOpenStackGetStacksStackId_404(WireMockServer wireMockServer) {
262                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/stackId"))
263                         .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
264         }
265         
266         public static void mockOpenStackGetStacksVfModule_200(WireMockServer wireMockServer, int port) throws IOException {
267                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse()
268                         .withHeader("X-Openstack-Request-Id", "openstackRquest")
269                                 .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK)));
270         }
271         
272         public static void mockOpenStackGetStacksVfModuleWithLocationHeader_200(WireMockServer wireMockServer, int port) throws IOException {
273                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse()
274                         .withHeader("X-Openstack-Request-Id", "openstackRquest")
275                                 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")
276                                         .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK)));
277         }
278         
279         public static void mockOpenStackGetStacksBaseStack_200(WireMockServer wireMockServer, int port) throws IOException {
280                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfModuleStackId")).willReturn(aResponse()
281                         .withHeader("X-Openstack-Request-Id", "openstackRquest")
282                                 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/baseVfModuleStackId")
283                                         .withBody(getBodyFromFile("OpenstackResponse_VnfBaseStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK)));
284         }
285         
286         public static void mockOpenStackPutStacks_200(WireMockServer wireMockServer) {
287                 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse()
288                         .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
289         }
290
291         public static void mockOpenStackPutStack(WireMockServer wireMockServer, String networkId,int responseCode) {
292                 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+networkId))
293                                 .willReturn(aResponse()
294                                 .withHeader("Content-Type", "application/json")
295                                 .withStatus(responseCode)));
296         }
297         
298         public static void mockOpenStackGetStacksStackId_200(WireMockServer wireMockServer, int port) throws IOException {
299                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/StackId")).willReturn(aResponse()
300                         .withHeader("X-Openstack-Request-Id", "openstackRquest")
301                                 .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/stackId")
302                                         .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK)));
303         }
304         
305         public static void mockOpenStackDeleteStacks(WireMockServer wireMockServer) {
306                 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b"))
307                         .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")));
308         }
309         
310         public static void mockOpenStackGetStacksVUSP_404(WireMockServer wireMockServer) {
311                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b"))
312                         .willReturn(aResponse()
313                                 .withHeader("X-Openstack-Request-Id", "openstackRquest")
314                                         .withStatus(HttpStatus.SC_NOT_FOUND)));
315         }
316         
317         public static void mockOpenStackGetStackCreated_200(WireMockServer wireMockServer, String filename, String networkName) {
318                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName))
319                                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
320                                                 .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
321         }
322
323         public static void mockOpenStackGetStack_404(WireMockServer wireMockServer, String networkName) {
324                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName))
325                                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
326                                                 .withStatus(HttpStatus.SC_NOT_FOUND)));
327         }
328
329         public static void mockOpenStackGetStack_500(WireMockServer wireMockServer, String networkName) {
330                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName))
331                                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
332                                                 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
333         }
334
335         public static void mockOpenStackGetStackDeleteOrUpdateComplete_200(WireMockServer wireMockServer, String filename) {
336                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
337                                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
338                                                 .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
339         }
340
341         public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String filename,String networkId,int status) {
342                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId))
343                                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
344                                                 .withBodyFile(filename).withStatus(status)));
345         }
346
347         public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String networkId,int status) {
348                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId))
349                                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
350                                                 .withStatus(status)));
351         }
352         
353         public static void mockOpenStackDeleteStack_200(WireMockServer wireMockServer) {
354                 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
355                                 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
356         }
357
358         public static void mockOpenStackDeleteStack_500(WireMockServer wireMockServer) {
359                 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
360                                 .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
361         }
362
363         public static void mockOpenStackDeleteNeutronNetwork(WireMockServer wireMockServer, String networkId,int responseCode) {
364                 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
365                                 .willReturn(aResponse().withStatus(responseCode)));
366         }
367         
368         public static void mockOpenStackPostMetadata_200(WireMockServer wireMockServer) {
369                 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata")).willReturn(aResponse()
370                                 .withHeader("Content-Type", "application/json")
371                                                 .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK)));
372         }
373         
374         public static void mockOpenStackGetMetadata_200(WireMockServer wireMockServer) {
375                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata")).willReturn(aResponse()
376                                 .withHeader("Content-Type", "application/json")
377                                                 .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK)));
378         }
379         
380         public static void mockOpenStackPostTenantWithBodyFile_200(WireMockServer wireMockServer) throws IOException {
381                 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants"))
382                                 .withRequestBody(equalToJson(readFile("src/test/resources/__files/OpenstackRequest_Tenant.json"))).willReturn(aResponse()
383                                 .withHeader("Content-Type", "application/json")
384                                                 .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
385         }
386         
387         public static void mockOpenStackPostTenant_200(WireMockServer wireMockServer) throws IOException {
388                 wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants")).willReturn(aResponse()
389                                 .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
390         }
391         
392         public static void mockOpenStackGetTenantByName_200(WireMockServer wireMockServer, String tenantName) {
393                 wireMockServer.stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)).willReturn(aResponse()
394                                 .withHeader("Content-Type", "application/json")
395                                                 .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
396         }
397         
398         public static void mockOpenStackGetTenantByName_404(WireMockServer wireMockServer, String tenantName) {
399                 wireMockServer.stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)).willReturn(aResponse()
400                                 .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
401         }
402         
403         public static void mockOpenStackGetTenantById_200(WireMockServer wireMockServer, String tenantId) {
404                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse()
405                                 .withHeader("Content-Type", "application/json")
406                                                 .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
407         }
408         
409         public static void mockOpenStackGetTenantById_404(WireMockServer wireMockServer, String tenantId) {
410                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse()
411                                 .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
412         }
413         
414         public static void mockOpenStackDeleteTenantById_200(WireMockServer wireMockServer, String tenantId) {
415                 wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse()
416                                 .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
417         }
418         
419         public static void mockOpenStackGetUser_200(WireMockServer wireMockServer, String user) {
420                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)).willReturn(aResponse()
421                                 .withHeader("Content-Type", "application/json")
422                                                 .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK)));
423         }
424         
425         public static void mockOpenStackGetRoles_200(WireMockServer wireMockServer, String roleFor) {
426                 wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")).willReturn(aResponse()
427                                 .withHeader("Content-Type", "application/json")
428                                                 .withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK)));
429         }
430         
431         public static void mockOpenStackPutRolesAdmin_200(WireMockServer wireMockServer, String roleFor) {
432                 wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/users/msoId/roles/" + roleFor + "/admin")).willReturn(aResponse()
433                                 .withHeader("Content-Type", "application/json")
434                                                 .withBody("").withStatus(HttpStatus.SC_OK)));
435         }
436         
437         public static void mockValetCreatePostResponse_200(WireMockServer wireMockServer, String requestId, String body) {
438                 wireMockServer.stubFor(post(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId))
439                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
440                                 .withBody(body).withStatus(HttpStatus.SC_OK)));
441         }
442         
443         public static void mockValetCreatePutResponse_200(WireMockServer wireMockServer, String requestId, String body) {
444                 wireMockServer.stubFor(put(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId))
445               .willReturn(aResponse().withHeader("Content-Type", "application/json")
446                           .withBody(body).withStatus(HttpStatus.SC_OK)));
447         }
448         
449         public static void mockValetDeleteDeleteResponse_200(WireMockServer wireMockServer, String requestId, String body) {
450                 wireMockServer.stubFor(delete(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId))
451                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
452                                 .withBody(body).withStatus(HttpStatus.SC_OK)));
453         }
454         
455         public static void mockValetConfirmPutRequest_200(WireMockServer wireMockServer, String requestId, String body) {
456                 wireMockServer.stubFor(put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/confirm/"))
457                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
458                                 .withBody(body).withStatus(HttpStatus.SC_OK)));
459         }
460         
461         public static void mockValetRollbackPutRequest_200(WireMockServer wireMockServer, String requestId, String body) {
462                 wireMockServer.stubFor(put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/rollback/"))
463                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
464                                 .withBody(body).withStatus(HttpStatus.SC_OK)));
465         }
466         
467         private static String getBodyFromFileVnfAdapter(String replaceWith) throws IOException {
468                 String temp = readFile("src/test/resources/__files/OpenstackResponse_Stack_Created_VfModule.json");
469                 if (replaceWith == null) {
470                         return temp;
471                 }
472                 return temp.replaceAll("CREATE_COMPLETE", replaceWith);
473         }
474         
475         private static String readFile(String fileName) throws IOException {
476                 try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
477                         StringBuilder sb = new StringBuilder();
478                         String line = br.readLine();
479
480                         while (line != null) {
481                                 sb.append(line);
482                                 sb.append("\n");
483                                 line = br.readLine();
484                         }
485                         return sb.toString();
486                 }
487         }
488         
489         public static String getBodyFromFile(String fileName, int port, String urlPath) throws IOException {
490                 return readFile("src/test/resources/__files/" + fileName).replaceAll("port", "http://localhost:" + port + urlPath);
491         }
492 }