Add RIC instance list and controller method
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / PortalApIMockConfiguration.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
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 package org.oransc.ric.portal.dashboard.config;
21
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.Mockito.doAnswer;
24 import static org.mockito.Mockito.mock;
25
26 import java.lang.invoke.MethodHandles;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import javax.servlet.http.HttpServletRequest;
31
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;
41
42 @Configuration
43 @Profile("test")
44 public class PortalApIMockConfiguration {
45
46         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
47
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";
51
52         @Bean
53         public ServletRegistrationBean<PortalRestAPIProxy> portalApiProxyServlet() {
54                 PortalRestAPIProxy servlet = new PortalRestAPIProxy();
55                 final ServletRegistrationBean<PortalRestAPIProxy> servletBean = new ServletRegistrationBean<>(servlet,
56                                 PortalApiConstants.API_PREFIX + "/*");
57                 servletBean.setName("PortalRestApiProxyServlet");
58                 return servletBean;
59         }
60
61         @Bean
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);
68                 doAnswer(inv -> {
69                         logger.debug("getAppCredentials");
70                         return credentialsMap;
71                 }).when(mockManager).getAppCredentials();
72                 doAnswer(inv -> {
73                         logger.debug("getUserId");
74                         return "userId";
75                 }).when(mockManager).validateEcompSso(any(HttpServletRequest.class));
76                 doAnswer(inv -> {
77                         logger.debug("getAppCredentials");
78                         return credentialsMap;
79                 }).when(mockManager).getAppCredentials();
80                 return mockManager;
81         }
82
83 }