2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertThat;
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.sql.Timestamp;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Spy;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.so.db.request.beans.InfraActiveRequests;
36 @RunWith(MockitoJUnitRunner.class)
37 public class RequestHandlerUtilsUnitTest {
40 private RequestHandlerUtils requestHandler;
42 private static final String CURRENT_REQUEST_ID = "eca3a1b1-43ab-457e-ab1c-367263d148b4";
43 private static final String RESUMED_REQUEST_ID = "59c7247f-839f-4923-90c3-05faa3ab354d";
44 private static final String SERVICE_INSTANCE_ID = "00032ab7-na18-42e5-965d-8ea592502018";
45 private final Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
46 private String requestUri =
47 "http:localhost:6746/onap/so/infra/orchestrationRequests/v7/00032ab7-na18-42e5-965d-8ea592502019/resume";
48 private InfraActiveRequests infraActiveRequest = new InfraActiveRequests();
49 private InfraActiveRequests currentActiveRequest = new InfraActiveRequests();
50 private InfraActiveRequests currentActiveRequestIARNull = new InfraActiveRequests();
52 public String getRequestBody(String request) throws IOException {
53 request = "src/test/resources/ResumeOrchestrationRequest" + request;
54 return new String(Files.readAllBytes(Paths.get(request)));
58 public void setup() throws IOException {
59 setInfraActiveRequest();
60 setCurrentActiveRequest();
61 setCurrentActiveRequestNullInfraActive();
64 private void setInfraActiveRequest() throws IOException {
65 infraActiveRequest.setTenantId("tenant-id");
66 infraActiveRequest.setRequestBody(getRequestBody("/RequestBody.json"));
67 infraActiveRequest.setAicCloudRegion("cloudRegion");
68 infraActiveRequest.setRequestScope("service");
69 infraActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID);
70 infraActiveRequest.setServiceInstanceName("serviceInstanceName");
71 infraActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString());
72 infraActiveRequest.setRequestAction(Action.createInstance.toString());
73 infraActiveRequest.setServiceType("serviceType");
76 private void setCurrentActiveRequest() throws IOException {
77 currentActiveRequest.setRequestId(CURRENT_REQUEST_ID);
78 currentActiveRequest.setSource("VID");
79 currentActiveRequest.setStartTime(startTimeStamp);
80 currentActiveRequest.setTenantId("tenant-id");
81 currentActiveRequest.setRequestBody(getRequestBody("/RequestBody.json"));
82 currentActiveRequest.setAicCloudRegion("cloudRegion");
83 currentActiveRequest.setRequestScope("service");
84 currentActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID);
85 currentActiveRequest.setServiceInstanceName("serviceInstanceName");
86 currentActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString());
87 currentActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
88 currentActiveRequest.setRequestAction(Action.createInstance.toString());
89 currentActiveRequest.setRequestUrl(requestUri);
90 currentActiveRequest.setRequestorId("xxxxxx");
91 currentActiveRequest.setProgress(new Long(5));
92 currentActiveRequest.setOriginalRequestId(RESUMED_REQUEST_ID);
95 private void setCurrentActiveRequestNullInfraActive() throws IOException {
96 currentActiveRequestIARNull.setRequestId(CURRENT_REQUEST_ID);
97 currentActiveRequestIARNull.setSource("VID");
98 currentActiveRequestIARNull.setStartTime(startTimeStamp);
99 currentActiveRequestIARNull.setRequestStatus(Status.IN_PROGRESS.toString());
100 currentActiveRequestIARNull.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
101 currentActiveRequestIARNull.setRequestUrl(requestUri);
102 currentActiveRequestIARNull.setRequestorId("xxxxxx");
103 currentActiveRequestIARNull.setProgress(new Long(5));
104 currentActiveRequestIARNull.setOriginalRequestId(RESUMED_REQUEST_ID);
109 public void createNewRecordCopyFromInfraActiveRequestTest() {
110 InfraActiveRequests result = requestHandler.createNewRecordCopyFromInfraActiveRequest(infraActiveRequest,
111 CURRENT_REQUEST_ID, startTimeStamp, "VID", requestUri, "xxxxxx", RESUMED_REQUEST_ID);
112 assertThat(currentActiveRequest, sameBeanAs(result));
116 public void createNewRecordCopyFromInfraActiveRequestNullIARTest() {
117 InfraActiveRequests result = requestHandler.createNewRecordCopyFromInfraActiveRequest(null, CURRENT_REQUEST_ID,
118 startTimeStamp, "VID", requestUri, "xxxxxx", RESUMED_REQUEST_ID);
119 assertThat(currentActiveRequestIARNull, sameBeanAs(result));