d39192cdf0a0846ccd0a1722df504aaa4c463cc3
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 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.infra.rest.handler;
22
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import static org.mockito.Mockito.doReturn;
26 import java.net.MalformedURLException;
27 import java.net.URL;
28 import java.util.Optional;
29 import javax.ws.rs.container.ContainerRequestContext;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.Spy;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.so.apihandlerinfra.infra.rest.handler.AbstractRestHandler;
36 import org.onap.so.serviceinstancebeans.RequestReferences;
37 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
38
39 @RunWith(MockitoJUnitRunner.class)
40 public class AbstractRestHandlerTest {
41
42     @Spy
43     AbstractRestHandler restHandler;
44
45     @Mock
46     ContainerRequestContext mockRequestContext;
47
48     @Test
49     public void test_createResponse() throws MalformedURLException {
50         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
51         RequestReferences requestReferences = new RequestReferences();
52         URL selfLinkURL = new URL("http://localhost:8080/v1");
53         requestReferences.setInstanceId("instanceId");
54         requestReferences.setRequestId("requestId");
55         requestReferences.setRequestSelfLink(selfLinkURL);
56         expectedResponse.setRequestReferences(requestReferences);
57
58         doReturn("http://localhost:8080/v1").when(restHandler).getRequestUri(mockRequestContext);
59         doReturn(Optional.of(selfLinkURL)).when(restHandler).buildSelfLinkUrl("http://localhost:8080/v1", "requestId");
60         ServiceInstancesResponse actualResponse =
61                 restHandler.createResponse("instanceId", "requestId", mockRequestContext);
62         assertThat(actualResponse, sameBeanAs(expectedResponse));
63     }
64 }