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.apihandlerinfra.infra.rest.handler.AbstractRestHandler;
36 import org.onap.so.serviceinstancebeans.RequestReferences;
37 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
39 @RunWith(MockitoJUnitRunner.class)
40 public class AbstractRestHandlerTest {
43 AbstractRestHandler restHandler;
46 ContainerRequestContext mockRequestContext;
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);
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));
66 public void test_buildSelfLinkUrl() throws MalformedURLException {
67 String initialLink = "http://some.domain.com:30277/onap/so/infra/serviceInstantiation/v7/serviceInstances";
68 String requestId = "4d0437c3-ee48-4361-a4f7-e1613c82493a";
69 Optional<URL> expectedLink = Optional.of(new URL(
70 "http://some.domain.com:30277/onap/so/infra/orchestrationRequests/v7/4d0437c3-ee48-4361-a4f7-e1613c82493a"));
71 Optional<URL> resultURL = restHandler.buildSelfLinkUrl(initialLink, requestId);
73 assertThat(resultURL, sameBeanAs(expectedLink));