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;
34 public class DashboardUserManagerTest {
36 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
38 public static EcompUser createEcompUser(String loginId) {
39 EcompUser user = new EcompUser();
41 user.setLoginId(loginId);
42 user.setFirstName("First");
43 user.setLastName("Last");
44 EcompRole role = new EcompRole();
46 role.setName(DashboardConstants.ROLE_NAME_ADMIN);
47 Set<EcompRole> roles = new HashSet<>();
54 public void testUserMgr() throws Exception {
55 final String loginId = "demo";
56 DashboardUserManager dum = new DashboardUserManager(true);
57 EcompUser user = createEcompUser(loginId);
59 logger.info("Created user {}", user);
62 throw new Exception("Unexpected success");
63 } catch (PortalAPIException ex) {
64 logger.info("caught expected exception: {}", ex.toString());
66 Assert.assertFalse(dum.getUsers().isEmpty());
67 EcompUser fetched = dum.getUser(loginId);
68 Assert.assertEquals(fetched, user);
69 fetched.setLastName("Lastier");
70 dum.updateUser(loginId, fetched);
71 EcompUser missing = dum.getUser("foo");
72 Assert.assertNull(missing);
73 EcompUser unk = createEcompUser("unknown");
75 dum.updateUser("unk", unk);
76 } catch (PortalAPIException ex) {
77 logger.info("caught expected exception: {}", ex.toString());