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 com.fasterxml.jackson.databind.DeserializationFeature;
24 import org.apache.http.HttpStatus;
25 import org.glassfish.jersey.client.ClientConfig;
26 import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider;
27 import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider;
28 import org.glassfish.jersey.server.ResourceConfig;
29 import org.junit.Test;
30 import org.openecomp.sdc.be.dao.api.ActionStatus;
31 import org.openecomp.sdc.be.impl.ComponentsUtils;
32 import org.openecomp.sdc.exception.ResponseFormat;
33 import org.springframework.context.annotation.Bean;
34 import org.springframework.context.annotation.Import;
36 import javax.ws.rs.core.Response;
38 import static org.junit.Assert.assertEquals;
39 import static org.mockito.Mockito.mock;
40 import static org.mockito.Mockito.when;
42 public class ExceptionHandlerEndpointTest extends JerseySpringBaseTest {
44 private static ComponentsUtils componentUtils;
46 @org.springframework.context.annotation.Configuration
47 @Import(BaseTestConfig.class)
48 static class ExceptionHandlerConfig {
51 ExceptionHandlerEndpoint exceptionHandlerEndpoint() {
52 return new ExceptionHandlerEndpoint(componentUtils);
57 protected void configureClient(ClientConfig config) {
58 final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider()
59 .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
60 config.register(jacksonJsonProvider);
64 protected ResourceConfig configure() {
65 componentUtils = mock(ComponentsUtils.class);
67 return super.configure(ExceptionHandlerConfig.class)
68 .register(ExceptionHandlerEndpoint.class);
72 public void getHandleException() {
73 when(componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(new ResponseFormat(HttpStatus.SC_INTERNAL_SERVER_ERROR));
74 Response response = target().path("/v1/catalog/handleException").request().get(Response.class);
75 assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());