2  * ============LICENSE_START=======================================================
 
   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
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  21 package org.onap.so.apihandlerinfra;
 
  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;
 
  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;
 
  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;
 
  71 public class OrchestrationRequestsTest extends BaseTest {
 
  73     private RequestsDbClient requestsDbClient;
 
  76     private OrchestrationRequests orchReq;
 
  78     private static final GetOrchestrationListResponse ORCHESTRATION_LIST = generateOrchestrationList();
 
  79     private static final String INVALID_REQUEST_ID = "invalid-request-id";
 
  81     private static GetOrchestrationListResponse generateOrchestrationList() {
 
  82         GetOrchestrationListResponse list = null;
 
  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();
 
  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)));
 
 125     public void testGetOrchestrationRequest() throws Exception {
 
 126         setupTestGetOrchestrationRequest();
 
 127         // TEST VALID REQUEST
 
 128         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
 
 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");
 
 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);
 
 148         UriComponentsBuilder builder = UriComponentsBuilder
 
 149                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
 
 151         ResponseEntity<GetOrchestrationResponse> response =
 
 152                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
 
 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());
 
 166     public void testGetOrchestrationRequestInstanceGroup() throws Exception {
 
 167         setupTestGetOrchestrationRequestInstanceGroup();
 
 168         // TEST VALID REQUEST
 
 169         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
 
 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");
 
 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);
 
 189         UriComponentsBuilder builder = UriComponentsBuilder
 
 190                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
 
 192         ResponseEntity<GetOrchestrationResponse> response =
 
 193                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
 
 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"));
 
 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();
 
 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}",
 
 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");
 
 227         e.setDataPairs(data);
 
 228         testResponse.getRequest().getRequestProcessingData().add(e);
 
 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);
 
 235         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
 
 236                 "/onap/so/infra/orchestrationRequests/v7/" + testRequestId + "?includeCloudRequest=true"));
 
 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());
 
 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));
 
 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/"));
 
 261         ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
 
 262                 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
 
 263         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
 
 267     public void testGetOrchestrationRequestInvalidRequestID() throws Exception {
 
 268         setupTestGetOrchestrationRequest();
 
 269         // TEST INVALID REQUESTID
 
 270         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
 
 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);
 
 280         UriComponentsBuilder builder = UriComponentsBuilder
 
 281                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
 
 283         ResponseEntity<GetOrchestrationResponse> response =
 
 284                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
 
 286         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
 
 290     public void testGetOrchestrationRequestFilter() throws Exception {
 
 291         setupTestGetOrchestrationRequestFilter();
 
 292         List<String> values = new ArrayList<>();
 
 293         values.add("EQUALS");
 
 294         values.add("vfModule");
 
 296         ObjectMapper mapper = new ObjectMapper();
 
 297         GetOrchestrationListResponse testResponse =
 
 298                 mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json"),
 
 299                         GetOrchestrationListResponse.class);
 
 301         Map<String, List<String>> orchestrationMap = new HashMap<>();
 
 302         orchestrationMap.put("modelType", values);
 
 303         List<GetOrchestrationResponse> testResponses = new ArrayList<>();
 
 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);
 
 310         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(
 
 311                 createURLWithPort("/onap/so/infra/orchestrationRequests/v6?filter=modelType:EQUALS:vfModule"));
 
 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());
 
 323     public void testUnlockOrchestrationRequest() throws Exception {
 
 324         setupTestUnlockOrchestrationRequest("0017f68c-eb2d-45bb-b7c7-ec31b37dc349", "UNLOCKED");
 
 325         ObjectMapper mapper = new ObjectMapper();
 
 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);
 
 333         UriComponentsBuilder builder;
 
 334         ResponseEntity<String> response;
 
 335         RequestError expectedRequestError;
 
 336         RequestError actualRequestError;
 
 340         expectedRequestError = new RequestError();
 
 341         se = new ServiceException();
 
 342         se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
 
 344                 "Orchestration RequestId 0017f68c-eb2d-45bb-b7c7-ec31b37dc349 has a status of UNLOCKED and can not be unlocked");
 
 345         expectedRequestError.setServiceException(se);
 
 347         builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
 
 348                 "/onap/so/infra/orchestrationRequests/v6/0017f68c-eb2d-45bb-b7c7-ec31b37dc349/unlock"));
 
 350         response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
 
 351         actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
 
 353         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
 
 354         assertThat(actualRequestError, sameBeanAs(expectedRequestError));
 
 358     public void testUnlockOrchestrationRequest_invalid_Json() throws Exception {
 
 359         setupTestUnlockOrchestrationRequest_invalid_Json();
 
 360         ObjectMapper mapper = new ObjectMapper();
 
 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);
 
 368         UriComponentsBuilder builder;
 
 369         ResponseEntity<String> response;
 
 370         RequestError expectedRequestError;
 
 371         RequestError actualRequestError;
 
 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);
 
 381         builder = UriComponentsBuilder.fromHttpUrl(
 
 382                 createURLWithPort("/onap/so/infra/orchestrationRequests/v6/" + INVALID_REQUEST_ID + "/unlock"));
 
 384         response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
 
 385         actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
 
 387         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
 
 388         assertThat(expectedRequestError, sameBeanAs(actualRequestError));
 
 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();
 
 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);
 
 403         UriComponentsBuilder builder;
 
 404         ResponseEntity<String> response;
 
 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"));
 
 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.
 
 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);
 
 441         List<org.onap.so.db.request.beans.RequestProcessingData> processingData = new ArrayList<>();
 
 442         List<RequestProcessingData> actualProcessingData = new ArrayList<>();
 
 443         ObjectMapper mapper = new ObjectMapper();
 
 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));
 
 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)));
 
 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)));
 
 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)));
 
 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)));
 
 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)));
 
 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)));
 
 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)));
 
 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)));
 
 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)));
 
 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)));
 
 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)));