2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
6 * Modifications Copyright (C) 2020 Nordix Foundation
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ========================LICENSE_END===================================
21 package org.oransc.portal.nonrtric.controlpanel.mock;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.doAnswer;
25 import static org.mockito.Mockito.mock;
27 import java.lang.invoke.MethodHandles;
28 import java.util.HashMap;
31 import javax.servlet.http.HttpServletRequest;
33 import org.onap.portalsdk.core.onboarding.crossapi.PortalRestAPIProxy;
34 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
35 import org.oransc.portal.nonrtric.controlpanel.portalapi.PortalAuthManager;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.boot.web.servlet.ServletRegistrationBean;
39 import org.springframework.context.annotation.Bean;
40 import org.springframework.context.annotation.Configuration;
41 import org.springframework.context.annotation.Profile;
45 public class PortalApIMockConfiguration {
47 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
49 // Unfortunately EPSDK-FW does not define these as constants
50 public static final String PORTAL_USERNAME_HEADER_KEY = "username";
51 public static final String PORTAL_PASSWORD_HEADER_KEY = "password";
54 public ServletRegistrationBean<PortalRestAPIProxy> portalApiProxyServlet() {
55 PortalRestAPIProxy servlet = new PortalRestAPIProxy();
56 final ServletRegistrationBean<PortalRestAPIProxy> servletBean =
57 new ServletRegistrationBean<>(servlet, PortalApiConstants.API_PREFIX + "/*");
58 servletBean.setName("PortalRestApiProxyServlet");
63 public PortalAuthManager portalAuthManager() throws Exception {
64 PortalAuthManager mockManager = mock(PortalAuthManager.class);
65 final Map<String, String> credentialsMap = new HashMap<>();
66 credentialsMap.put("appName", "appName");
67 credentialsMap.put(PORTAL_USERNAME_HEADER_KEY, PORTAL_USERNAME_HEADER_KEY);
68 credentialsMap.put(PORTAL_PASSWORD_HEADER_KEY, PORTAL_PASSWORD_HEADER_KEY);
70 logger.debug("getAppCredentials");
71 return credentialsMap;
72 }).when(mockManager).getAppCredentials();
74 logger.debug("getUserId");
76 }).when(mockManager).validateEcompSso(any(HttpServletRequest.class));
78 logger.debug("getAppCredentials");
79 return credentialsMap;
80 }).when(mockManager).getAppCredentials();