use of com.synopsys.integration.alert.database.user.UserEntity in project hub-alert by blackducksoftware.
the class DefaultUserAccessorTest method addUserExistsTest.
@Test
public void addUserExistsTest() throws Exception {
UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L);
userEntity.setId(1L);
Mockito.when(userRepository.findByUserName(Mockito.any())).thenReturn(Optional.of(userEntity));
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor);
try {
defaultUserAccessor.addUser(username, password, emailAddress);
fail("User with the same name that already exists in the userRepository did not throw expected " + AlertConfigurationException.class.getSimpleName());
} catch (AlertConfigurationException e) {
assertNotNull(e);
}
}
use of com.synopsys.integration.alert.database.user.UserEntity in project hub-alert by blackducksoftware.
the class DefaultUserAccessorTest method deleteUserByNameTest.
@Test
public void deleteUserByNameTest() throws Exception {
// userEntity Id's between 0 and 2 are reserved
UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L);
userEntity.setId(5L);
Mockito.when(userRepository.findByUserName(Mockito.eq(username))).thenReturn(Optional.of(userEntity));
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor);
defaultUserAccessor.deleteUser(username);
Mockito.verify(roleAccessor).updateUserRoles(Mockito.any(), Mockito.any());
Mockito.verify(userRepository).deleteById(Mockito.any());
}
use of com.synopsys.integration.alert.database.user.UserEntity in project hub-alert by blackducksoftware.
the class DefaultUserAccessorTest method assignRolesTest.
@Test
public void assignRolesTest() {
final String badUsername = "badUsername";
final Long roleId = 5L;
UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L);
userEntity.setId(1L);
Mockito.when(userRepository.findByUserName(Mockito.eq(username))).thenReturn(Optional.of(userEntity));
Mockito.when(userRepository.findByUserName(Mockito.eq(badUsername))).thenReturn(Optional.empty());
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor);
boolean assignedRoles = defaultUserAccessor.assignRoles(username, Set.of(roleId));
boolean assignedRolesFalse = defaultUserAccessor.assignRoles(badUsername, Set.of(roleId));
Mockito.verify(roleAccessor).updateUserRoles(Mockito.eq(userEntity.getId()), Mockito.any());
Mockito.verify(roleAccessor).getRoles(Mockito.any());
assertTrue(assignedRoles);
assertFalse(assignedRolesFalse);
}
use of com.synopsys.integration.alert.database.user.UserEntity in project hub-alert by blackducksoftware.
the class DefaultUserAccessorTest method deleteUserReservedIdTest.
@Test
public void deleteUserReservedIdTest() throws Exception {
UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L);
userEntity.setId(1L);
Mockito.when(userRepository.findByUserName(Mockito.eq(username))).thenReturn(Optional.of(userEntity));
Mockito.when(userRepository.findById(Mockito.any())).thenReturn(Optional.of(userEntity));
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor);
try {
defaultUserAccessor.deleteUser(username);
fail("A forbidden userEntity id did not throw the expected AlertForbiddenOperationException");
} catch (AlertForbiddenOperationException e) {
assertNotNull(e);
}
}
use of com.synopsys.integration.alert.database.user.UserEntity in project hub-alert by blackducksoftware.
the class DefaultUserAccessorTest method getUserByUsernameTest.
@Test
public void getUserByUsernameTest() {
final String emptyUsername = "";
final Long authenticationTypeId = 1L;
final String roleName = "userName";
UserEntity userEntity = new UserEntity(username, password, emailAddress, authenticationTypeId);
userEntity.setId(1L);
UserRoleRelation userRoleRelation = new UserRoleRelation(1L, 2L);
UserRoleModel userRoleModel = createUserRoleModel(1L, roleName, true);
Mockito.when(userRepository.findByUserName(username)).thenReturn(Optional.of(userEntity));
Mockito.when(userRepository.findByUserName(emptyUsername)).thenReturn(Optional.empty());
createModelMocks(userRoleRelation, userRoleModel, AuthenticationType.DATABASE);
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor);
Optional<UserModel> userModelOptional = defaultUserAccessor.getUser(username);
Optional<UserModel> userModelOptionalEmpty = defaultUserAccessor.getUser(emptyUsername);
assertTrue(userModelOptional.isPresent());
assertFalse(userModelOptionalEmpty.isPresent());
UserModel userModel = userModelOptional.get();
testUserModel(userEntity.getId(), username, emailAddress, roleName, userModel);
}
Aggregations