Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / servlets / ExceptionHandlerEndpointTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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.openecomp.sdc.be.servlets;
22
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;
35
36 import javax.ws.rs.core.Response;
37
38 import static org.junit.Assert.assertEquals;
39 import static org.mockito.Mockito.mock;
40 import static org.mockito.Mockito.when;
41
42 public class ExceptionHandlerEndpointTest extends JerseySpringBaseTest {
43
44     private static ComponentsUtils componentUtils;
45
46     @org.springframework.context.annotation.Configuration
47     @Import(BaseTestConfig.class)
48     static class ExceptionHandlerConfig {
49
50         @Bean
51         ExceptionHandlerEndpoint exceptionHandlerEndpoint() {
52             return new ExceptionHandlerEndpoint(componentUtils);
53         }
54     }
55
56     @Override
57     protected void configureClient(ClientConfig config) {
58         final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider()
59                 .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
60         config.register(jacksonJsonProvider);
61     }
62
63     @Override
64     protected ResourceConfig configure() {
65         componentUtils = mock(ComponentsUtils.class);
66
67         return super.configure(ExceptionHandlerConfig.class)
68                 .register(ExceptionHandlerEndpoint.class);
69     }
70
71     @Test
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());
76     }
77 }