2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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.oransc.ric.portal.dashboard.config;
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.Mockito.doAnswer;
24 import static org.mockito.Mockito.mock;
26 import java.lang.invoke.MethodHandles;
27 import java.util.HashMap;
30 import javax.servlet.http.HttpServletRequest;
32 import org.onap.portalsdk.core.onboarding.crossapi.PortalRestAPIProxy;
33 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
34 import org.oransc.ric.portal.dashboard.portalapi.PortalAuthManager;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.boot.web.servlet.ServletRegistrationBean;
38 import org.springframework.context.annotation.Bean;
39 import org.springframework.context.annotation.Configuration;
40 import org.springframework.context.annotation.Profile;
44 public class PortalApIMockConfiguration {
46 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
48 // Unfortunately EPSDK-FW does not define these as constants
49 public static final String PORTAL_USERNAME_HEADER_KEY = "username";
50 public static final String PORTAL_PASSWORD_HEADER_KEY = "password";
53 public ServletRegistrationBean<PortalRestAPIProxy> portalApiProxyServlet() {
54 PortalRestAPIProxy servlet = new PortalRestAPIProxy();
55 final ServletRegistrationBean<PortalRestAPIProxy> servletBean =
56 new ServletRegistrationBean<>(servlet, PortalApiConstants.API_PREFIX + "/*");
57 servletBean.setName("PortalRestApiProxyServlet");
62 public PortalAuthManager portalAuthManager() throws Exception {
63 PortalAuthManager mockManager = mock(PortalAuthManager.class);
64 final Map<String, String> credentialsMap = new HashMap<>();
65 credentialsMap.put("appName", "appName");
66 credentialsMap.put(PORTAL_USERNAME_HEADER_KEY, PORTAL_USERNAME_HEADER_KEY);
67 credentialsMap.put(PORTAL_PASSWORD_HEADER_KEY, PORTAL_PASSWORD_HEADER_KEY);
69 logger.debug("getAppCredentials");
70 return credentialsMap;
71 }).when(mockManager).getAppCredentials();
73 logger.debug("getUserId");
75 }).when(mockManager).validateEcompSso(any(HttpServletRequest.class));
77 logger.debug("getAppCredentials");
78 return credentialsMap;
79 }).when(mockManager).getAppCredentials();