Fix locally failing TCs in catalog-be
[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 static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26
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;
43
44 class ExceptionHandlerEndpointTest extends JerseySpringBaseTest {
45
46     private static ComponentsUtils componentUtils;
47
48     @org.springframework.context.annotation.Configuration
49     @Import(BaseTestConfig.class)
50     static class ExceptionHandlerConfig {
51
52         @Bean
53         ExceptionHandlerEndpoint exceptionHandlerEndpoint() {
54             return new ExceptionHandlerEndpoint(componentUtils);
55         }
56     }
57
58     @BeforeEach
59     public void before() throws Exception {
60         super.setUp();
61     }
62
63     @AfterEach
64     void after() throws Exception {
65         super.tearDown();
66     }
67
68     @Override
69     protected void configureClient(ClientConfig config) {
70         final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider()
71             .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
72         config.register(jacksonJsonProvider);
73     }
74
75     @Override
76     protected ResourceConfig configure() {
77         forceSet(TestProperties.CONTAINER_PORT, "0");
78         componentUtils = mock(ComponentsUtils.class);
79
80         return super.configure(ExceptionHandlerConfig.class)
81             .register(ExceptionHandlerEndpoint.class);
82     }
83
84     @Test
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());
90     }
91 }