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 static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.when;
27 import javax.servlet.ServletContext;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpSession;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.openecomp.sdc.common.api.Constants;
36 import org.openecomp.sdc.fe.config.Configuration;
37 import org.openecomp.sdc.fe.config.ConfigurationManager;
39 @RunWith(MockitoJUnitRunner.class)
40 public class KibanaServletTest {
42 private static final int KIBANA_PORT = 9898;
43 private static final String CONTEXT_PATH = "/context";
44 private static final String SERVLET_PATH = "/sdc1/kibanaProxy";
45 private static final String PATH_INFO = "/info";
46 private static final String QUERY_STRING = "query=projectR";
47 private static final String REQUEST_URI = "uri";
48 private static final String KIBANA_PROTOCOL = "kbn";
49 private static final String KIBANA_HOST = "kibana.com";
50 private static final String EXPECTED = "kbn://kibana.com:9898/context/info?query=projectR";
52 private final KibanaServlet kibanaServlet = new KibanaServlet();
55 private Configuration configuration;
58 private ConfigurationManager manager;
61 private ServletContext context;
64 private HttpSession session;
67 private HttpServletRequest request;
70 public void testRewriteTarget() {
72 when(manager.getConfiguration()).thenReturn(configuration);
73 when(context.getAttribute(eq(Constants.CONFIGURATION_MANAGER_ATTR))).thenReturn(manager);
74 when(session.getServletContext()).thenReturn(context);
75 when(request.getSession()).thenReturn(session);
77 when(request.getContextPath()).thenReturn(CONTEXT_PATH);
78 when(request.getServletPath()).thenReturn(SERVLET_PATH);
79 when(request.getPathInfo()).thenReturn(PATH_INFO);
80 when(request.getQueryString()).thenReturn(QUERY_STRING);
81 when(request.getRequestURI()).thenReturn(REQUEST_URI);
83 when(configuration.getKibanaProtocol()).thenReturn(KIBANA_PROTOCOL);
84 when(configuration.getKibanaHost()).thenReturn(KIBANA_HOST);
85 when(configuration.getKibanaPort()).thenReturn(KIBANA_PORT);
88 final String url = kibanaServlet.rewriteTarget(request);
91 assertEquals(EXPECTED, url);