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 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;
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 e.setTag("pincFabricConfigRequest");
137 List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
138 HashMap<String, String> data1 = new HashMap<String, String>();
139 data1.put("requestAction", "assign");
141 e.setDataPairs(data);
142 testResponse.getRequest().getRequestProcessingData().add(e);
143 String testRequestId = request.getRequestId();
144 HttpHeaders headers = new HttpHeaders();
145 headers.set("Accept", MediaType.APPLICATION_JSON);
146 headers.set("Content-Type", MediaType.APPLICATION_JSON);
147 headers.set(ONAPLogConstants.Headers.REQUEST_ID, "1e45215d-b7b3-4c5a-9316-65bdddaf649f");
148 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
150 UriComponentsBuilder builder = UriComponentsBuilder
151 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
153 ResponseEntity<GetOrchestrationResponse> response =
154 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
156 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
157 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime")
158 .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
159 assertNull(response.getBody().getRequest().getInstanceReferences().getRequestorId());
160 assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
161 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
162 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
163 assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
164 assertEquals("1e45215d-b7b3-4c5a-9316-65bdddaf649f", response.getHeaders().get("X-TransactionID").get(0));
165 assertNotNull(response.getBody().getRequest().getFinishTime());
169 public void getOrchestrationRequestSimpleTest() throws Exception {
170 setupTestGetOrchestrationRequest();
171 // TEST VALID REQUEST
172 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
174 Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
175 request.setRequestProcessingData(null);
176 testResponse.setRequest(request);
178 String testRequestId = request.getRequestId();
179 HttpHeaders headers = new HttpHeaders();
180 headers.set("Accept", MediaType.APPLICATION_JSON);
181 headers.set("Content-Type", MediaType.APPLICATION_JSON);
182 headers.set(ONAPLogConstants.Headers.REQUEST_ID, "e5e3c007-9fe9-4a20-8691-bdd20e14504d");
183 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
184 UriComponentsBuilder builder = UriComponentsBuilder
185 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId))
186 .queryParam("format", "simple");
188 ResponseEntity<GetOrchestrationResponse> response =
189 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
191 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
192 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime")
193 .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
194 assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
195 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
196 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
197 assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
198 assertEquals("e5e3c007-9fe9-4a20-8691-bdd20e14504d", response.getHeaders().get("X-TransactionID").get(0));
199 assertNotNull(response.getBody().getRequest().getFinishTime());
203 public void testGetOrchestrationRequestInstanceGroup() throws Exception {
204 setupTestGetOrchestrationRequestInstanceGroup();
205 // TEST VALID REQUEST
206 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
208 Request request = ORCHESTRATION_LIST.getRequestList().get(8).getRequest();
209 testResponse.setRequest(request);
210 testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>());
211 RequestProcessingData e = new RequestProcessingData();
212 e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
213 e.setTag("pincFabricConfigRequest");
214 List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
215 HashMap<String, String> data1 = new HashMap<String, String>();
216 data1.put("requestAction", "assign");
218 e.setDataPairs(data);
219 testResponse.getRequest().getRequestProcessingData().add(e);
220 String testRequestId = request.getRequestId();
221 HttpHeaders headers = new HttpHeaders();
222 headers.set("Accept", MediaType.APPLICATION_JSON);
223 headers.set("Content-Type", MediaType.APPLICATION_JSON);
224 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
226 UriComponentsBuilder builder = UriComponentsBuilder
227 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
229 ResponseEntity<GetOrchestrationResponse> response =
230 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
232 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
233 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime")
234 .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
238 public void testGetOrchestrationRequestWithOpenstackDetails() throws Exception {
239 setupTestGetOrchestrationRequestOpenstackDetails("00032ab7-3fb3-42e5-965d-8ea592502017", "COMPLETED");
240 // Test request with modelInfo request body
241 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
243 Request request = ORCHESTRATION_LIST.getRequestList().get(0).getRequest();
244 List<CloudRequestData> cloudRequestData = new ArrayList<>();
245 CloudRequestData cloudData = new CloudRequestData();
246 cloudData.setCloudIdentifier("heatstackName/123123");
247 ObjectMapper mapper = new ObjectMapper();
248 Object reqData = mapper.readValue(
249 "{\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}",
251 cloudData.setCloudRequest(reqData);
252 cloudRequestData.add(cloudData);
253 request.setCloudRequestData(cloudRequestData);
254 testResponse.setRequest(request);
255 String testRequestId = request.getRequestId();
256 testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>());
257 RequestProcessingData e = new RequestProcessingData();
258 e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
259 e.setTag("pincFabricConfigRequest");
260 List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
261 HashMap<String, String> data1 = new HashMap<String, String>();
262 data1.put("requestAction", "assign");
264 e.setDataPairs(data);
265 testResponse.getRequest().getRequestProcessingData().add(e);
267 HttpHeaders headers = new HttpHeaders();
268 headers.set("Accept", MediaType.APPLICATION_JSON);
269 headers.set("Content-Type", MediaType.APPLICATION_JSON);
270 headers.set(ONAPLogConstants.Headers.REQUEST_ID, "0321e28d-3dde-4b31-9b28-1e0f07231b93");
271 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
273 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
274 "/onap/so/infra/orchestrationRequests/v7/" + testRequestId + "?includeCloudRequest=true"));
276 ResponseEntity<GetOrchestrationResponse> response =
277 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
278 System.out.println("Response :" + response.getBody().toString());
279 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
281 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime")
282 .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
283 assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
284 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
285 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
286 assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
287 assertEquals("0321e28d-3dde-4b31-9b28-1e0f07231b93", response.getHeaders().get("X-TransactionID").get(0));
291 public void testGetOrchestrationRequestNoRequestID() {
292 HttpHeaders headers = new HttpHeaders();
293 headers.set("Accept", "application/json; charset=UTF-8");
294 headers.set("Content-Type", "application/json; charset=UTF-8");
295 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
296 UriComponentsBuilder builder =
297 UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v6/"));
299 ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
300 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
301 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
305 public void testGetOrchestrationRequestInvalidRequestID() throws Exception {
306 setupTestGetOrchestrationRequest();
307 // TEST INVALID REQUESTID
308 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
310 Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
311 testResponse.setRequest(request);
312 String testRequestId = "00032ab7-pfb3-42e5-965d-8ea592502016";
313 HttpHeaders headers = new HttpHeaders();
314 headers.set("Accept", MediaType.APPLICATION_JSON);
315 headers.set("Content-Type", MediaType.APPLICATION_JSON);
316 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
318 UriComponentsBuilder builder = UriComponentsBuilder
319 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
321 ResponseEntity<GetOrchestrationResponse> response =
322 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
324 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
328 public void testGetOrchestrationRequestFilter() throws Exception {
329 setupTestGetOrchestrationRequestFilter();
330 List<String> values = new ArrayList<>();
331 values.add("EQUALS");
332 values.add("vfModule");
334 ObjectMapper mapper = new ObjectMapper();
335 GetOrchestrationListResponse testResponse =
336 mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json"),
337 GetOrchestrationListResponse.class);
339 Map<String, List<String>> orchestrationMap = new HashMap<>();
340 orchestrationMap.put("modelType", values);
341 List<GetOrchestrationResponse> testResponses = new ArrayList<>();
343 List<InfraActiveRequests> requests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap);
344 HttpHeaders headers = new HttpHeaders();
345 headers.set("Accept", MediaType.APPLICATION_JSON);
346 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
348 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(
349 createURLWithPort("/onap/so/infra/orchestrationRequests/v6?filter=modelType:EQUALS:vfModule"));
351 ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
352 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
353 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("requestList.request.startTime")
354 .ignoring("requestList.request.finishTime").ignoring("requestList.request.requestStatus.timeStamp"));
355 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
356 assertEquals(requests.size(), response.getBody().getRequestList().size());
361 public void testUnlockOrchestrationRequest() throws Exception {
362 setupTestUnlockOrchestrationRequest("0017f68c-eb2d-45bb-b7c7-ec31b37dc349", "UNLOCKED");
363 ObjectMapper mapper = new ObjectMapper();
365 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
366 HttpHeaders headers = new HttpHeaders();
367 headers.set("Accept", MediaType.APPLICATION_JSON);
368 headers.set("Content-Type", MediaType.APPLICATION_JSON);
369 HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
371 UriComponentsBuilder builder;
372 ResponseEntity<String> response;
373 RequestError expectedRequestError;
374 RequestError actualRequestError;
378 expectedRequestError = new RequestError();
379 se = new ServiceException();
380 se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
382 "Orchestration RequestId 0017f68c-eb2d-45bb-b7c7-ec31b37dc349 has a status of UNLOCKED and can not be unlocked");
383 expectedRequestError.setServiceException(se);
385 builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
386 "/onap/so/infra/orchestrationRequests/v6/0017f68c-eb2d-45bb-b7c7-ec31b37dc349/unlock"));
388 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
389 actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
391 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
392 assertThat(actualRequestError, sameBeanAs(expectedRequestError));
396 public void testUnlockOrchestrationRequest_invalid_Json() throws Exception {
397 setupTestUnlockOrchestrationRequest_invalid_Json();
398 ObjectMapper mapper = new ObjectMapper();
400 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
401 HttpHeaders headers = new HttpHeaders();
402 headers.set("Accept", MediaType.APPLICATION_JSON);
403 headers.set("Content-Type", MediaType.APPLICATION_JSON);
404 HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
406 UriComponentsBuilder builder;
407 ResponseEntity<String> response;
408 RequestError expectedRequestError;
409 RequestError actualRequestError;
412 // Test invalid requestId
413 expectedRequestError = new RequestError();
414 se = new ServiceException();
415 se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
416 se.setText("Null response from RequestDB when searching by RequestId " + INVALID_REQUEST_ID);
417 expectedRequestError.setServiceException(se);
419 builder = UriComponentsBuilder.fromHttpUrl(
420 createURLWithPort("/onap/so/infra/orchestrationRequests/v6/" + INVALID_REQUEST_ID + "/unlock"));
422 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
423 actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
425 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
426 assertThat(expectedRequestError, sameBeanAs(actualRequestError));
430 public void testUnlockOrchestrationRequest_Valid_Status()
431 throws JsonParseException, JsonMappingException, IOException, ValidationException {
432 setupTestUnlockOrchestrationRequest_Valid_Status("5ffbabd6-b793-4377-a1ab-082670fbc7ac", "PENDING");
433 ObjectMapper mapper = new ObjectMapper();
435 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
436 HttpHeaders headers = new HttpHeaders();
437 headers.set("Accept", MediaType.APPLICATION_JSON);
438 headers.set("Content-Type", MediaType.APPLICATION_JSON);
439 HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
441 UriComponentsBuilder builder;
442 ResponseEntity<String> response;
446 request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
447 builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
448 "/onap/so/infra/orchestrationRequests/v7/" + "5ffbabd6-b793-4377-a1ab-082670fbc7ac" + "/unlock"));
450 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
451 // Cannot assert anything further here, already have a wiremock in place
452 // which ensures that the post was
453 // properly called to update.
457 public void mapRequestProcessingDataTest() throws JsonParseException, JsonMappingException, IOException {
458 RequestProcessingData entry = new RequestProcessingData();
459 RequestProcessingData secondEntry = new RequestProcessingData();
460 List<HashMap<String, String>> expectedList = new ArrayList<>();
461 HashMap<String, String> expectedMap = new HashMap<>();
462 List<HashMap<String, String>> secondExpectedList = new ArrayList<>();
463 HashMap<String, String> secondExpectedMap = new HashMap<>();
464 List<RequestProcessingData> expectedDataList = new ArrayList<>();
465 entry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
466 entry.setTag("pincFabricConfigRequest");
467 expectedMap.put("requestAction", "assign");
468 expectedMap.put("pincFabricId", "testId");
469 expectedList.add(expectedMap);
470 entry.setDataPairs(expectedList);
471 secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715");
472 secondEntry.setTag("pincFabricConfig");
473 secondExpectedMap.put("requestAction", "unassign");
474 secondExpectedList.add(secondExpectedMap);
475 secondEntry.setDataPairs(secondExpectedList);
476 expectedDataList.add(entry);
477 expectedDataList.add(secondEntry);
479 List<org.onap.so.db.request.beans.RequestProcessingData> processingData = new ArrayList<>();
480 List<RequestProcessingData> actualProcessingData = new ArrayList<>();
481 ObjectMapper mapper = new ObjectMapper();
483 mapper.readValue(new File("src/test/resources/OrchestrationRequest/RequestProcessingData.json"),
484 new TypeReference<List<org.onap.so.db.request.beans.RequestProcessingData>>() {});
485 actualProcessingData = orchReq.mapRequestProcessingData(processingData);
486 assertThat(actualProcessingData, sameBeanAs(expectedDataList));
490 public void setupTestGetOrchestrationRequest() throws Exception {
491 // For testGetOrchestrationRequest
492 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018"))
493 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
494 .withBody(new String(Files.readAllBytes(
495 Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequest.json"))))
496 .withStatus(HttpStatus.SC_OK)));
498 .stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"))
499 .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-1a18-42e5-965d-8ea592502018"))
500 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
501 .withBody(new String(Files.readAllBytes(Paths
502 .get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
503 .withStatus(HttpStatus.SC_OK)));
506 public void setupTestGetOrchestrationRequestInstanceGroup() throws Exception {
507 // For testGetOrchestrationRequest
508 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018"))
509 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
510 .withBody(new String(Files.readAllBytes(Paths.get(
511 "src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json"))))
512 .withStatus(HttpStatus.SC_OK)));
514 .stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"))
515 .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-1a18-42e5-965d-8ea592502018"))
516 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
517 .withBody(new String(Files.readAllBytes(Paths
518 .get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
519 .withStatus(HttpStatus.SC_OK)));
522 private void setupTestGetOrchestrationRequestRequestDetails(String requestId, String status) throws Exception {
523 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse()
524 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
525 .withBody(new String(Files.readAllBytes(
526 Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequestDetails.json"))))
527 .withStatus(HttpStatus.SC_OK)));
530 private void setupTestGetOrchestrationRequestOpenstackDetails(String requestId, String status) throws Exception {
531 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse()
532 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
533 .withBody(new String(Files.readAllBytes(Paths
534 .get("src/test/resources/OrchestrationRequest/getOrchestrationOpenstackRequestDetails.json"))))
535 .withStatus(HttpStatus.SC_OK)));
538 private void setupTestUnlockOrchestrationRequest(String requestId, String status) {
539 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId)))
540 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
541 .withBody(String.format(getResponseTemplate, requestId, status)).withStatus(HttpStatus.SC_OK)));
544 private void setupTestUnlockOrchestrationRequest_invalid_Json() {
545 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(INVALID_REQUEST_ID))).willReturn(aResponse()
546 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_NOT_FOUND)));
550 private void setupTestUnlockOrchestrationRequest_Valid_Status(String requestID, String status) {
551 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestID)))
552 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
553 .withBody(String.format(getResponseTemplate, requestID, status)).withStatus(HttpStatus.SC_OK)));
555 wireMockServer.stubFor(post(urlPathEqualTo(getTestUrl("")))
556 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
557 .withBody(String.format(infraActivePost, requestID)).withStatus(HttpStatus.SC_OK)));
560 private void setupTestGetOrchestrationRequestFilter() throws Exception {
561 // for testGetOrchestrationRequestFilter();
562 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"))
563 .withRequestBody(equalToJson("{\"modelType\":[\"EQUALS\",\"vfModule\"]}"))
564 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
565 .withBody(new String(Files.readAllBytes(
566 Paths.get("src/test/resources/OrchestrationRequest/getRequestDetailsFilter.json"))))
567 .withStatus(HttpStatus.SC_OK)));