2 * ============LICENSE_START=======================================================
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
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.fe.servlets;
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;
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpSession;
32 import javax.ws.rs.core.Response;
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;
39 @RunWith(MockitoJUnitRunner.class)
40 public class FeHealthCheckServletTest {
42 private final FeHealthCheckServlet healthCheckServlet = new FeHealthCheckServlet();
43 private final Response response = Response.ok().entity("Ok").build();
46 private HealthCheckService healthCheckService;
49 private ServletContext servletContext;
52 private HttpSession session;
55 private HttpServletRequest request;
58 public void testGetFEandBeHealthCheck() {
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);
66 final Response healthCheck = healthCheckServlet.getFEandBeHealthCheck(request);
69 assertEquals(response, healthCheck);