Search in sources :

Example 1 with EMAIL_ADDRESS_REQUIRED

use of org.simbasecurity.core.exception.SimbaMessageKey.EMAIL_ADDRESS_REQUIRED in project simba-os by cegeka.

the class UserFactoryTest method createUser_UserWithoutEmail_EmailRequiredAccordingToParameter_ShouldThrowAnException.

@Test
public void createUser_UserWithoutEmail_EmailRequiredAccordingToParameter_ShouldThrowAnException() {
    User user = aDefaultUser().withoutEmail().withUserName("userName").build();
    when(configurationService.getValue(SimbaConfigurationParameter.EMAIL_ADDRESS_REQUIRED)).thenReturn(true);
    assertThatThrownBy(() -> userFactory.create(user)).extracting(t -> ((SimbaException) t).getMessageKey()).containsExactly(EMAIL_ADDRESS_REQUIRED);
    verifyZeroInteractions(resetPasswordService);
    verify(userRepository, never()).persist(any(User.class));
    verify(managementAudit, never()).log(any(String.class), any(String.class));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RoleTestBuilder.role(org.simbasecurity.core.domain.RoleTestBuilder.role) EMAIL_ADDRESS_REQUIRED(org.simbasecurity.core.exception.SimbaMessageKey.EMAIL_ADDRESS_REQUIRED) RoleRepository(org.simbasecurity.core.domain.repository.RoleRepository) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserTestBuilder.aDefaultUser(org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser) RunWith(org.junit.runner.RunWith) SimbaConfigurationParameter(org.simbasecurity.core.config.SimbaConfigurationParameter) User(org.simbasecurity.core.domain.User) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StubEmailFactory(org.simbasecurity.core.domain.StubEmailFactory) CoreConfigurationService(org.simbasecurity.core.service.config.CoreConfigurationService) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) NewUser(org.simbasecurity.core.service.communication.reset.password.NewUser) UserTestBuilder.aUser(org.simbasecurity.core.domain.UserTestBuilder.aUser) ResetPasswordService(org.simbasecurity.core.service.communication.reset.password.ResetPasswordService) AutowirerRule(org.simbasecurity.test.AutowirerRule) Test(org.junit.Test) UserValidator(org.simbasecurity.core.domain.validator.UserValidator) ManagementAudit(org.simbasecurity.core.audit.ManagementAudit) SimbaException(org.simbasecurity.core.exception.SimbaException) UserRepository(org.simbasecurity.core.domain.repository.UserRepository) Mockito(org.mockito.Mockito) List(java.util.List) Rule(org.junit.Rule) PasswordGenerator(org.simbasecurity.core.domain.generator.PasswordGenerator) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) PasswordValidator(org.simbasecurity.core.domain.validator.PasswordValidator) SimbaException(org.simbasecurity.core.exception.SimbaException) UserTestBuilder.aDefaultUser(org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser) User(org.simbasecurity.core.domain.User) NewUser(org.simbasecurity.core.service.communication.reset.password.NewUser) UserTestBuilder.aUser(org.simbasecurity.core.domain.UserTestBuilder.aUser) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Lists.newArrayList (org.assertj.core.util.Lists.newArrayList)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 InjectMocks (org.mockito.InjectMocks)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)1 ManagementAudit (org.simbasecurity.core.audit.ManagementAudit)1 SimbaConfigurationParameter (org.simbasecurity.core.config.SimbaConfigurationParameter)1 RoleTestBuilder.role (org.simbasecurity.core.domain.RoleTestBuilder.role)1 StubEmailFactory (org.simbasecurity.core.domain.StubEmailFactory)1 User (org.simbasecurity.core.domain.User)1 UserTestBuilder.aDefaultUser (org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser)1 UserTestBuilder.aUser (org.simbasecurity.core.domain.UserTestBuilder.aUser)1