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