2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia 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
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=========================================================
20 package org.openecomp.sdc.fe.servlets;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.Mockito;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.openecomp.sdc.common.api.Constants;
30 import org.openecomp.sdc.common.rest.api.RestConfigurationInfo;
31 import org.openecomp.sdc.fe.config.Configuration;
32 import org.openecomp.sdc.fe.config.ConfigurationManager;
34 import javax.servlet.ServletContext;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpSession;
38 @RunWith(MockitoJUnitRunner.class)
39 public class ConfigMgrServletTest {
41 private static final String VERSION_1 = "VERSION 1";
42 private static final String PROTOCOL = "PROTO";
44 private HttpServletRequest request;
46 private HttpSession session;
48 private ServletContext context;
50 private ConfigurationManager configManager;
54 Mockito.when(request.getSession()).thenReturn(session);
55 Mockito.when(session.getServletContext()).thenReturn(context);
56 Mockito.when(context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configManager);
60 public void shouldGetConfigForRestType() {
61 String wantedResult = "{\n"
62 + " \"connectionPoolSize\": 5\n"
64 RestConfigurationInfo restConfiguration = new RestConfigurationInfo();
65 restConfiguration.setConnectionPoolSize(5);
66 Mockito.when(configManager.getRestClientConfiguration()).thenReturn(restConfiguration);
68 ConfigMgrServlet configMgrServlet = new ConfigMgrServlet();
69 String config = configMgrServlet.getConfig(request, "rest");
70 Assert.assertEquals(wantedResult, config);
74 public void shouldGetConfigForConfigurationType() {
75 checkForConfigurationTypeOrEmpty("configuration");
79 public void shouldGetConfigForNullType() {
80 checkForConfigurationTypeOrEmpty(null);
83 private void checkForConfigurationTypeOrEmpty(String type) {
84 String wantedResult = "{\n"
85 + " \"beProtocol\": \"PROTO\",\n"
86 + " \"version\": \"VERSION 1\",\n"
87 + " \"threadpoolSize\": 0,\n"
88 + " \"requestTimeout\": 0\n"
91 Configuration configuration = new Configuration();
92 configuration.setVersion(VERSION_1);
93 configuration.setBeProtocol(PROTOCOL);
94 Mockito.when(configManager.getConfiguration()).thenReturn(configuration);
96 ConfigMgrServlet configMgrServlet = new ConfigMgrServlet();
97 String config = configMgrServlet.getConfig(request, type);
98 Assert.assertEquals(wantedResult, config);