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;
22 import java.lang.invoke.MethodHandles;
23 import java.util.HashSet;
26 import org.junit.Assert;
27 import org.junit.jupiter.api.Test;
28 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
29 import org.onap.portalsdk.core.restful.domain.EcompRole;
30 import org.onap.portalsdk.core.restful.domain.EcompUser;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.test.context.ActiveProfiles;
35 @ActiveProfiles("test")
36 public class DashboardUserManagerTest {
38 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
40 public static EcompUser createEcompUser(String loginId) {
41 EcompUser user = new EcompUser();
43 user.setLoginId(loginId);
44 user.setFirstName("First");
45 user.setLastName("Last");
46 EcompRole role = new EcompRole();
48 role.setName(DashboardConstants.ROLE_NAME_ADMIN);
49 Set<EcompRole> roles = new HashSet<>();
56 public void testUserMgr() throws Exception {
57 final String loginId = "demo";
58 DashboardUserManager dum = new DashboardUserManager(true);
59 EcompUser user = createEcompUser(loginId);
61 logger.info("Created user {}", user);
64 throw new Exception("Unexpected success");
65 } catch (PortalAPIException ex) {
66 logger.info("caught expected exception: {}", ex.toString());
68 Assert.assertFalse(dum.getUsers().isEmpty());
69 EcompUser fetched = dum.getUser(loginId);
70 Assert.assertEquals(fetched, user);
71 fetched.setLastName("Lastier");
72 dum.updateUser(loginId, fetched);
73 EcompUser missing = dum.getUser("foo");
74 Assert.assertNull(missing);
75 EcompUser unk = createEcompUser("unknown");
77 dum.updateUser("unk", unk);
78 } catch (PortalAPIException ex) {
79 logger.info("caught expected exception: {}", ex.toString());