CSIT Fix for SDC-2585
[sdc.git] / catalog-fe / src / test / java / org / openecomp / sdc / fe / servlets / KibanaServletTest.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 static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.when;
26
27 import javax.servlet.ServletContext;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpSession;
30
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;
38
39 @RunWith(MockitoJUnitRunner.class)
40 public class KibanaServletTest {
41
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";
51
52     private final KibanaServlet kibanaServlet = new KibanaServlet();
53
54     @Mock
55     private Configuration configuration;
56
57     @Mock
58     private ConfigurationManager manager;
59
60     @Mock
61     private ServletContext context;
62
63     @Mock
64     private HttpSession session;
65
66     @Mock
67     private HttpServletRequest request;
68
69     @Test
70     public void testRewriteTarget() {
71         // given
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);
76
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);
82
83         when(configuration.getKibanaProtocol()).thenReturn(KIBANA_PROTOCOL);
84         when(configuration.getKibanaHost()).thenReturn(KIBANA_HOST);
85         when(configuration.getKibanaPort()).thenReturn(KIBANA_PORT);
86
87         // when
88         final String url = kibanaServlet.rewriteTarget(request);
89
90         // then
91         assertEquals(EXPECTED, url);
92     }
93 }