2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.apihandlerinfra;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.any;
25 import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
26 import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
27 import static com.github.tomakehurst.wiremock.client.WireMock.get;
28 import static com.github.tomakehurst.wiremock.client.WireMock.post;
29 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
30 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
31 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
32 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertNotNull;
36 import java.io.IOException;
37 import java.nio.file.Files;
38 import java.nio.file.Paths;
39 import java.util.ArrayList;
40 import java.util.HashMap;
41 import java.util.List;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
45 import org.apache.http.HttpStatus;
46 import org.junit.Before;
47 import org.junit.Test;
48 import org.onap.logging.ref.slf4j.ONAPLogConstants;
49 import org.onap.so.apihandler.common.ErrorNumbers;
50 import org.onap.so.db.request.beans.InfraActiveRequests;
51 import org.onap.so.db.request.client.RequestsDbClient;
52 import org.onap.so.exceptions.ValidationException;
53 import org.onap.so.serviceinstancebeans.CloudRequestData;
54 import org.onap.so.serviceinstancebeans.GetOrchestrationListResponse;
55 import org.onap.so.serviceinstancebeans.GetOrchestrationResponse;
56 import org.onap.so.serviceinstancebeans.Request;
57 import org.onap.so.serviceinstancebeans.RequestError;
58 import org.onap.so.serviceinstancebeans.RequestProcessingData;
59 import org.onap.so.serviceinstancebeans.ServiceException;
60 import org.springframework.beans.factory.annotation.Autowired;
61 import org.springframework.http.HttpEntity;
62 import org.springframework.http.HttpHeaders;
63 import org.springframework.http.HttpMethod;
64 import org.springframework.http.ResponseEntity;
65 import org.springframework.web.util.UriComponentsBuilder;
66 import com.fasterxml.jackson.core.JsonParseException;
67 import com.fasterxml.jackson.core.type.TypeReference;
68 import com.fasterxml.jackson.databind.JsonMappingException;
69 import com.fasterxml.jackson.databind.ObjectMapper;
71 public class OrchestrationRequestsTest extends BaseTest {
73 private RequestsDbClient requestsDbClient;
76 private OrchestrationRequests orchReq;
78 private static final GetOrchestrationListResponse ORCHESTRATION_LIST = generateOrchestrationList();
79 private static final String INVALID_REQUEST_ID = "invalid-request-id";
81 private static GetOrchestrationListResponse generateOrchestrationList() {
82 GetOrchestrationListResponse list = null;
84 ObjectMapper mapper = new ObjectMapper();
85 list = mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationList.json"),
86 GetOrchestrationListResponse.class);
87 } catch (JsonParseException jpe) {
88 jpe.printStackTrace();
89 } catch (JsonMappingException jme) {
90 jme.printStackTrace();
91 } catch (IOException ioe) {
92 ioe.printStackTrace();
98 public void setup() throws IOException {
99 wireMockServer.stubFor(get(urlMatching("/sobpmnengine/history/process-instance.*")).willReturn(aResponse()
100 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
101 .withBody(new String(Files.readAllBytes(
102 Paths.get("src/test/resources/OrchestrationRequest/ProcessInstanceHistoryResponse.json"))))
103 .withStatus(org.apache.http.HttpStatus.SC_OK)));
104 wireMockServer.stubFor(
105 get(("/sobpmnengine/history/activity-instance?processInstanceId=c4c6b647-a26e-11e9-b144-0242ac14000b"))
106 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
107 .withBody(new String(Files.readAllBytes(Paths.get(
108 "src/test/resources/OrchestrationRequest/ActivityInstanceHistoryResponse.json"))))
109 .withStatus(HttpStatus.SC_OK)));
110 wireMockServer.stubFor(get(
111 ("/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc?SO_REQUEST_ID=00032ab7-1a18-42e5-965d-8ea592502018&IS_INTERNAL_DATA=false"))
112 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
113 .withBody(new String(Files.readAllBytes(Paths.get(
114 "src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json"))))
115 .withStatus(HttpStatus.SC_OK)));
116 wireMockServer.stubFor(get(
117 ("/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc?SO_REQUEST_ID=00032ab7-3fb3-42e5-965d-8ea592502017&IS_INTERNAL_DATA=false"))
118 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
119 .withBody(new String(Files.readAllBytes(Paths.get(
120 "src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json"))))
121 .withStatus(HttpStatus.SC_OK)));
125 public void testGetOrchestrationRequest() throws Exception {
126 setupTestGetOrchestrationRequest();
127 // TEST VALID REQUEST
128 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
130 Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
131 testResponse.setRequest(request);
132 testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>());
133 RequestProcessingData e = new RequestProcessingData();
134 e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
135 e.setTag("pincFabricConfigRequest");
136 List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
137 HashMap<String, String> data1 = new HashMap<String, String>();
138 data1.put("requestAction", "assign");
140 e.setDataPairs(data);
141 testResponse.getRequest().getRequestProcessingData().add(e);
142 String testRequestId = request.getRequestId();
143 HttpHeaders headers = new HttpHeaders();
144 headers.set("Accept", MediaType.APPLICATION_JSON);
145 headers.set("Content-Type", MediaType.APPLICATION_JSON);
146 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.toUriString(), 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 assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
159 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
160 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
161 assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
162 assertEquals("1e45215d-b7b3-4c5a-9316-65bdddaf649f", response.getHeaders().get("X-TransactionID").get(0));
163 assertNotNull(response.getBody().getRequest().getFinishTime());
167 public void getOrchestrationRequestSimpleTest() throws Exception {
168 setupTestGetOrchestrationRequest();
169 // TEST VALID REQUEST
170 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
172 Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
173 request.setRequestProcessingData(null);
174 testResponse.setRequest(request);
176 String testRequestId = request.getRequestId();
177 HttpHeaders headers = new HttpHeaders();
178 headers.set("Accept", MediaType.APPLICATION_JSON);
179 headers.set("Content-Type", MediaType.APPLICATION_JSON);
180 headers.set(ONAPLogConstants.Headers.REQUEST_ID, "e5e3c007-9fe9-4a20-8691-bdd20e14504d");
181 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
182 UriComponentsBuilder builder = UriComponentsBuilder
183 .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId))
184 .queryParam("format", "simple");
186 ResponseEntity<GetOrchestrationResponse> response =
187 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
189 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
190 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime")
191 .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
192 assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
193 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
194 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
195 assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
196 assertEquals("e5e3c007-9fe9-4a20-8691-bdd20e14504d", response.getHeaders().get("X-TransactionID").get(0));
197 assertNotNull(response.getBody().getRequest().getFinishTime());
201 public void testGetOrchestrationRequestInstanceGroup() throws Exception {
202 setupTestGetOrchestrationRequestInstanceGroup();
203 // TEST VALID REQUEST
204 GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
206 Request request = ORCHESTRATION_LIST.getRequestList().get(8).getRequest();
207 testResponse.setRequest(request);
208 testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>());
209 RequestProcessingData e = new RequestProcessingData();
210 e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
211 e.setTag("pincFabricConfigRequest");
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 e.setTag("pincFabricConfigRequest");
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);
339 List<GetOrchestrationResponse> testResponses = new ArrayList<>();
341 List<InfraActiveRequests> requests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap);
342 HttpHeaders headers = new HttpHeaders();
343 headers.set("Accept", MediaType.APPLICATION_JSON);
344 HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
346 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(
347 createURLWithPort("/onap/so/infra/orchestrationRequests/v6?filter=modelType:EQUALS:vfModule"));
349 ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(),
350 HttpMethod.GET, entity, GetOrchestrationListResponse.class);
351 assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("requestList.request.startTime")
352 .ignoring("requestList.request.finishTime").ignoring("requestList.request.requestStatus.timeStamp"));
353 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
354 assertEquals(requests.size(), response.getBody().getRequestList().size());
359 public void testUnlockOrchestrationRequest() throws Exception {
360 setupTestUnlockOrchestrationRequest("0017f68c-eb2d-45bb-b7c7-ec31b37dc349", "UNLOCKED");
361 ObjectMapper mapper = new ObjectMapper();
363 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
364 HttpHeaders headers = new HttpHeaders();
365 headers.set("Accept", MediaType.APPLICATION_JSON);
366 headers.set("Content-Type", MediaType.APPLICATION_JSON);
367 HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
369 UriComponentsBuilder builder;
370 ResponseEntity<String> response;
371 RequestError expectedRequestError;
372 RequestError actualRequestError;
376 expectedRequestError = new RequestError();
377 se = new ServiceException();
378 se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
380 "Orchestration RequestId 0017f68c-eb2d-45bb-b7c7-ec31b37dc349 has a status of UNLOCKED and can not be unlocked");
381 expectedRequestError.setServiceException(se);
383 builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
384 "/onap/so/infra/orchestrationRequests/v6/0017f68c-eb2d-45bb-b7c7-ec31b37dc349/unlock"));
386 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
387 actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
389 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
390 assertThat(actualRequestError, sameBeanAs(expectedRequestError));
394 public void testUnlockOrchestrationRequest_invalid_Json() throws Exception {
395 setupTestUnlockOrchestrationRequest_invalid_Json();
396 ObjectMapper mapper = new ObjectMapper();
398 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
399 HttpHeaders headers = new HttpHeaders();
400 headers.set("Accept", MediaType.APPLICATION_JSON);
401 headers.set("Content-Type", MediaType.APPLICATION_JSON);
402 HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
404 UriComponentsBuilder builder;
405 ResponseEntity<String> response;
406 RequestError expectedRequestError;
407 RequestError actualRequestError;
410 // Test invalid requestId
411 expectedRequestError = new RequestError();
412 se = new ServiceException();
413 se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
414 se.setText("Null response from RequestDB when searching by RequestId " + INVALID_REQUEST_ID);
415 expectedRequestError.setServiceException(se);
417 builder = UriComponentsBuilder.fromHttpUrl(
418 createURLWithPort("/onap/so/infra/orchestrationRequests/v6/" + INVALID_REQUEST_ID + "/unlock"));
420 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
421 actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
423 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
424 assertThat(expectedRequestError, sameBeanAs(actualRequestError));
428 public void testUnlockOrchestrationRequest_Valid_Status()
429 throws JsonParseException, JsonMappingException, IOException, ValidationException {
430 setupTestUnlockOrchestrationRequest_Valid_Status("5ffbabd6-b793-4377-a1ab-082670fbc7ac", "PENDING");
431 ObjectMapper mapper = new ObjectMapper();
433 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
434 HttpHeaders headers = new HttpHeaders();
435 headers.set("Accept", MediaType.APPLICATION_JSON);
436 headers.set("Content-Type", MediaType.APPLICATION_JSON);
437 HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
439 UriComponentsBuilder builder;
440 ResponseEntity<String> response;
444 request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
445 builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(
446 "/onap/so/infra/orchestrationRequests/v7/" + "5ffbabd6-b793-4377-a1ab-082670fbc7ac" + "/unlock"));
448 response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
449 // Cannot assert anything further here, already have a wiremock in place
450 // which ensures that the post was
451 // properly called to update.
455 public void mapRequestProcessingDataTest() throws JsonParseException, JsonMappingException, IOException {
456 RequestProcessingData entry = new RequestProcessingData();
457 RequestProcessingData secondEntry = new RequestProcessingData();
458 List<HashMap<String, String>> expectedList = new ArrayList<>();
459 HashMap<String, String> expectedMap = new HashMap<>();
460 List<HashMap<String, String>> secondExpectedList = new ArrayList<>();
461 HashMap<String, String> secondExpectedMap = new HashMap<>();
462 List<RequestProcessingData> expectedDataList = new ArrayList<>();
463 entry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
464 entry.setTag("pincFabricConfigRequest");
465 expectedMap.put("requestAction", "assign");
466 expectedMap.put("pincFabricId", "testId");
467 expectedList.add(expectedMap);
468 entry.setDataPairs(expectedList);
469 secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715");
470 secondEntry.setTag("pincFabricConfig");
471 secondExpectedMap.put("requestAction", "unassign");
472 secondExpectedList.add(secondExpectedMap);
473 secondEntry.setDataPairs(secondExpectedList);
474 expectedDataList.add(entry);
475 expectedDataList.add(secondEntry);
477 List<org.onap.so.db.request.beans.RequestProcessingData> processingData = new ArrayList<>();
478 List<RequestProcessingData> actualProcessingData = new ArrayList<>();
479 ObjectMapper mapper = new ObjectMapper();
481 mapper.readValue(new File("src/test/resources/OrchestrationRequest/RequestProcessingData.json"),
482 new TypeReference<List<org.onap.so.db.request.beans.RequestProcessingData>>() {});
483 actualProcessingData = orchReq.mapRequestProcessingData(processingData);
484 assertThat(actualProcessingData, sameBeanAs(expectedDataList));
488 public void setupTestGetOrchestrationRequest() throws Exception {
489 // For testGetOrchestrationRequest
490 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018"))
491 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
492 .withBody(new String(Files.readAllBytes(
493 Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequest.json"))))
494 .withStatus(HttpStatus.SC_OK)));
496 .stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"))
497 .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-1a18-42e5-965d-8ea592502018"))
498 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
499 .withBody(new String(Files.readAllBytes(Paths
500 .get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json"))))
501 .withStatus(HttpStatus.SC_OK)));
504 public void setupTestGetOrchestrationRequestInstanceGroup() 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(Paths.get(
509 "src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json"))))
510 .withStatus(HttpStatus.SC_OK)));
512 .stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"))
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 private void setupTestGetOrchestrationRequestRequestDetails(String requestId, String status) throws Exception {
521 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse()
522 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
523 .withBody(new String(Files.readAllBytes(
524 Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequestDetails.json"))))
525 .withStatus(HttpStatus.SC_OK)));
528 private void setupTestGetOrchestrationRequestOpenstackDetails(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(Paths
532 .get("src/test/resources/OrchestrationRequest/getOrchestrationOpenstackRequestDetails.json"))))
533 .withStatus(HttpStatus.SC_OK)));
536 private void setupTestUnlockOrchestrationRequest(String requestId, String status) {
537 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId)))
538 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
539 .withBody(String.format(getResponseTemplate, requestId, status)).withStatus(HttpStatus.SC_OK)));
542 private void setupTestUnlockOrchestrationRequest_invalid_Json() {
543 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(INVALID_REQUEST_ID))).willReturn(aResponse()
544 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_NOT_FOUND)));
548 private void setupTestUnlockOrchestrationRequest_Valid_Status(String requestID, String status) {
549 wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestID)))
550 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
551 .withBody(String.format(getResponseTemplate, requestID, status)).withStatus(HttpStatus.SC_OK)));
553 wireMockServer.stubFor(post(urlPathEqualTo(getTestUrl("")))
554 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
555 .withBody(String.format(infraActivePost, requestID)).withStatus(HttpStatus.SC_OK)));
558 private void setupTestGetOrchestrationRequestFilter() throws Exception {
559 // for testGetOrchestrationRequestFilter();
560 wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"))
561 .withRequestBody(equalToJson("{\"modelType\":[\"EQUALS\",\"vfModule\"]}"))
562 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
563 .withBody(new String(Files.readAllBytes(
564 Paths.get("src/test/resources/OrchestrationRequest/getRequestDetailsFilter.json"))))
565 .withStatus(HttpStatus.SC_OK)));