use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserManagementServiceImplTest method testUpdatePassword.
@Test
public void testUpdatePassword() {
String credentials = "encryptedPassword";
Integer userId = 1;
UserDetail userDetail = mock(UserDetail.class);
UserIndex userIndex = mock(UserIndex.class);
UserRole userRole = mock(UserRole.class);
Set<UserIndex> userIndices = new HashSet<UserIndex>();
userIndices.add(userIndex);
Set<UserRole> userRoles = new HashSet<UserRole>();
userRoles.add(userRole);
when(userRole.getName()).thenReturn("ROLE_ADMINISTRATOR");
buildUserDetail(userId, userDetail, "password");
when(userService.getUserForId(userId)).thenReturn(user);
when(passwordEncoder.encodePassword("password", "admin")).thenReturn(credentials);
when(user.getUserIndices()).thenReturn(userIndices);
when(user.getRoles()).thenReturn(userRoles);
boolean success = service.updateUser(userDetail);
assertTrue("User's password updated successfully", success);
verify(passwordEncoder).encodePassword("password", "admin");
verify(authoritiesService, times(0)).getAdministratorRole();
verify(userDao).saveOrUpdateUser(user);
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserServiceImpl method getUserAsBean.
@Override
public UserBean getUserAsBean(User user) {
UserBean bean = new UserBean();
bean.setUserId(Integer.toString(user.getId()));
UserRole anonymous = _authoritiesService.getAnonymousRole();
boolean isAnonymous = user.getRoles().contains(anonymous);
bean.setAnonymous(isAnonymous);
UserRole admin = _authoritiesService.getAdministratorRole();
boolean isAdmin = user.getRoles().contains(admin);
bean.setAdmin(isAdmin);
List<UserIndexBean> indices = new ArrayList<UserIndexBean>();
bean.setIndices(indices);
for (UserIndex index : user.getUserIndices()) {
UserIndexKey key = index.getId();
UserIndexBean indexBean = new UserIndexBean();
indexBean.setType(key.getType());
indexBean.setValue(key.getValue());
indices.add(indexBean);
}
_userPropertiesService.getUserAsBean(user, bean);
return bean;
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserDaoImplTest method deleteUser.
@Test
public void deleteUser() {
UserRole userRole = new UserRole("user");
_dao.saveOrUpdateUserRole(userRole);
User user = new User();
user.setCreationTime(new Date());
user.setProperties(new UserPropertiesV2());
user.getRoles().add(userRole);
UserIndexKey key = new UserIndexKey("phone", "2065551234");
UserIndex index = new UserIndex();
index.setId(key);
index.setUser(user);
user.getUserIndices().add(index);
_dao.saveOrUpdateUser(user);
assertEquals(1, _dao.getNumberOfUsers());
UserIndex index2 = _dao.getUserIndexForId(key);
assertEquals(key, index2.getId());
assertEquals(user, index2.getUser());
_dao.deleteUser(user);
assertEquals(0, _dao.getNumberOfUsers());
index2 = _dao.getUserIndexForId(key);
assertNull(index2);
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserDaoImplTest method test.
@Test
public void test() {
assertEquals(0, _dao.getNumberOfUserRoles());
UserRole adminRole = new UserRole("admin");
UserRole userRole = new UserRole("user");
_dao.saveOrUpdateUserRole(adminRole);
_dao.saveOrUpdateUserRole(userRole);
assertEquals(2, _dao.getNumberOfUserRoles());
assertEquals(0, _dao.getNumberOfUsersWithRole(adminRole));
assertEquals(0, _dao.getNumberOfUsersWithRole(userRole));
User userA = new User();
userA.setCreationTime(new Date());
userA.setProperties(new UserPropertiesV1());
userA.getRoles().add(userRole);
_dao.saveOrUpdateUser(userA);
assertEquals(0, _dao.getNumberOfUsersWithRole(adminRole));
assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
User userB = new User();
userB.setCreationTime(new Date());
userB.setProperties(new UserPropertiesV1());
userB.getRoles().add(adminRole);
_dao.saveOrUpdateUser(userB);
assertEquals(1, _dao.getNumberOfUsersWithRole(adminRole));
assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
userA.getRoles().add(adminRole);
_dao.saveOrUpdateUser(userA);
assertEquals(2, _dao.getNumberOfUsersWithRole(adminRole));
assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserManagementServiceImplTest method testUpdateUserRole.
@Test
public void testUpdateUserRole() {
Integer userId = 1;
UserDetail userDetail = mock(UserDetail.class);
UserIndex userIndex = mock(UserIndex.class);
UserRole userRole = mock(UserRole.class);
Set<UserIndex> userIndices = new HashSet<UserIndex>();
userIndices.add(userIndex);
Set<UserRole> userRoles = new HashSet<UserRole>();
userRoles.add(userRole);
when(userRole.getName()).thenReturn("ROLE_USER");
buildUserDetail(userId, userDetail, "");
when(userService.getUserForId(userId)).thenReturn(user);
when(user.getUserIndices()).thenReturn(userIndices);
when(user.getRoles()).thenReturn(userRoles);
boolean success = service.updateUser(userDetail);
assertTrue("User's password updated successfully", success);
verify(passwordEncoder, times(0)).encodePassword("", "admin");
verify(authoritiesService).getUserRoleForName("ROLE_ADMINISTRATOR");
verify(userDao).saveOrUpdateUser(user);
}
Aggregations