Refactor error messages to be in lower case (#30)
This commit is contained in:
@ -99,7 +99,7 @@ public class UserResource {
|
||||
.httpStatusCode(OK.value())
|
||||
.httpStatus(OK)
|
||||
.reason(OK.getReasonPhrase())
|
||||
.message("User deleted successfully".toUpperCase())
|
||||
.message("User deleted successfully")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ public class HttpResponseUtility {
|
||||
.httpStatus(httpStatus)
|
||||
.httpStatusCode(httpStatus.value())
|
||||
.reason(httpStatus.getReasonPhrase().toUpperCase())
|
||||
.message(message.toUpperCase())
|
||||
.message(message)
|
||||
.build();
|
||||
return new ResponseEntity<>(httpResponse, httpStatus);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class ErrorControllerTest {
|
||||
.satisfies(httpResponse -> assertAll(
|
||||
() -> assertThat(httpResponse.getHttpStatus()).isEqualTo(NOT_FOUND),
|
||||
() -> assertThat(httpResponse.getHttpStatusCode()).isEqualTo(NOT_FOUND.value()),
|
||||
() -> assertThat(httpResponse.getMessage()).isEqualTo("RESOURCE NOT FOUND"),
|
||||
() -> assertThat(httpResponse.getMessage()).isEqualTo("Resource not found"),
|
||||
() -> assertThat(httpResponse.getReason()).isEqualTo(NOT_FOUND.getReasonPhrase().toUpperCase()),
|
||||
() -> assertThat(httpResponse.getTimestamp()).isCloseTo(LocalDateTime.now(), within(300, ChronoUnit.MILLIS))
|
||||
));
|
||||
|
||||
@ -31,8 +31,8 @@ class ExceptionsControllerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"emailExists,THIS EMAIL IS ALREADY TAKEN",
|
||||
"userNotFound,THE USER WAS NOT FOUND"
|
||||
"emailExists,This email is already taken",
|
||||
"userNotFound,The user was not found"
|
||||
})
|
||||
void badRequestException(String endpoint, String expectedMessage) {
|
||||
|
||||
|
||||
@ -140,7 +140,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
User fakeUser = createRandomUser();
|
||||
String username = user.getUsername();
|
||||
fakeUser.setUsername(username);
|
||||
String expectedMessage = ("Username `" + username + "` is already taken. Please select another one").toUpperCase();
|
||||
String expectedMessage = ("Username `" + username + "` is already taken. Please select another one");
|
||||
|
||||
//when
|
||||
ResponseEntity<HttpResponse> responseEntity = restTemplate.postForEntity("/user/register", fakeUser, HttpResponse.class);
|
||||
@ -167,7 +167,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
User fakeUser = createRandomUser();
|
||||
String email = user.getEmail();
|
||||
fakeUser.setEmail(email);
|
||||
String expectedMessage = ("User with email `" + email + "` is already registered").toUpperCase();
|
||||
String expectedMessage = ("User with email `" + email + "` is already registered");
|
||||
|
||||
//when
|
||||
ResponseEntity<HttpResponse> responseEntity = restTemplate.postForEntity("/user/register", fakeUser, HttpResponse.class);
|
||||
@ -232,7 +232,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
//given
|
||||
String password = "absentUserPass";
|
||||
String username = FAKER.name().username();
|
||||
String expectedMessage = "USERNAME / PASSWORD INCORRECT. PLEASE TRY AGAIN";
|
||||
String expectedMessage = "Username / password incorrect. Please try again";
|
||||
|
||||
//when
|
||||
var userLogin = UserLoginDto.builder()
|
||||
@ -265,7 +265,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
//given
|
||||
String password = "wrongPass";
|
||||
String username = user.getUsername();
|
||||
String expectedMessage = "USERNAME / PASSWORD INCORRECT. PLEASE TRY AGAIN";
|
||||
String expectedMessage = "Username / password incorrect. Please try again";
|
||||
|
||||
//when
|
||||
var userLogin = UserLoginDto.builder()
|
||||
@ -321,7 +321,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
.hasFieldOrPropertyWithValue("httpStatusCode", 400)
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("reason", "BAD REQUEST")
|
||||
.hasFieldOrPropertyWithValue("message", "USERNAME / PASSWORD INCORRECT. PLEASE TRY AGAIN");
|
||||
.hasFieldOrPropertyWithValue("message", "Username / password incorrect. Please try again");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@ -345,7 +345,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
.hasFieldOrPropertyWithValue("httpStatusCode", 401)
|
||||
.hasFieldOrPropertyWithValue("httpStatus", UNAUTHORIZED)
|
||||
.hasFieldOrPropertyWithValue("reason", "UNAUTHORIZED")
|
||||
.hasFieldOrPropertyWithValue("message", "YOUR ACCOUNT HAS BEEN LOCKED. PLEASE CONTACT ADMINISTRATION");
|
||||
.hasFieldOrPropertyWithValue("message", "Your account has been locked. Please contact administration");
|
||||
}
|
||||
|
||||
|
||||
@ -672,7 +672,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", OK)
|
||||
.hasFieldOrPropertyWithValue("message", "USER DELETED SUCCESSFULLY");
|
||||
.hasFieldOrPropertyWithValue("message", "User deleted successfully");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -697,7 +697,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", FORBIDDEN)
|
||||
.hasFieldOrPropertyWithValue("message", "YOU DO NOT HAVE ENOUGH PERMISSION");
|
||||
.hasFieldOrPropertyWithValue("message", "You do not have enough permission");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -724,7 +724,7 @@ class UserResourceTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", "USER WAS NOT FOUND");
|
||||
.hasFieldOrPropertyWithValue("message", "User was not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", "ERROR(S) IN PARAMETERS: [FIRSTNAME:SHOULD NOT BE EMPTY]");
|
||||
.hasFieldOrPropertyWithValue("message", "Error(s) in parameters: [firstName:Should not be empty]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -160,7 +160,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", "ERROR(S) IN PARAMETERS: [ROLE:FAILED TO CONVERT PROPERTY VALUE OF TYPE 'JAVA.LANG.STRING' TO REQUIRED TYPE 'NET.SHYSHKIN.STUDY.FULLSTACK.SUPPORTPORTAL.BACKEND.DOMAIN.ROLE' FOR PROPERTY 'ROLE'; NESTED EXCEPTION IS ORG.SPRINGFRAMEWORK.CORE.CONVERT.CONVERSIONFAILEDEXCEPTION: FAILED TO CONVERT FROM TYPE [JAVA.LANG.STRING] TO TYPE [@JAVAX.VALIDATION.CONSTRAINTS.NOTNULL NET.SHYSHKIN.STUDY.FULLSTACK.SUPPORTPORTAL.BACKEND.DOMAIN.ROLE] FOR VALUE 'ROLE_FAKE'; NESTED EXCEPTION IS JAVA.LANG.ILLEGALARGUMENTEXCEPTION: NO ENUM CONSTANT NET.SHYSHKIN.STUDY.FULLSTACK.SUPPORTPORTAL.BACKEND.DOMAIN.ROLE.ROLE_FAKE]");
|
||||
.hasFieldOrPropertyWithValue("message", "Error(s) in parameters: [role:Failed to convert property value of type 'java.lang.String' to required type 'net.shyshkin.study.fullstack.supportportal.backend.domain.Role' for property 'role'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull net.shyshkin.study.fullstack.supportportal.backend.domain.Role] for value 'ROLE_FAKE'; nested exception is java.lang.IllegalArgumentException: No enum constant net.shyshkin.study.fullstack.supportportal.backend.domain.Role.ROLE_FAKE]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -196,7 +196,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", "ERROR(S) IN PARAMETERS: [EMAIL:MUST MATCH EMAIL FORMAT]");
|
||||
.hasFieldOrPropertyWithValue("message", "Error(s) in parameters: [email:Must match email format]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -232,7 +232,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", "ERROR(S) IN PARAMETERS: [NOTLOCKED:FAILED TO CONVERT PROPERTY VALUE OF TYPE 'JAVA.LANG.STRING' TO REQUIRED TYPE 'BOOLEAN' FOR PROPERTY 'NOTLOCKED'; NESTED EXCEPTION IS JAVA.LANG.ILLEGALARGUMENTEXCEPTION: INVALID BOOLEAN VALUE [NOT_A_BOOLEAN]]");
|
||||
.hasFieldOrPropertyWithValue("message", "Error(s) in parameters: [notLocked:Failed to convert property value of type 'java.lang.String' to required type 'boolean' for property 'notLocked'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [not_a_boolean]]");
|
||||
}
|
||||
}
|
||||
|
||||
@ -381,7 +381,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", "ERROR(S) IN PARAMETERS: [LASTNAME:SHOULD NOT BE EMPTY]");
|
||||
.hasFieldOrPropertyWithValue("message", "Error(s) in parameters: [lastName:Should not be empty]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -423,7 +423,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", currentUsername).toUpperCase());
|
||||
.hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", currentUsername));
|
||||
}
|
||||
|
||||
}
|
||||
@ -480,7 +480,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", username).toUpperCase());
|
||||
.hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", username));
|
||||
}
|
||||
}
|
||||
|
||||
@ -628,7 +628,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", username).toUpperCase());
|
||||
.hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", username));
|
||||
}
|
||||
}
|
||||
|
||||
@ -685,7 +685,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", BAD_REQUEST)
|
||||
.hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", absentUsername).toUpperCase());
|
||||
.hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", absentUsername));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -708,7 +708,7 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
||||
.isNotNull()
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.hasFieldOrPropertyWithValue("httpStatus", INTERNAL_SERVER_ERROR)
|
||||
.hasFieldOrPropertyWithValue("message", "Error occurred while processing file".toUpperCase());
|
||||
.hasFieldOrPropertyWithValue("message", "Error occurred while processing file");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user