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