e80fd9e6908d29416f233c5117191ba1c671b23b
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra;
22
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;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class RequestHandlerUtilsUnitTest {
38
39     @Spy
40     private RequestHandlerUtils requestHandler;
41
42     private static final String CURRENT_REQUEST_ID = "eca3a1b1-43ab-457e-ab1c-367263d148b4";
43     private static final String SERVICE_INSTANCE_ID = "00032ab7-na18-42e5-965d-8ea592502018";
44     private final Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
45     private String requestUri =
46             "http:localhost:6746/onap/so/infra/orchestrationRequests/v7/00032ab7-na18-42e5-965d-8ea592502019/resume";
47     private InfraActiveRequests infraActiveRequest = new InfraActiveRequests();
48     private InfraActiveRequests currentActiveRequest = new InfraActiveRequests();
49     private InfraActiveRequests currentActiveRequestIARNull = new InfraActiveRequests();
50
51     public String getRequestBody(String request) throws IOException {
52         request = "src/test/resources/ResumeOrchestrationRequest" + request;
53         return new String(Files.readAllBytes(Paths.get(request)));
54     }
55
56     @Before
57     public void setup() throws IOException {
58         setInfraActiveRequest();
59         setCurrentActiveRequest();
60         setCurrentActiveRequestNullInfraActive();
61     }
62
63     private void setInfraActiveRequest() throws IOException {
64         infraActiveRequest.setTenantId("tenant-id");
65         infraActiveRequest.setRequestBody(getRequestBody("/RequestBody.json"));
66         infraActiveRequest.setAicCloudRegion("cloudRegion");
67         infraActiveRequest.setRequestScope("service");
68         infraActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID);
69         infraActiveRequest.setServiceInstanceName("serviceInstanceName");
70         infraActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString());
71         infraActiveRequest.setRequestAction(Action.createInstance.toString());
72         infraActiveRequest.setServiceType("serviceType");
73     }
74
75     private void setCurrentActiveRequest() throws IOException {
76         currentActiveRequest.setRequestId(CURRENT_REQUEST_ID);
77         currentActiveRequest.setSource("VID");
78         currentActiveRequest.setStartTime(startTimeStamp);
79         currentActiveRequest.setTenantId("tenant-id");
80         currentActiveRequest.setRequestBody(getRequestBody("/RequestBody.json"));
81         currentActiveRequest.setAicCloudRegion("cloudRegion");
82         currentActiveRequest.setRequestScope("service");
83         currentActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID);
84         currentActiveRequest.setServiceInstanceName("serviceInstanceName");
85         currentActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString());
86         currentActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
87         currentActiveRequest.setRequestAction(Action.createInstance.toString());
88         currentActiveRequest.setRequestUrl(requestUri);
89         currentActiveRequest.setRequestorId("xxxxxx");
90         currentActiveRequest.setProgress(new Long(5));
91     }
92
93     private void setCurrentActiveRequestNullInfraActive() throws IOException {
94         currentActiveRequestIARNull.setRequestId(CURRENT_REQUEST_ID);
95         currentActiveRequestIARNull.setSource("VID");
96         currentActiveRequestIARNull.setStartTime(startTimeStamp);
97         currentActiveRequestIARNull.setRequestStatus(Status.IN_PROGRESS.toString());
98         currentActiveRequestIARNull.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
99         currentActiveRequestIARNull.setRequestUrl(requestUri);
100         currentActiveRequestIARNull.setRequestorId("xxxxxx");
101         currentActiveRequestIARNull.setProgress(new Long(5));
102     }
103
104
105     @Test
106     public void createNewRecordCopyFromInfraActiveRequestTest() {
107         InfraActiveRequests result = requestHandler.createNewRecordCopyFromInfraActiveRequest(infraActiveRequest,
108                 CURRENT_REQUEST_ID, startTimeStamp, "VID", requestUri, "xxxxxx");
109         assertThat(currentActiveRequest, sameBeanAs(result));
110     }
111
112     @Test
113     public void createNewRecordCopyFromInfraActiveRequestNullIARTest() {
114         InfraActiveRequests result = requestHandler.createNewRecordCopyFromInfraActiveRequest(null, CURRENT_REQUEST_ID,
115                 startTimeStamp, "VID", requestUri, "xxxxxx");
116         assertThat(currentActiveRequestIARNull, sameBeanAs(result));
117     }
118 }