Catalog alignment
[sdc.git] / catalog-fe / src / test / java / org / openecomp / sdc / fe / servlets / FeHealthCheckServletTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Samsung. 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.fe.servlets;
22
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.junit.MockitoJUnitRunner;
27 import org.openecomp.sdc.fe.impl.HealthCheckService;
28
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpSession;
32 import javax.ws.rs.core.Response;
33
34 import static org.junit.Assert.assertEquals;
35 import static org.mockito.ArgumentMatchers.eq;
36 import static org.mockito.Mockito.when;
37 import static org.openecomp.sdc.common.api.Constants.HEALTH_CHECK_SERVICE_ATTR;
38
39 @RunWith(MockitoJUnitRunner.class)
40 public class FeHealthCheckServletTest {
41
42     private final FeHealthCheckServlet healthCheckServlet = new FeHealthCheckServlet();
43     private final Response response = Response.status(200).entity("Ok").build();
44
45     @Mock
46     private HealthCheckService healthCheckService;
47
48     @Mock
49     private ServletContext servletContext;
50
51     @Mock
52     private HttpSession session;
53
54     @Mock
55     private HttpServletRequest request;
56
57     @Test
58     public void testGetFEandBeHealthCheck() {
59         // given
60         when(healthCheckService.getFeHealth()).thenReturn(response);
61         when(servletContext.getAttribute(eq(HEALTH_CHECK_SERVICE_ATTR))).thenReturn(healthCheckService);
62         when(session.getServletContext()).thenReturn(servletContext);
63         when(request.getSession()).thenReturn(session);
64
65         // when
66         final Response healthCheck = healthCheckServlet.getFEandBeHealthCheck(request);
67
68         // then
69         assertEquals(response, healthCheck);
70     }
71 }