28797d247b832276062ee07511602b5b5125e336
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / OrchestrationRequestsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.apihandlerinfra;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.any;
25 import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
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.stubFor;
30 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
31 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
32 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertNotNull;
35
36 import java.io.File;
37 import java.io.IOException;
38 import java.nio.file.Files;
39 import java.nio.file.Paths;
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Map;
44
45 import javax.ws.rs.core.MediaType;
46 import javax.ws.rs.core.Response;
47
48 import org.apache.http.HttpStatus;
49 import org.junit.Ignore;
50 import org.junit.Test;
51 import org.onap.so.apihandler.common.ErrorNumbers;
52 import org.onap.so.db.request.beans.InfraActiveRequests;
53 import org.onap.so.db.request.client.RequestsDbClient;
54 import org.onap.so.exceptions.ValidationException;
55 import org.onap.so.serviceinstancebeans.GetOrchestrationListResponse;
56 import org.onap.so.serviceinstancebeans.GetOrchestrationResponse;
57 import org.onap.so.serviceinstancebeans.Request;
58 import org.onap.so.serviceinstancebeans.RequestError;
59 import org.onap.so.serviceinstancebeans.RequestProcessingData;
60 import org.onap.so.serviceinstancebeans.ServiceException;
61 import org.springframework.beans.factory.annotation.Autowired;
62 import org.springframework.http.HttpEntity;
63 import org.springframework.http.HttpHeaders;
64 import org.springframework.http.HttpMethod;
65 import org.springframework.http.ResponseEntity;
66 import org.springframework.web.util.UriComponentsBuilder;
67
68 import com.fasterxml.jackson.core.JsonParseException;
69 import com.fasterxml.jackson.core.type.TypeReference;
70 import com.fasterxml.jackson.databind.DeserializationFeature;
71 import com.fasterxml.jackson.databind.JsonMappingException;
72 import com.fasterxml.jackson.databind.ObjectMapper;
73
74 public class OrchestrationRequestsTest extends BaseTest {
75     @Autowired
76     private RequestsDbClient requestsDbClient;
77     
78     @Autowired 
79     private OrchestrationRequests orchReq;
80
81     private static final GetOrchestrationListResponse ORCHESTRATION_LIST = generateOrchestrationList();
82     private static final String INVALID_REQUEST_ID = "invalid-request-id";
83
84     private static GetOrchestrationListResponse generateOrchestrationList() {
85         GetOrchestrationListResponse list = null;
86         try {
87             ObjectMapper mapper = new ObjectMapper();
88             list = mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationList.json"),
89                     GetOrchestrationListResponse.class);
90         } catch (JsonParseException jpe) {
91             jpe.printStackTrace();
92         } catch (JsonMappingException jme) {
93             jme.printStackTrace();
94         } catch (IOException ioe) {
95             ioe.printStackTrace();
96         }
97         return list;
98     }
99
100     @Test
101     public void testGetOrchestrationRequest() throws Exception {
102         setupTestGetOrchestrationRequest();
103         // TEST VALID REQUEST
104         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
105
106         Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
107         testResponse.setRequest(request);
108         String testRequestId = request.getRequestId();
109         HttpHeaders headers = new HttpHeaders();
110         headers.set("Accept", MediaType.APPLICATION_JSON);
111         headers.set("Content-Type", MediaType.APPLICATION_JSON);
112         HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
113
114         UriComponentsBuilder builder = UriComponentsBuilder
115                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
116
117         ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET,
118                 entity, GetOrchestrationResponse.class);
119
120         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
121         assertThat(response.getBody(),
122             sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime")
123                 .ignoring("request.requestStatus.timeStamp"));
124         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
125         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
126         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
127         assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
128         assertEquals("00032ab7-na18-42e5-965d-8ea592502018", response.getHeaders().get("X-TransactionID").get(0));
129         assertNotNull(response.getBody().getRequest().getFinishTime());
130     }
131     
132     @Test
133     public void testGetOrchestrationRequestInstanceGroup() throws Exception {
134         setupTestGetOrchestrationRequestInstanceGroup();
135         // TEST VALID REQUEST
136         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
137
138         Request request = ORCHESTRATION_LIST.getRequestList().get(8).getRequest();
139         testResponse.setRequest(request);
140         String testRequestId = request.getRequestId();
141         HttpHeaders headers = new HttpHeaders();
142         headers.set("Accept", MediaType.APPLICATION_JSON);
143         headers.set("Content-Type", MediaType.APPLICATION_JSON);
144         HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
145
146         UriComponentsBuilder builder = UriComponentsBuilder
147                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
148
149         ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET,
150                 entity, GetOrchestrationResponse.class);
151
152         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
153         assertThat(response.getBody(),
154             sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime")
155                 .ignoring("request.requestStatus.timeStamp"));
156     }
157
158     @Test
159     public void testGetOrchestrationRequestRequestDetails() throws Exception {
160         setupTestGetOrchestrationRequestRequestDetails("00032ab7-3fb3-42e5-965d-8ea592502017", "COMPLETED");
161         //Test request with modelInfo request body
162         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
163
164         Request request = ORCHESTRATION_LIST.getRequestList().get(0).getRequest();
165         testResponse.setRequest(request);
166         String testRequestId = request.getRequestId();
167
168         HttpHeaders headers = new HttpHeaders();
169         headers.set("Accept", MediaType.APPLICATION_JSON);
170         headers.set("Content-Type", MediaType.APPLICATION_JSON);
171         HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
172
173         UriComponentsBuilder builder = UriComponentsBuilder
174                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
175
176         ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET,
177                 entity, GetOrchestrationResponse.class);
178
179         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
180         assertThat(response.getBody(),
181             sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime")
182                 .ignoring("request.requestStatus.timeStamp"));
183         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
184         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
185         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
186         assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
187         assertEquals("00032ab7-3fb3-42e5-965d-8ea592502017", response.getHeaders().get("X-TransactionID").get(0));
188     }
189
190     @Test
191     public void testGetOrchestrationRequestNoRequestID() {
192         HttpHeaders headers = new HttpHeaders();
193         headers.set("Accept", "application/json; charset=UTF-8");
194         headers.set("Content-Type", "application/json; charset=UTF-8"); 
195         HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
196         UriComponentsBuilder builder = UriComponentsBuilder
197                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v6/"));
198
199         ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
200                 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
201         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
202     }
203
204     @Test
205     public void testGetOrchestrationRequestFilter() throws Exception {
206         setupTestGetOrchestrationRequestFilter();
207         List<String> values = new ArrayList<>();
208         values.add("EQUALS");
209         values.add("vfModule");
210         
211         ObjectMapper mapper = new ObjectMapper();
212         GetOrchestrationListResponse testResponse = mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json"),
213                 GetOrchestrationListResponse.class);
214
215         Map<String, List<String>> orchestrationMap = new HashMap<>();
216         orchestrationMap.put("modelType", values);
217         List<GetOrchestrationResponse> testResponses = new ArrayList<>();
218
219         List<InfraActiveRequests> requests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap);
220         HttpHeaders headers = new HttpHeaders();
221         headers.set("Accept", MediaType.APPLICATION_JSON);
222         HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
223         
224         UriComponentsBuilder builder = UriComponentsBuilder
225                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v6?filter=modelType:EQUALS:vfModule"));
226
227         ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
228                 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
229         assertThat(response.getBody(),
230             sameBeanAs(testResponse).ignoring("requestList.request.startTime").ignoring("requestList.request.finishTime")
231                 .ignoring("requestList.request.requestStatus.timeStamp"));
232         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
233         assertEquals(requests.size(), response.getBody().getRequestList().size());
234         
235     }
236
237     @Test
238     public void testUnlockOrchestrationRequest() throws Exception {
239         setupTestUnlockOrchestrationRequest("0017f68c-eb2d-45bb-b7c7-ec31b37dc349", "UNLOCKED");
240         ObjectMapper mapper = new ObjectMapper();
241         mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
242         String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
243         HttpHeaders headers = new HttpHeaders();
244         headers.set("Accept", MediaType.APPLICATION_JSON);
245         headers.set("Content-Type", MediaType.APPLICATION_JSON);
246         HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
247
248         UriComponentsBuilder builder;
249         ResponseEntity<String> response;
250         RequestError expectedRequestError;
251         RequestError actualRequestError;
252         ServiceException se;
253
254         // Test invalid JSON
255         expectedRequestError = new RequestError();
256         se = new ServiceException();
257         se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
258         se.setText("Orchestration RequestId 0017f68c-eb2d-45bb-b7c7-ec31b37dc349 has a status of UNLOCKED and can not be unlocked");
259         expectedRequestError.setServiceException(se);
260
261         builder = UriComponentsBuilder.fromHttpUrl(
262                 createURLWithPort("/onap/so/infra/orchestrationRequests/v6/0017f68c-eb2d-45bb-b7c7-ec31b37dc349/unlock"));
263
264         response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
265         actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
266
267         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
268         assertThat(actualRequestError, sameBeanAs(expectedRequestError));
269     }
270
271     @Test
272     public void testUnlockOrchestrationRequest_invalid_Json() throws Exception {
273         setupTestUnlockOrchestrationRequest_invalid_Json();
274         ObjectMapper mapper = new ObjectMapper();
275         mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
276         String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
277         HttpHeaders headers = new HttpHeaders();
278         headers.set("Accept", MediaType.APPLICATION_JSON);
279         headers.set("Content-Type", MediaType.APPLICATION_JSON);
280         HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
281
282         UriComponentsBuilder builder;
283         ResponseEntity<String> response;
284         RequestError expectedRequestError;
285         RequestError actualRequestError;
286         ServiceException se;
287
288         // Test invalid requestId
289         expectedRequestError = new RequestError();
290         se = new ServiceException();
291         se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
292         se.setText("Null response from RequestDB when searching by RequestId");
293         expectedRequestError.setServiceException(se);
294
295         builder = UriComponentsBuilder.fromHttpUrl(
296                 createURLWithPort("/onap/so/infra/orchestrationRequests/v6/" + INVALID_REQUEST_ID + "/unlock"));
297
298         response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
299         actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
300
301         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
302         assertThat(actualRequestError, sameBeanAs(expectedRequestError));
303     }
304
305     @Test
306     public void testUnlockOrchestrationRequest_Valid_Status()
307             throws JsonParseException, JsonMappingException, IOException, ValidationException {
308         setupTestUnlockOrchestrationRequest_Valid_Status("5ffbabd6-b793-4377-a1ab-082670fbc7ac", "PENDING");
309         ObjectMapper mapper = new ObjectMapper();
310         String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
311         HttpHeaders headers = new HttpHeaders();
312         headers.set("Accept", MediaType.APPLICATION_JSON);
313         headers.set("Content-Type", MediaType.APPLICATION_JSON);
314         HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
315
316         UriComponentsBuilder builder;
317         ResponseEntity<String> response;
318         Request request;
319
320         // Test valid status
321         request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
322         builder = UriComponentsBuilder.fromHttpUrl(
323                 createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + "5ffbabd6-b793-4377-a1ab-082670fbc7ac" + "/unlock"));
324
325         response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
326         //Cannot assert anything further here, already have a wiremock in place which ensures that the post was properly called to update.
327     }
328
329     @Ignore //What is this testing?
330     @Test
331     public void testGetOrchestrationRequestRequestDetailsWhiteSpace() throws Exception {
332         InfraActiveRequests requests = new InfraActiveRequests();
333         requests.setAction("create");
334         requests.setRequestBody("  ");
335         requests.setRequestId("requestId");
336         requests.setRequestScope("service");
337         requests.setRequestType("createInstance");
338         ObjectMapper mapper = new ObjectMapper();
339         String json = mapper.writeValueAsString(requests);
340
341         requestsDbClient.save(requests);
342         HttpHeaders headers = new HttpHeaders();
343         headers.set("Accept", MediaType.APPLICATION_JSON);
344         headers.set("Content-Type", MediaType.APPLICATION_JSON);
345         HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
346
347         UriComponentsBuilder builder = UriComponentsBuilder
348                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/requestId"));
349
350         ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET,
351                 entity, GetOrchestrationResponse.class);
352
353         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
354         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
355         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
356         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
357         assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
358         assertEquals("requestId", response.getHeaders().get("X-TransactionID").get(0));
359     }
360
361     @Ignore //What is this testing?
362     @Test
363     public void testGetOrchestrationRequestRequestDetailsAlaCarte() throws IOException {
364         InfraActiveRequests requests = new InfraActiveRequests();
365
366         String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/AlaCarteRequest.json")));
367
368         requests.setAction("create");
369         requests.setRequestBody(requestJSON);
370         requests.setRequestId("requestId");
371         requests.setRequestScope("service");
372         requests.setRequestType("createInstance");
373 //        iar.save(requests);
374         HttpHeaders headers = new HttpHeaders();
375         headers.set("Accept", MediaType.APPLICATION_JSON);
376         headers.set("Content-Type", MediaType.APPLICATION_JSON);
377         HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
378
379         UriComponentsBuilder builder = UriComponentsBuilder
380                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/requestId"));
381
382         ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET,
383                 entity, GetOrchestrationResponse.class);
384
385         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
386         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
387         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
388         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
389         assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
390         assertEquals("requestId", response.getHeaders().get("X-TransactionID").get(0));
391     }
392     @Test
393     public void mapRequestProcessingDataTest() throws JsonParseException, JsonMappingException, IOException{
394         RequestProcessingData entry = new RequestProcessingData();
395         RequestProcessingData secondEntry = new RequestProcessingData();
396         List<HashMap<String, String>> expectedList = new ArrayList<>();
397         HashMap<String, String> expectedMap = new HashMap<>();
398         List<HashMap<String, String>> secondExpectedList = new ArrayList<>();
399         HashMap<String, String> secondExpectedMap = new HashMap<>();
400         List<RequestProcessingData> expectedDataList = new ArrayList<>();
401         entry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
402         entry.setTag("pincFabricConfigRequest");
403         expectedMap.put("requestAction", "assign");
404         expectedMap.put("pincFabricId", "testId");
405         expectedList.add(expectedMap);
406         entry.setDataPairs(expectedList);
407         secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715");
408         secondEntry.setTag("pincFabricConfig");
409         secondExpectedMap.put("requestAction", "unassign");
410         secondExpectedList.add(secondExpectedMap);
411         secondEntry.setDataPairs(secondExpectedList);
412         expectedDataList.add(entry);
413         expectedDataList.add(secondEntry);
414         
415         List<org.onap.so.db.request.beans.RequestProcessingData> processingData = new ArrayList<>(); 
416         List<RequestProcessingData> actualProcessingData = new ArrayList<>();
417         ObjectMapper mapper = new ObjectMapper();
418         processingData = mapper.readValue(new File("src/test/resources/OrchestrationRequest/RequestProcessingData.json"),
419                         new TypeReference<List<org.onap.so.db.request.beans.RequestProcessingData>>(){});
420         actualProcessingData = orchReq.mapRequestProcessingData(processingData);
421         assertThat(actualProcessingData,sameBeanAs(expectedDataList));
422     }
423
424     public void setupTestGetOrchestrationRequest() throws Exception{
425         //For testGetOrchestrationRequest
426         stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-na18-42e5-965d-8ea592502018")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
427                 .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequest.json"))))
428                 .withStatus(HttpStatus.SC_OK)));
429         stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"))
430                         .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-na18-42e5-965d-8ea592502018"))
431                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
432                 .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
433                 .withStatus(HttpStatus.SC_OK)));
434     }
435     public void setupTestGetOrchestrationRequestInstanceGroup() throws Exception{
436         //For testGetOrchestrationRequest
437         stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-na18-42e5-965d-8ea592502018")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
438                 .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json"))))
439                 .withStatus(HttpStatus.SC_OK)));
440         stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"))
441                         .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-na18-42e5-965d-8ea592502018"))
442                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
443                 .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
444                 .withStatus(HttpStatus.SC_OK)));
445     }
446
447     private void setupTestGetOrchestrationRequestRequestDetails(String requestId, String status) throws Exception{
448         stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
449                 .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequestDetails.json"))))
450                 .withStatus(HttpStatus.SC_OK)));
451     }
452
453     private void setupTestUnlockOrchestrationRequest(String requestId, String status) {
454         stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
455                 .withBody(String.format(getResponseTemplate, requestId, status))
456                 .withStatus(HttpStatus.SC_OK)));
457
458     }
459
460
461
462     private void setupTestUnlockOrchestrationRequest_invalid_Json() {
463         stubFor(get(urlPathEqualTo(getTestUrl(INVALID_REQUEST_ID))).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
464                 .withStatus(HttpStatus.SC_NOT_FOUND)));
465
466     }
467
468     private void setupTestUnlockOrchestrationRequest_Valid_Status(String requestID, String status) {
469         stubFor(get(urlPathEqualTo(getTestUrl(requestID))).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
470                 .withBody(String.format(getResponseTemplate, requestID, status))
471                 .withStatus(HttpStatus.SC_OK)));
472
473         stubFor(post(urlPathEqualTo(getTestUrl(""))).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
474                 .withBody(String.format(infraActivePost, requestID))
475                 .withStatus(HttpStatus.SC_OK)));
476     }
477
478     private void setupTestGetOrchestrationRequestFilter() throws Exception{
479         //for testGetOrchestrationRequestFilter();
480         stubFor(any(urlPathEqualTo("/infraActiveRequests/getOrchestrationFiltersFromInfraActive/")).withRequestBody(equalToJson("{\"modelType\":[\"EQUALS\",\"vfModule\"]}")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
481                 .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestDetailsFilter.json"))))
482                 .withStatus(HttpStatus.SC_OK)));
483     }
484 }