Skip to content

Commit

Permalink
Remove exception class name from the error message (geonetwork#6977)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwallen authored Oct 29, 2023
1 parent 4a946e6 commit b417ead
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions services/src/main/java/org/fao/geonet/api/ApiError.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public ApiError(String code, String message, String description) {

public ApiError(String code, Exception exception) {
this(code,
exception.getClass().getSimpleName(),
exception.getMessage()
exception.getMessage(),
null
);
this.exception = exception;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void addExistingGroup() throws Exception {
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(status().is(400))
.andExpect(jsonPath("$.description", is("A group with name 'sample' already exist.")));
.andExpect(jsonPath("$.message", is("A group with name 'sample' already exist.")));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void addExistingIdentifier() throws Exception {
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(status().is(400))
.andExpect(jsonPath("$.description", is("A metadata identifier template with id '" + metadataIdentifierTemplateToAdd.getId() + "' already exist.")));
.andExpect(jsonPath("$.message", is("A metadata identifier template with id '" + metadataIdentifierTemplateToAdd.getId() + "' already exist.")));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public void subTemplateValidIsNotSet() throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andExpect(content().contentType(API_JSON_EXPECTED_ENCODING))
.andExpect(jsonPath("$.message").value("BadParameterEx"))
.andExpect(jsonPath("$.description").value("Parameter isvalid MUST be set for subtemplate."));
.andExpect(jsonPath("$.message").value("Parameter isvalid MUST be set for subtemplate."));

List<MetadataValidation> validations = metadataValidationRepository.findAllById_MetadataId(subTemplate.getId());
assertEquals(0, validations.size());
Expand Down Expand Up @@ -158,8 +157,7 @@ public void subTemplateValidSetButTemplate() throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andExpect(content().contentType(API_JSON_EXPECTED_ENCODING))
.andExpect(jsonPath("$.message").value("BadParameterEx"))
.andExpect(jsonPath("$.description").value("Parameter isvalid can't be set if it is not a Subtemplate. You cannot force validation of a metadata or a template."));
.andExpect(jsonPath("$.message").value("Parameter isvalid can't be set if it is not a Subtemplate. You cannot force validation of a metadata or a template."));

List<MetadataValidation> validations = metadataValidationRepository.findAllById_MetadataId(subTemplate.getId());
assertEquals(0, validations.size());
Expand Down
28 changes: 14 additions & 14 deletions services/src/test/java/org/fao/geonet/api/users/UsersApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void deleteUserLogged() throws Exception {
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(status().is(400))
.andExpect(jsonPath("$.description", is("You cannot delete yourself from the user database")))
.andExpect(jsonPath("$.message", is("You cannot delete yourself from the user database")))
.andExpect(content().contentType(API_JSON_EXPECTED_ENCODING));
}

Expand Down Expand Up @@ -214,7 +214,7 @@ public void deleteUserNotAllowedToUserAdmin() throws Exception {
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(status().is(400))
.andExpect(jsonPath("$.description", is("You don't have rights to delete this user because the user is not part of your group")))
.andExpect(jsonPath("$.message", is("You don't have rights to delete this user because the user is not part of your group")))
.andExpect(content().contentType(API_JSON_EXPECTED_ENCODING));
}

Expand Down Expand Up @@ -271,7 +271,7 @@ public void createUserMissingUsername() throws Exception {
.contentType(API_JSON_EXPECTED_ENCODING)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("username is a required parameter for newuser operation")))
.andExpect(jsonPath("$.message", is("username is a required parameter for newuser operation")))
.andExpect(status().is(400));
}

Expand Down Expand Up @@ -299,7 +299,7 @@ public void createDuplicatedUsername() throws Exception {
.contentType(API_JSON_EXPECTED_ENCODING)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("Users with username " + user.getUsername()
.andExpect(jsonPath("$.message", is("Users with username " + user.getUsername()
+ " ignore case already exists")))
.andExpect(status().is(400));

Expand Down Expand Up @@ -329,7 +329,7 @@ public void createDuplicatedUsernameIgnoreCase() throws Exception {
.contentType(API_JSON_EXPECTED_ENCODING)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("Users with username " + user.getUsername()
.andExpect(jsonPath("$.message", is("Users with username " + user.getUsername()
+ " ignore case already exists")))
.andExpect(status().is(400));

Expand Down Expand Up @@ -357,7 +357,7 @@ public void resetPassword() throws Exception {
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(status().is(400))
.andExpect(jsonPath("$.description", is("The old password is not valid.")));
.andExpect(jsonPath("$.message", is("The old password is not valid.")));


passwordReset.setPasswordOld("testuser-editor-password");
Expand Down Expand Up @@ -397,7 +397,7 @@ public void resetPasswordToNotAllowedUser() throws Exception {
.contentType(API_JSON_EXPECTED_ENCODING)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("You don't have rights to do this")))
.andExpect(jsonPath("$.message", is("You don't have rights to do this")))
.andExpect(status().is(400));
}

Expand All @@ -424,7 +424,7 @@ public void resetPasswordNotEqual() throws Exception {
.content(json)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("Passwords should be equal")))
.andExpect(jsonPath("$.message", is("Passwords should be equal")))
.andExpect(status().is(400));
}

Expand All @@ -451,7 +451,7 @@ public void resetPasswordWrongOldPassword() throws Exception {
.content(json)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("The old password is not valid.")))
.andExpect(jsonPath("$.message", is("The old password is not valid.")))
.andExpect(status().is(400));
}

Expand All @@ -477,7 +477,7 @@ public void resetPasswordNotExistingUser() throws Exception {
.content(json)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("User not found")))
.andExpect(jsonPath("$.message", is("User not found")))
.andExpect(status().is(404));
}

Expand Down Expand Up @@ -564,7 +564,7 @@ public void updateUserByUserAdminNotAllowed() throws Exception {
.contentType(API_JSON_EXPECTED_ENCODING)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("You don't have rights to do this")))
.andExpect(jsonPath("$.message", is("You don't have rights to do this")))
.andExpect(status().is(400));
}

Expand Down Expand Up @@ -598,7 +598,7 @@ public void updateUserDuplicatedUsername() throws Exception {
.contentType(API_JSON_EXPECTED_ENCODING)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("Another user with username "
.andExpect(jsonPath("$.message", is("Another user with username "
+ "'testuser-editor' ignore case already exists")))
.andExpect(status().is(400));
}
Expand Down Expand Up @@ -633,7 +633,7 @@ public void updateUserDuplicatedUsernameIgnoreCase() throws Exception {
.contentType(API_JSON_EXPECTED_ENCODING)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("Another user with username 'testuser-editor' ignore case already exists")))
.andExpect(jsonPath("$.message", is("Another user with username 'testuser-editor' ignore case already exists")))
.andExpect(status().is(400));
}

Expand Down Expand Up @@ -701,7 +701,7 @@ public void updateUserAlreadyExistingUsernameCase() throws Exception {
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(status().is(400))
.andExpect(jsonPath("$.description", is("Another user with username 'testuser-editor' ignore case already exists")));
.andExpect(jsonPath("$.message", is("Another user with username 'testuser-editor' ignore case already exists")));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void testParameterMustBeSet() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.session(this.mockHttpSession)
.accept(MediaType.parseMediaType("application/json")))
.andExpect(jsonPath("$.description", is("At least one edit must be defined.")))
.andExpect(jsonPath("$.message", is("At least one edit must be defined.")))
.andExpect(status().is(400));

}
Expand Down

0 comments on commit b417ead

Please sign in to comment.