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;
 
  35 import static org.junit.Assert.assertNull;
 
  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;
 
  44 import java.util.UUID;
 
  45 import javax.ws.rs.core.MediaType;
 
  46 import javax.ws.rs.core.Response;
 
  47 import org.apache.http.HttpStatus;
 
  48 import org.junit.Before;
 
  49 import org.junit.Test;
 
  50 import org.onap.logging.ref.slf4j.ONAPLogConstants;
 
  51 import org.onap.so.apihandler.common.ErrorNumbers;
 
  52 import org.onap.so.db.request.beans.InfraActiveRequests;
 
  53 import org.onap.so.db.request.client.RequestsDbClient;
 
  54 import org.onap.so.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;
 
  72 public class OrchestrationRequestsTest extends BaseTest {
 
  74     private RequestsDbClient requestsDbClient;
 
  77     private OrchestrationRequests orchReq;
 
  79     private static final GetOrchestrationListResponse ORCHESTRATION_LIST = generateOrchestrationList();
 
  80     private static final String INVALID_REQUEST_ID = "invalid-request-id";
 
  82     private static GetOrchestrationListResponse generateOrchestrationList() {
 
  83         GetOrchestrationListResponse list = null;
 
  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();
 
  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)));
 
 126     public void testGetOrchestrationRequest() throws Exception {
 
 127         setupTestGetOrchestrationRequest();
 
 128         // TEST VALID REQUEST
 
 129         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
 
 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");
 
 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);
 
 149         UriComponentsBuilder builder = UriComponentsBuilder
 
 150                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
 
 152         ResponseEntity<GetOrchestrationResponse> response =
 
 153                 restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
 
 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());
 
 168     public void getOrchestrationRequestSimpleTest() throws Exception {
 
 169         setupTestGetOrchestrationRequest();
 
 170         // TEST VALID REQUEST
 
 171         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
 
 173         Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
 
 174         request.setRequestProcessingData(null);
 
 175         testResponse.setRequest(request);
 
 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");
 
 187         ResponseEntity<GetOrchestrationResponse> response =
 
 188                 restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
 
 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());
 
 202     public void testGetOrchestrationRequestInstanceGroup() throws Exception {
 
 203         setupTestGetOrchestrationRequestInstanceGroup();
 
 204         // TEST VALID REQUEST
 
 205         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
 
 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");
 
 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);
 
 224         UriComponentsBuilder builder = UriComponentsBuilder
 
 225                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
 
 227         ResponseEntity<GetOrchestrationResponse> response =
 
 228                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
 
 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"));
 
 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();
 
 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}",
 
 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");
 
 261         e.setDataPairs(data);
 
 262         testResponse.getRequest().getRequestProcessingData().add(e);
 
 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);
 
 270         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
 
 271                 "/onap/so/infra/orchestrationRequests/v7/" + testRequestId + "?includeCloudRequest=true"));
 
 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());
 
 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));
 
 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/"));
 
 296         ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
 
 297                 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
 
 298         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
 
 302     public void testGetOrchestrationRequestInvalidRequestID() throws Exception {
 
 303         setupTestGetOrchestrationRequest();
 
 304         // TEST INVALID REQUESTID
 
 305         GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
 
 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);
 
 315         UriComponentsBuilder builder = UriComponentsBuilder
 
 316                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
 
 318         ResponseEntity<GetOrchestrationResponse> response =
 
 319                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
 
 321         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
 
 325     public void testGetOrchestrationRequestFilter() throws Exception {
 
 326         setupTestGetOrchestrationRequestFilter();
 
 327         List<String> values = new ArrayList<>();
 
 328         values.add("EQUALS");
 
 329         values.add("vfModule");
 
 331         ObjectMapper mapper = new ObjectMapper();
 
 332         GetOrchestrationListResponse testResponse =
 
 333                 mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json"),
 
 334                         GetOrchestrationListResponse.class);
 
 336         Map<String, List<String>> orchestrationMap = new HashMap<>();
 
 337         orchestrationMap.put("modelType", values);
 
 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);
 
 344         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(
 
 345                 createURLWithPort("/onap/so/infra/orchestrationRequests/v6?filter=modelType:EQUALS:vfModule"));
 
 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());
 
 357     public void testUnlockOrchestrationRequest() throws Exception {
 
 358         setupTestUnlockOrchestrationRequest("0017f68c-eb2d-45bb-b7c7-ec31b37dc349", "UNLOCKED");
 
 359         ObjectMapper mapper = new ObjectMapper();
 
 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);
 
 367         UriComponentsBuilder builder;
 
 368         ResponseEntity<String> response;
 
 369         RequestError expectedRequestError;
 
 370         RequestError actualRequestError;
 
 374         expectedRequestError = new RequestError();
 
 375         se = new ServiceException();
 
 376         se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
 
 378                 "Orchestration RequestId 0017f68c-eb2d-45bb-b7c7-ec31b37dc349 has a status of UNLOCKED and can not be unlocked");
 
 379         expectedRequestError.setServiceException(se);
 
 381         builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
 
 382                 "/onap/so/infra/orchestrationRequests/v6/0017f68c-eb2d-45bb-b7c7-ec31b37dc349/unlock"));
 
 384         response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
 
 385         actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
 
 387         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
 
 388         assertThat(actualRequestError, sameBeanAs(expectedRequestError));
 
 392     public void testUnlockOrchestrationRequest_invalid_Json() throws Exception {
 
 393         setupTestUnlockOrchestrationRequest_invalid_Json();
 
 394         ObjectMapper mapper = new ObjectMapper();
 
 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);
 
 402         UriComponentsBuilder builder;
 
 403         ResponseEntity<String> response;
 
 404         RequestError expectedRequestError;
 
 405         RequestError actualRequestError;
 
 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);
 
 415         builder = UriComponentsBuilder.fromHttpUrl(
 
 416                 createURLWithPort("/onap/so/infra/orchestrationRequests/v6/" + INVALID_REQUEST_ID + "/unlock"));
 
 418         response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
 
 419         actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
 
 421         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
 
 422         assertThat(expectedRequestError, sameBeanAs(actualRequestError));
 
 426     public void testUnlockOrchestrationRequest_Valid_Status() throws IOException {
 
 427         setupTestUnlockOrchestrationRequest_Valid_Status("5ffbabd6-b793-4377-a1ab-082670fbc7ac", "PENDING");
 
 429                 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
 
 430         HttpHeaders headers = new HttpHeaders();
 
 431         headers.set("Accept", MediaType.APPLICATION_JSON);
 
 432         headers.set("Content-Type", MediaType.APPLICATION_JSON);
 
 433         HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
 
 435         UriComponentsBuilder builder;
 
 436         builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
 
 437                 "/onap/so/infra/orchestrationRequests/v7/" + "5ffbabd6-b793-4377-a1ab-082670fbc7ac" + "/unlock"));
 
 438         // Cannot assert anything further here, already have a wiremock in place
 
 439         // which ensures that the post was
 
 440         // properly called to update.
 
 444     public void mapRequestProcessingDataTest() throws IOException {
 
 445         RequestProcessingData entry = new RequestProcessingData();
 
 446         RequestProcessingData secondEntry = new RequestProcessingData();
 
 447         List<HashMap<String, String>> expectedList = new ArrayList<>();
 
 448         HashMap<String, String> expectedMap = new HashMap<>();
 
 449         List<HashMap<String, String>> secondExpectedList = new ArrayList<>();
 
 450         HashMap<String, String> secondExpectedMap = new HashMap<>();
 
 451         List<RequestProcessingData> expectedDataList = new ArrayList<>();
 
 452         entry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
 
 453         expectedMap.put("requestAction", "assign");
 
 454         expectedMap.put("fabricId", "testId");
 
 455         expectedList.add(expectedMap);
 
 456         entry.setDataPairs(expectedList);
 
 457         secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715");
 
 458         secondExpectedMap.put("requestAction", "unassign");
 
 459         secondExpectedList.add(secondExpectedMap);
 
 460         secondEntry.setDataPairs(secondExpectedList);
 
 461         expectedDataList.add(entry);
 
 462         expectedDataList.add(secondEntry);
 
 464         List<org.onap.so.db.request.beans.RequestProcessingData> processingData = new ArrayList<>();
 
 465         List<RequestProcessingData> actualProcessingData = new ArrayList<>();
 
 466         ObjectMapper mapper = new ObjectMapper();
 
 468                 mapper.readValue(new File("src/test/resources/OrchestrationRequest/RequestProcessingData.json"),
 
 469                         new TypeReference<List<org.onap.so.db.request.beans.RequestProcessingData>>() {});
 
 470         actualProcessingData = orchReq.mapRequestProcessingData(processingData);
 
 471         assertThat(actualProcessingData, sameBeanAs(expectedDataList));
 
 475     public void testThatActiveRequestsExceptionsAreMapped() {
 
 476         String testRequestId = UUID.randomUUID().toString();
 
 477         wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/" + testRequestId))
 
 478                 .willReturn(aResponse().withStatus(HttpStatus.SC_UNAUTHORIZED)));
 
 480         HttpHeaders headers = new HttpHeaders();
 
 481         headers.set("Accept", MediaType.APPLICATION_JSON);
 
 482         headers.set("Content-Type", MediaType.APPLICATION_JSON);
 
 483         headers.set(ONAPLogConstants.Headers.REQUEST_ID, "1e45215d-b7b3-4c5a-9316-65bdddaf649f");
 
 484         HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
 
 486         UriComponentsBuilder builder = UriComponentsBuilder
 
 487                 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
 
 489         ResponseEntity<GetOrchestrationResponse> response =
 
 490                 restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
 
 492         assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), response.getStatusCode().value());
 
 495     public void setupTestGetOrchestrationRequest() throws Exception {
 
 496         // For testGetOrchestrationRequest
 
 497         wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018"))
 
 498                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 499                         .withBody(new String(Files.readAllBytes(
 
 500                                 Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequest.json"))))
 
 501                         .withStatus(HttpStatus.SC_OK)));
 
 502         wireMockServer.stubFor(get(urlPathEqualTo(
 
 503                 "/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc/"))
 
 504                         .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-1a18-42e5-965d-8ea592502018"))
 
 505                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 506                                 .withBody(new String(Files.readAllBytes(Paths
 
 507                                         .get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
 
 508                                 .withStatus(HttpStatus.SC_OK)));
 
 511     public void setupTestGetOrchestrationRequestInstanceGroup() throws Exception {
 
 512         // For testGetOrchestrationRequest
 
 513         wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018"))
 
 514                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 515                         .withBody(new String(Files.readAllBytes(Paths.get(
 
 516                                 "src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json"))))
 
 517                         .withStatus(HttpStatus.SC_OK)));
 
 518         wireMockServer.stubFor(get(urlPathEqualTo(
 
 519                 "/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc/"))
 
 520                         .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-1a18-42e5-965d-8ea592502018"))
 
 521                         .withQueryParam("IS_INTERNAL_DATA", equalTo("false"))
 
 522                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 523                                 .withBody(new String(Files.readAllBytes(Paths
 
 524                                         .get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
 
 525                                 .withStatus(HttpStatus.SC_OK)));
 
 528     private void setupTestGetOrchestrationRequestRequestDetails(String requestId, String status) throws Exception {
 
 529         wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse()
 
 530                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 531                 .withBody(new String(Files.readAllBytes(
 
 532                         Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequestDetails.json"))))
 
 533                 .withStatus(HttpStatus.SC_OK)));
 
 536     private void setupTestGetOrchestrationRequestOpenstackDetails(String requestId, String status) throws Exception {
 
 537         wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse()
 
 538                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 539                 .withBody(new String(Files.readAllBytes(Paths
 
 540                         .get("src/test/resources/OrchestrationRequest/getOrchestrationOpenstackRequestDetails.json"))))
 
 541                 .withStatus(HttpStatus.SC_OK)));
 
 544     private void setupTestUnlockOrchestrationRequest(String requestId, String status) {
 
 545         wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId)))
 
 546                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 547                         .withBody(String.format(getResponseTemplate, requestId, status)).withStatus(HttpStatus.SC_OK)));
 
 550     private void setupTestUnlockOrchestrationRequest_invalid_Json() {
 
 551         wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(INVALID_REQUEST_ID))).willReturn(aResponse()
 
 552                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_NOT_FOUND)));
 
 556     private void setupTestUnlockOrchestrationRequest_Valid_Status(String requestID, String status) {
 
 557         wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestID)))
 
 558                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 559                         .withBody(String.format(getResponseTemplate, requestID, status)).withStatus(HttpStatus.SC_OK)));
 
 561         wireMockServer.stubFor(post(urlPathEqualTo(getTestUrl("")))
 
 562                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 563                         .withBody(String.format(infraActivePost, requestID)).withStatus(HttpStatus.SC_OK)));
 
 566     private void setupTestGetOrchestrationRequestFilter() throws Exception {
 
 567         // for testGetOrchestrationRequestFilter();
 
 568         wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"))
 
 569                 .withRequestBody(equalToJson("{\"modelType\":[\"EQUALS\",\"vfModule\"]}"))
 
 570                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
 
 571                         .withBody(new String(Files.readAllBytes(
 
 572                                 Paths.get("src/test/resources/OrchestrationRequest/getRequestDetailsFilter.json"))))
 
 573                         .withStatus(HttpStatus.SC_OK)));