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