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.exceptions.ValidationException;
55 import org.onap.so.serviceinstancebeans.CloudRequestData;
56 import org.onap.so.serviceinstancebeans.GetOrchestrationListResponse;
57 import org.onap.so.serviceinstancebeans.GetOrchestrationResponse;
58 import org.onap.so.serviceinstancebeans.Request;
59 import org.onap.so.serviceinstancebeans.RequestError;
60 import org.onap.so.serviceinstancebeans.RequestProcessingData;
61 import org.onap.so.serviceinstancebeans.ServiceException;
62 import org.springframework.beans.factory.annotation.Autowired;
63 import org.springframework.http.HttpEntity;
64 import org.springframework.http.HttpHeaders;
65 import org.springframework.http.HttpMethod;
66 import org.springframework.http.ResponseEntity;
67 import org.springframework.web.util.UriComponentsBuilder;
68 import com.fasterxml.jackson.core.JsonParseException;
69 import com.fasterxml.jackson.core.type.TypeReference;
70 import com.fasterxml.jackson.databind.JsonMappingException;
71 import com.fasterxml.jackson.databind.ObjectMapper;
73 public class OrchestrationRequestsTest extends BaseTest {
75 private RequestsDbClient requestsDbClient;
78 private OrchestrationRequests orchReq;
80 private static final GetOrchestrationListResponse ORCHESTRATION_LIST = generateOrchestrationList();
81 private static final String INVALID_REQUEST_ID = "invalid-request-id";
83 private static GetOrchestrationListResponse generateOrchestrationList() {
84 GetOrchestrationListResponse list = null;
86 ObjectMapper mapper = new ObjectMapper();
87 list = mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationList.json"),
88 GetOrchestrationListResponse.class);
89 } catch (JsonParseException jpe) {
90 jpe.printStackTrace();
91 } catch (JsonMappingException jme) {
92 jme.printStackTrace();
93 } catch (IOException ioe) {
94 ioe.printStackTrace();
100 public void setup() throws IOException {
101 wireMockServer.stubFor(get(urlMatching("/sobpmnengine/history/process-instance.*")).willReturn(aResponse()
102 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
103 .withBody(new String(Files.readAllBytes(
104 Paths.get("src/test/resources/OrchestrationRequest/ProcessInstanceHistoryResponse.json"))))
105 .withStatus(org.apache.http.HttpStatus.SC_OK)));
106 wireMockServer.stubFor(get(
107 ("/sobpmnengine/history/activity-instance?processInstanceId=c2fd4066-a26e-11e9-b144-0242ac14000b&maxResults=1"))
108 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
109 .withBody(new String(Files.readAllBytes(Paths.get(
110 "src/test/resources/OrchestrationRequest/ActivityInstanceHistoryResponse.json"))))
111 .withStatus(HttpStatus.SC_OK)));
112 wireMockServer.stubFor(get(
113 ("/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc?SO_REQUEST_ID=00032ab7-1a18-42e5-965d-8ea592502018&IS_INTERNAL_DATA=false"))
114 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
115 .withBody(new String(Files.readAllBytes(Paths.get(
116 "src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json"))))
117 .withStatus(HttpStatus.SC_OK)));
118 wireMockServer.stubFor(get(
119 ("/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc?SO_REQUEST_ID=00032ab7-3fb3-42e5-965d-8ea592502017&IS_INTERNAL_DATA=false"))
120 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
121 .withBody(new String(Files.readAllBytes(Paths.get(
122 "src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json"))))
123 .withStatus(HttpStatus.SC_OK)));
127 public void testGetOrchestrationRequest() throws Exception {
128 setupTestGetOrchestrationRequest();
129 // TEST VALID REQUEST
130 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
132 Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
133 testResponse.setRequest(request);
134 testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>());
135 RequestProcessingData e = new RequestProcessingData();
136 e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
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.build().toUri(), 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.build().toUri(), 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 List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
214 HashMap<String, String> data1 = new HashMap<String, String>();
215 data1.put("requestAction", "assign");
217 e.setDataPairs(data);
218 testResponse.getRequest().getRequestProcessingData().add(e);
219 String testRequestId = request.getRequestId();
220 HttpHeaders headers = new HttpHeaders();
221 headers.set("Accept", MediaType.APPLICATION_JSON);
222 headers.set("Content-Type", MediaType.APPLICATION_JSON);
223 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
225 UriComponentsBuilder builder = UriComponentsBuilder
226 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
228 ResponseEntity<GetOrchestrationResponse> response =
229 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
231 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
232 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime")
233 .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
237 public void testGetOrchestrationRequestWithOpenstackDetails() throws Exception {
238 setupTestGetOrchestrationRequestOpenstackDetails("00032ab7-3fb3-42e5-965d-8ea592502017", "COMPLETED");
239 // Test request with modelInfo request body
240 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
242 Request request = ORCHESTRATION_LIST.getRequestList().get(0).getRequest();
243 List<CloudRequestData> cloudRequestData = new ArrayList<>();
244 CloudRequestData cloudData = new CloudRequestData();
245 cloudData.setCloudIdentifier("heatstackName/123123");
246 ObjectMapper mapper = new ObjectMapper();
247 Object reqData = mapper.readValue(
248 "{\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}",
250 cloudData.setCloudRequest(reqData);
251 cloudRequestData.add(cloudData);
252 request.setCloudRequestData(cloudRequestData);
253 testResponse.setRequest(request);
254 String testRequestId = request.getRequestId();
255 testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>());
256 RequestProcessingData e = new RequestProcessingData();
257 e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
258 List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
259 HashMap<String, String> data1 = new HashMap<String, String>();
260 data1.put("requestAction", "assign");
262 e.setDataPairs(data);
263 testResponse.getRequest().getRequestProcessingData().add(e);
265 HttpHeaders headers = new HttpHeaders();
266 headers.set("Accept", MediaType.APPLICATION_JSON);
267 headers.set("Content-Type", MediaType.APPLICATION_JSON);
268 headers.set(ONAPLogConstants.Headers.REQUEST_ID, "0321e28d-3dde-4b31-9b28-1e0f07231b93");
269 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
271 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
272 "/onap/so/infra/orchestrationRequests/v7/" + testRequestId + "?includeCloudRequest=true"));
274 ResponseEntity<GetOrchestrationResponse> response =
275 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
276 System.out.println("Response :" + response.getBody().toString());
277 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
279 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime")
280 .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
281 assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
282 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
283 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
284 assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
285 assertEquals("0321e28d-3dde-4b31-9b28-1e0f07231b93", response.getHeaders().get("X-TransactionID").get(0));
289 public void testGetOrchestrationRequestNoRequestID() {
290 HttpHeaders headers = new HttpHeaders();
291 headers.set("Accept", "application/json; charset=UTF-8");
292 headers.set("Content-Type", "application/json; charset=UTF-8");
293 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
294 UriComponentsBuilder builder =
295 UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v6/"));
297 ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
298 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
299 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
303 public void testGetOrchestrationRequestInvalidRequestID() throws Exception {
304 setupTestGetOrchestrationRequest();
305 // TEST INVALID REQUESTID
306 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
308 Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
309 testResponse.setRequest(request);
310 String testRequestId = "00032ab7-pfb3-42e5-965d-8ea592502016";
311 HttpHeaders headers = new HttpHeaders();
312 headers.set("Accept", MediaType.APPLICATION_JSON);
313 headers.set("Content-Type", MediaType.APPLICATION_JSON);
314 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
316 UriComponentsBuilder builder = UriComponentsBuilder
317 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
319 ResponseEntity<GetOrchestrationResponse> response =
320 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
322 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
326 public void testGetOrchestrationRequestFilter() throws Exception {
327 setupTestGetOrchestrationRequestFilter();
328 List<String> values = new ArrayList<>();
329 values.add("EQUALS");
330 values.add("vfModule");
332 ObjectMapper mapper = new ObjectMapper();
333 GetOrchestrationListResponse testResponse =
334 mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json"),
335 GetOrchestrationListResponse.class);
337 Map<String, List<String>> orchestrationMap = new HashMap<>();
338 orchestrationMap.put("modelType", values);
340 List<InfraActiveRequests> requests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap);
341 HttpHeaders headers = new HttpHeaders();
342 headers.set("Accept", MediaType.APPLICATION_JSON);
343 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
345 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(
346 createURLWithPort("/onap/so/infra/orchestrationRequests/v6?filter=modelType:EQUALS:vfModule"));
348 ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
349 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
350 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("requestList.request.startTime")
351 .ignoring("requestList.request.finishTime").ignoring("requestList.request.requestStatus.timeStamp"));
352 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
353 assertEquals(requests.size(), response.getBody().getRequestList().size());
358 public void testUnlockOrchestrationRequest() throws Exception {
359 setupTestUnlockOrchestrationRequest("0017f68c-eb2d-45bb-b7c7-ec31b37dc349", "UNLOCKED");
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;
375 expectedRequestError = new RequestError();
376 se = new ServiceException();
377 se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
379 "Orchestration RequestId 0017f68c-eb2d-45bb-b7c7-ec31b37dc349 has a status of UNLOCKED and can not be unlocked");
380 expectedRequestError.setServiceException(se);
382 builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
383 "/onap/so/infra/orchestrationRequests/v6/0017f68c-eb2d-45bb-b7c7-ec31b37dc349/unlock"));
385 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
386 actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
388 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
389 assertThat(actualRequestError, sameBeanAs(expectedRequestError));
393 public void testUnlockOrchestrationRequest_invalid_Json() throws Exception {
394 setupTestUnlockOrchestrationRequest_invalid_Json();
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;
405 RequestError expectedRequestError;
406 RequestError actualRequestError;
409 // Test invalid requestId
410 expectedRequestError = new RequestError();
411 se = new ServiceException();
412 se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
413 se.setText("Null response from RequestDB when searching by RequestId " + INVALID_REQUEST_ID);
414 expectedRequestError.setServiceException(se);
416 builder = UriComponentsBuilder.fromHttpUrl(
417 createURLWithPort("/onap/so/infra/orchestrationRequests/v6/" + INVALID_REQUEST_ID + "/unlock"));
419 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
420 actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
422 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
423 assertThat(expectedRequestError, sameBeanAs(actualRequestError));
427 public void testUnlockOrchestrationRequest_Valid_Status()
428 throws JsonParseException, JsonMappingException, IOException, ValidationException {
429 setupTestUnlockOrchestrationRequest_Valid_Status("5ffbabd6-b793-4377-a1ab-082670fbc7ac", "PENDING");
431 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
432 HttpHeaders headers = new HttpHeaders();
433 headers.set("Accept", MediaType.APPLICATION_JSON);
434 headers.set("Content-Type", MediaType.APPLICATION_JSON);
435 HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
437 UriComponentsBuilder builder;
438 ResponseEntity<String> response;
442 request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
443 builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
444 "/onap/so/infra/orchestrationRequests/v7/" + "5ffbabd6-b793-4377-a1ab-082670fbc7ac" + "/unlock"));
446 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
447 // Cannot assert anything further here, already have a wiremock in place
448 // which ensures that the post was
449 // properly called to update.
453 public void mapRequestProcessingDataTest() throws JsonParseException, JsonMappingException, IOException {
454 RequestProcessingData entry = new RequestProcessingData();
455 RequestProcessingData secondEntry = new RequestProcessingData();
456 List<HashMap<String, String>> expectedList = new ArrayList<>();
457 HashMap<String, String> expectedMap = new HashMap<>();
458 List<HashMap<String, String>> secondExpectedList = new ArrayList<>();
459 HashMap<String, String> secondExpectedMap = new HashMap<>();
460 List<RequestProcessingData> expectedDataList = new ArrayList<>();
461 entry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
462 expectedMap.put("requestAction", "assign");
463 expectedMap.put("fabricId", "testId");
464 expectedList.add(expectedMap);
465 entry.setDataPairs(expectedList);
466 secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715");
467 secondExpectedMap.put("requestAction", "unassign");
468 secondExpectedList.add(secondExpectedMap);
469 secondEntry.setDataPairs(secondExpectedList);
470 expectedDataList.add(entry);
471 expectedDataList.add(secondEntry);
473 List<org.onap.so.db.request.beans.RequestProcessingData> processingData = new ArrayList<>();
474 List<RequestProcessingData> actualProcessingData = new ArrayList<>();
475 ObjectMapper mapper = new ObjectMapper();
477 mapper.readValue(new File("src/test/resources/OrchestrationRequest/RequestProcessingData.json"),
478 new TypeReference<List<org.onap.so.db.request.beans.RequestProcessingData>>() {});
479 actualProcessingData = orchReq.mapRequestProcessingData(processingData);
480 assertThat(actualProcessingData, sameBeanAs(expectedDataList));
484 public void testThatActiveRequestsExceptionsAreMapped() throws Exception {
485 String testRequestId = UUID.randomUUID().toString();
486 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/" + testRequestId))
487 .willReturn(aResponse().withStatus(HttpStatus.SC_UNAUTHORIZED)));
489 HttpHeaders headers = new HttpHeaders();
490 headers.set("Accept", MediaType.APPLICATION_JSON);
491 headers.set("Content-Type", MediaType.APPLICATION_JSON);
492 headers.set(ONAPLogConstants.Headers.REQUEST_ID, "1e45215d-b7b3-4c5a-9316-65bdddaf649f");
493 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
495 UriComponentsBuilder builder = UriComponentsBuilder
496 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
498 ResponseEntity<GetOrchestrationResponse> response =
499 restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
501 assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), response.getStatusCode().value());
504 public void setupTestGetOrchestrationRequest() throws Exception {
505 // For testGetOrchestrationRequest
506 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018"))
507 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
508 .withBody(new String(Files.readAllBytes(
509 Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequest.json"))))
510 .withStatus(HttpStatus.SC_OK)));
511 wireMockServer.stubFor(get(urlPathEqualTo(
512 "/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc/"))
513 .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-1a18-42e5-965d-8ea592502018"))
514 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
515 .withBody(new String(Files.readAllBytes(Paths
516 .get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
517 .withStatus(HttpStatus.SC_OK)));
520 public void setupTestGetOrchestrationRequestInstanceGroup() throws Exception {
521 // For testGetOrchestrationRequest
522 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018"))
523 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
524 .withBody(new String(Files.readAllBytes(Paths.get(
525 "src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json"))))
526 .withStatus(HttpStatus.SC_OK)));
527 wireMockServer.stubFor(get(urlPathEqualTo(
528 "/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc/"))
529 .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-1a18-42e5-965d-8ea592502018"))
530 .withQueryParam("IS_INTERNAL_DATA", equalTo("false"))
531 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
532 .withBody(new String(Files.readAllBytes(Paths
533 .get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
534 .withStatus(HttpStatus.SC_OK)));
537 private void setupTestGetOrchestrationRequestRequestDetails(String requestId, String status) throws Exception {
538 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse()
539 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
540 .withBody(new String(Files.readAllBytes(
541 Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequestDetails.json"))))
542 .withStatus(HttpStatus.SC_OK)));
545 private void setupTestGetOrchestrationRequestOpenstackDetails(String requestId, String status) throws Exception {
546 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse()
547 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
548 .withBody(new String(Files.readAllBytes(Paths
549 .get("src/test/resources/OrchestrationRequest/getOrchestrationOpenstackRequestDetails.json"))))
550 .withStatus(HttpStatus.SC_OK)));
553 private void setupTestUnlockOrchestrationRequest(String requestId, String status) {
554 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId)))
555 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
556 .withBody(String.format(getResponseTemplate, requestId, status)).withStatus(HttpStatus.SC_OK)));
559 private void setupTestUnlockOrchestrationRequest_invalid_Json() {
560 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(INVALID_REQUEST_ID))).willReturn(aResponse()
561 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_NOT_FOUND)));
565 private void setupTestUnlockOrchestrationRequest_Valid_Status(String requestID, String status) {
566 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestID)))
567 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
568 .withBody(String.format(getResponseTemplate, requestID, status)).withStatus(HttpStatus.SC_OK)));
570 wireMockServer.stubFor(post(urlPathEqualTo(getTestUrl("")))
571 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
572 .withBody(String.format(infraActivePost, requestID)).withStatus(HttpStatus.SC_OK)));
575 private void setupTestGetOrchestrationRequestFilter() throws Exception {
576 // for testGetOrchestrationRequestFilter();
577 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"))
578 .withRequestBody(equalToJson("{\"modelType\":[\"EQUALS\",\"vfModule\"]}"))
579 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
580 .withBody(new String(Files.readAllBytes(
581 Paths.get("src/test/resources/OrchestrationRequest/getRequestDetailsFilter.json"))))
582 .withStatus(HttpStatus.SC_OK)));