2 * ============LICENSE_START=======================================================
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
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.infra.rest.handler;
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;
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.serviceinstancebeans.RequestReferences;
36 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
38 @RunWith(MockitoJUnitRunner.class)
39 public class AbstractRestHandlerTest {
42 AbstractRestHandler restHandler;
45 ContainerRequestContext mockRequestContext;
48 public void test_createResponse() throws MalformedURLException {
49 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
50 RequestReferences requestReferences = new RequestReferences();
51 URL selfLinkURL = new URL("http://localhost:8080/v1");
52 requestReferences.setInstanceId("instanceId");
53 requestReferences.setRequestId("requestId");
54 requestReferences.setRequestSelfLink(selfLinkURL);
55 expectedResponse.setRequestReferences(requestReferences);
57 doReturn("http://localhost:8080/v1").when(restHandler).getRequestUri(mockRequestContext);
58 doReturn(Optional.of(selfLinkURL)).when(restHandler).buildSelfLinkUrl("http://localhost:8080/v1", "requestId");
59 ServiceInstancesResponse actualResponse =
60 restHandler.createResponse("instanceId", "requestId", mockRequestContext);
61 assertThat(actualResponse, sameBeanAs(expectedResponse));
65 public void test_buildSelfLinkUrl() throws MalformedURLException {
66 String initialLink = "http://some.domain.com:30277/onap/so/infra/serviceInstantiation/v7/serviceInstances";
67 String requestId = "4d0437c3-ee48-4361-a4f7-e1613c82493a";
68 Optional<URL> expectedLink = Optional.of(new URL(
69 "http://some.domain.com:30277/onap/so/infra/orchestrationRequests/v7/4d0437c3-ee48-4361-a4f7-e1613c82493a"));
70 Optional<URL> resultURL = restHandler.buildSelfLinkUrl(initialLink, requestId);
72 assertThat(resultURL, sameBeanAs(expectedLink));