App metrics visualization manage
[portal/ric-dashboard.git] / dashboard / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / AdminMockConfiguration.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 java.io.IOException;
23 import java.io.PrintWriter;
24 import java.lang.invoke.MethodHandles;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.Locale;
28 import java.util.Set;
29
30 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
31 import org.onap.portalsdk.core.restful.domain.EcompRole;
32 import org.onap.portalsdk.core.restful.domain.EcompUser;
33 import org.oransc.ric.portal.dashboard.DashboardUserManager;
34 import org.oransc.ric.portal.dashboard.AppStatsManager;
35 import org.oransc.ric.portal.dashboard.exception.StatsManagerException;
36 import org.oransc.ric.portal.dashboard.model.AppStats;
37 import org.oransc.ric.portal.dashboard.model.StatsDetailsTransport;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Configuration;
43 import org.springframework.context.annotation.Profile;
44
45 import javax.servlet.ServletOutputStream;
46 import javax.servlet.http.Cookie;
47 import javax.servlet.http.HttpServletResponse;
48
49 /**
50  * Creates user manager and stats manager with mock data.
51  */
52 @Configuration
53 @Profile("test")
54 public class AdminMockConfiguration {
55
56         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
57
58         @Autowired
59         public AdminMockConfiguration() {
60         }
61
62         @Bean
63         // The bean (method) name must be globally unique
64         public DashboardUserManager userManager() throws IOException, PortalAPIException {
65                 logger.debug("userManager: adding mock data");
66                 DashboardUserManager mgr = new DashboardUserManager(true);
67                 String[] firsts = { "John", "Alice", "Pierce", "Paul", "Jack" };
68                 String[] lasts = { "Doe", "Nolan", "King", "Smith", "Reacher" };
69                 String[] logins = { "jdoe", "anolan", "pking", "psmith", "jreacher" };
70                 boolean[] actives = { true, true, false, false, true };
71                 EcompRole role = new EcompRole();
72                 role.setName("view");
73                 Set<EcompRole> roles = new HashSet<>();
74                 roles.add(role);
75                 for (int i = 0; i < firsts.length; ++i) {
76                         EcompUser eu = new EcompUser();
77                         eu.setFirstName(firsts[i]);
78                         eu.setLastName(lasts[i]);
79                         eu.setLoginId(logins[i]);
80                         eu.setActive(actives[i]);
81                         eu.setRoles(roles);
82                         mgr.createUser(eu);
83                 }
84                 return mgr;
85         }
86
87         @Bean
88         // The bean (method) name must be globally unique
89         public AppStatsManager statsManager() throws IOException, StatsManagerException {
90                 logger.debug("statsManager: adding mock data");
91                 AppStatsManager mgr = new AppStatsManager(true);
92                 String instanceKey = RICInstanceMockConfiguration.INSTANCE_KEY_1;
93                 StatsDetailsTransport statsDetails = new StatsDetailsTransport();
94                 statsDetails.setAppId(0);
95                 statsDetails.setAppName("MachLearn");
96                 statsDetails.setMetricUrl("https://www.example.com");
97                 mgr.createStats(instanceKey, statsDetails);
98                 return mgr;
99         }
100
101 }