Search in sources :

Example 21 with Email

use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.

the class RequestValidatorTest method testValidateUserInvalidEmailAddress.

@Test
void testValidateUserInvalidEmailAddress() {
    Email email = new Email("notARealEmail", false, "token");
    User user = new User(email, "password");
    RequestValidationException e = assertThrows(RequestValidationException.class, () -> validator.validate(user));
    assertEquals("Invalid email address format. Please try again.", e.getMessage());
    assertEquals(RequestValidationException.Error.INVALID_PARAMETERS, e.getError());
}
Also used : Email(com.sanctionco.thunder.models.Email) User(com.sanctionco.thunder.models.User) Test(org.junit.jupiter.api.Test)

Example 22 with Email

use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.

the class RequestValidatorTest method testValidateEmptyPassword.

@Test
void testValidateEmptyPassword() {
    var propertyValidator = mock(PropertyValidator.class);
    var validator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, HASH_SERVICE, true);
    when(propertyValidator.isValidPropertiesMap(anyMap())).thenReturn(true);
    Email email = new Email("test@test.com", false, "token");
    User user = new User(email, "password");
    RequestValidationException e = assertThrows(RequestValidationException.class, () -> validator.validate("", "test@test.com", user));
    assertEquals("Credentials are required to access this resource.", e.getMessage());
    assertEquals(RequestValidationException.Error.INVALID_PARAMETERS, e.getError());
}
Also used : Email(com.sanctionco.thunder.models.Email) User(com.sanctionco.thunder.models.User) Test(org.junit.jupiter.api.Test)

Example 23 with Email

use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.

the class RequestValidatorTest method testValidateUserEmptyEmailAddress.

@Test
void testValidateUserEmptyEmailAddress() {
    Email email = new Email("", false, "token");
    User user = new User(email, "password");
    RequestValidationException e = assertThrows(RequestValidationException.class, () -> validator.validate(user));
    assertEquals("Invalid email address format. Please try again.", e.getMessage());
    assertEquals(RequestValidationException.Error.INVALID_PARAMETERS, e.getError());
}
Also used : Email(com.sanctionco.thunder.models.Email) User(com.sanctionco.thunder.models.User) Test(org.junit.jupiter.api.Test)

Example 24 with Email

use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.

the class RequestValidatorTest method testValidateUserSuccess.

@Test
void testValidateUserSuccess() {
    var propertyValidator = mock(PropertyValidator.class);
    var validator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, HASH_SERVICE, true);
    when(propertyValidator.isValidPropertiesMap(anyMap())).thenReturn(true);
    Email email = new Email("test@test.com", false, "token");
    User user = new User(email, "password");
    assertDoesNotThrow(() -> validator.validate(user));
}
Also used : Email(com.sanctionco.thunder.models.Email) User(com.sanctionco.thunder.models.User) Test(org.junit.jupiter.api.Test)

Example 25 with Email

use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.

the class RequestValidatorTest method testValidateUserMismatchPropertyMap.

@Test
void testValidateUserMismatchPropertyMap() {
    var propertyValidator = mock(PropertyValidator.class);
    var validator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, HASH_SERVICE, true);
    when(propertyValidator.isValidPropertiesMap(anyMap())).thenReturn(false);
    Email email = new Email("test@test.com", false, "token");
    User user = new User(email, "password");
    RequestValidationException e = assertThrows(RequestValidationException.class, () -> validator.validate(user));
    assertEquals("Cannot post a user with invalid properties.", e.getMessage());
    assertEquals(RequestValidationException.Error.INVALID_PARAMETERS, e.getError());
}
Also used : Email(com.sanctionco.thunder.models.Email) User(com.sanctionco.thunder.models.User) Test(org.junit.jupiter.api.Test)

Aggregations

Email (com.sanctionco.thunder.models.Email)27 User (com.sanctionco.thunder.models.User)26 Test (org.junit.jupiter.api.Test)20 RequestValidator (com.sanctionco.thunder.validation.RequestValidator)9 MetricRegistry (com.codahale.metrics.MetricRegistry)5 Metered (com.codahale.metrics.annotation.Metered)5 RequestValidationException (com.sanctionco.thunder.validation.RequestValidationException)5 Objects (java.util.Objects)5 Inject (javax.inject.Inject)5 POST (javax.ws.rs.POST)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Counter (com.codahale.metrics.Counter)4 ThunderException (com.sanctionco.thunder.ThunderException)4 UsersDao (com.sanctionco.thunder.dao.UsersDao)4 EmailService (com.sanctionco.thunder.email.EmailService)4 SwaggerAnnotations (com.sanctionco.thunder.openapi.SwaggerAnnotations)4 MetricNameUtil (com.sanctionco.thunder.util.MetricNameUtil)4 Auth (io.dropwizard.auth.Auth)4