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