2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.openecomp.sdc.be.servlets;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
27 import com.fasterxml.jackson.databind.DeserializationFeature;
28 import javax.ws.rs.core.Response;
29 import org.apache.http.HttpStatus;
30 import org.glassfish.jersey.client.ClientConfig;
31 import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider;
32 import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider;
33 import org.glassfish.jersey.server.ResourceConfig;
34 import org.glassfish.jersey.test.TestProperties;
35 import org.junit.jupiter.api.AfterEach;
36 import org.junit.jupiter.api.BeforeEach;
37 import org.junit.jupiter.api.Test;
38 import org.openecomp.sdc.be.dao.api.ActionStatus;
39 import org.openecomp.sdc.be.impl.ComponentsUtils;
40 import org.openecomp.sdc.exception.ResponseFormat;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Import;
44 class ExceptionHandlerEndpointTest extends JerseySpringBaseTest {
46 private static ComponentsUtils componentUtils;
48 @org.springframework.context.annotation.Configuration
49 @Import(BaseTestConfig.class)
50 static class ExceptionHandlerConfig {
53 ExceptionHandlerEndpoint exceptionHandlerEndpoint() {
54 return new ExceptionHandlerEndpoint(componentUtils);
59 public void before() throws Exception {
64 void after() throws Exception {
69 protected void configureClient(ClientConfig config) {
70 final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider()
71 .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
72 config.register(jacksonJsonProvider);
76 protected ResourceConfig configure() {
77 forceSet(TestProperties.CONTAINER_PORT, "0");
78 componentUtils = mock(ComponentsUtils.class);
80 return super.configure(ExceptionHandlerConfig.class)
81 .register(ExceptionHandlerEndpoint.class);
85 void getHandleException() {
86 when(componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR))
87 .thenReturn(new ResponseFormat(HttpStatus.SC_INTERNAL_SERVER_ERROR));
88 Response response = target().path("/v1/catalog/handleException").request().get(Response.class);
89 assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());