X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=webapp-backend%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fconfig%2FPortalApiMockConfiguration.java;fp=webapp-backend%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fconfig%2FPortalApiMockConfiguration.java;h=ab8083a9fb4098b6d9293d9c205de7e6fb2bbd7d;hb=662cc613e80c4079fdf5a54ce3135652cb9ad9a1;hp=0000000000000000000000000000000000000000;hpb=a16f2d04fa1af4fe1ea993133a1d106e7fa1da3d;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/PortalApiMockConfiguration.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/PortalApiMockConfiguration.java new file mode 100644 index 00000000..ab8083a9 --- /dev/null +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/PortalApiMockConfiguration.java @@ -0,0 +1,79 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard.config; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; + +import java.lang.invoke.MethodHandles; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.onap.portalsdk.core.onboarding.crossapi.PortalRestAPIProxy; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.oransc.ric.portal.dashboard.portalapi.PortalAuthManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +@Configuration +@Profile("test") +public class PortalApiMockConfiguration { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + // Unfortunately EPSDK-FW does not define these as constants + public static final String PORTAL_USERNAME_HEADER_KEY = "username"; + public static final String PORTAL_PASSWORD_HEADER_KEY = "password"; + + @Bean + public ServletRegistrationBean portalApiProxyServlet() { + PortalRestAPIProxy servlet = new PortalRestAPIProxy(); + final ServletRegistrationBean servletBean = new ServletRegistrationBean<>(servlet, + PortalApiConstants.API_PREFIX + "/*"); + servletBean.setName("PortalRestApiProxyServlet"); + return servletBean; + } + + @Bean + public PortalAuthManager portalAuthManager() throws Exception { + PortalAuthManager mockManager = mock(PortalAuthManager.class); + final Map credentialsMap = new HashMap<>(); + credentialsMap.put("appName", "appName"); + credentialsMap.put(PORTAL_USERNAME_HEADER_KEY, PORTAL_USERNAME_HEADER_KEY); + credentialsMap.put(PORTAL_PASSWORD_HEADER_KEY, PORTAL_PASSWORD_HEADER_KEY); + doAnswer(inv -> { + logger.debug("getAppCredentials"); + return credentialsMap; + }).when(mockManager).getAppCredentials(); + doAnswer(inv -> { + logger.debug("getUserId"); + return "userId"; + }).when(mockManager).validateEcompSso(any(HttpServletRequest.class)); + return mockManager; + } + +}