2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.usermanager.internal;
11 import java.util.Arrays;
12 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
18 import org.opendaylight.controller.sal.authorization.UserLevel;
19 import org.springframework.security.core.GrantedAuthority;
21 public class AuthenticatedUserTest {
23 static String[] roleArray;
24 static AuthenticatedUser user;
27 public static void testSetup() {
28 roleArray = new String[] { UserLevel.NETWORKOPERATOR.toString(),
29 UserLevel.APPUSER.toString() };
33 public void testAuthenticatedUser() {
34 user = new AuthenticatedUser("auser");
36 Assert.assertFalse(user.getAccessDate().isEmpty());
37 Assert.assertNull(user.getUserRoles());
42 public void testSetUserRoleList() {
43 List<String> retrievedRoleList = null;
44 List<String> roleList = Arrays.asList(roleArray);
47 user = new AuthenticatedUser("auser");
48 user.setRoleList(roleList);
49 retrievedRoleList = user.getUserRoles();
50 Assert.assertTrue(roleList.equals(retrievedRoleList));
53 user = new AuthenticatedUser("auser");
54 user.setRoleList(roleArray);
55 retrievedRoleList = user.getUserRoles();
56 for (int i = 0; i < roleArray.length; i++)
57 Assert.assertTrue(roleArray[i].equals(retrievedRoleList.get(i)));
60 user.addUserRole("AnotherRole");
61 Assert.assertTrue(user.getUserRoles().lastIndexOf("AnotherRole") != -1);
66 public void testGetGrantedAuthorities() {
67 List<GrantedAuthority> gaList = user
68 .getGrantedAuthorities(UserLevel.NETWORKOPERATOR);
69 Assert.assertTrue(gaList.get(0).getAuthority()
70 .equals("ROLE_NETWORK-OPERATOR"));