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