Skip to content

Commit

Permalink
RDCC-5070 handling special characters in searchString(/search endpoin…
Browse files Browse the repository at this point in the history
…t). (#348)

* RDCC-5070 handling special characters in searchString(/search endpoint).

* RDCC-5070 updated the error message and fixed sonarlint regex expression

* RDCC-5070 fixed checkstyle issue

* RDCC-5070 fixed checkstyle issue

* RDCC-5070 updated the error message for searchString

* RDCC-5070 updated the error message for searchString
  • Loading branch information
nayeemshaik-hmcts authored Jul 13, 2022
1 parent 3bd3fa3 commit 404f4d5
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void shouldReturn400WhenSearchStringDoesNotContainRequiredLength(String role) {
userSearchRequest, role, false);
assertThat(response).containsEntry("http_status", "400");
var responseBody = (String) response.get("response_body");
assertTrue(responseBody.contains("should have atleast 3 characters"));
assertTrue(responseBody.contains("searchString must be at least 3 characters including letters, "
+ "apostrophe, hyphen"));
}

@ParameterizedTest
Expand All @@ -150,7 +151,8 @@ void shouldReturn400WhenSearchStringContainsOtherThanLetters(String role) {
userSearchRequest, role, false);
assertThat(response).containsEntry("http_status", "400");
var responseBody = (String) response.get("response_body");
assertTrue(responseBody.contains("should contains letters only"));
assertTrue(responseBody.contains("searchString must be at least 3 characters including letters, "
+ "apostrophe, hyphen"));
}

@ParameterizedTest
Expand Down Expand Up @@ -196,5 +198,93 @@ void shouldReturn200WhenUserProfileRequestedForGivenSearchStringWithEmptyAdditio
assertThat(response).containsEntry("http_status", "200 OK");
}

@ParameterizedTest
@ValueSource(strings = { "jrd-system-user","jrd-admin"})
void shouldReturn200WhenUserProfileApostropheString(String role) {
UserSearchRequest userSearchRequest = UserSearchRequest.builder()
.searchString("Am'")
.build();
var response = judicialReferenceDataClient.searchUsers(
userSearchRequest, role, false);
var profiles = (List<Map<String, String>>)response.get("body");
assertEquals(1, profiles.size());
assertEquals("[email protected]", profiles.get(0).get("emailId"));
assertEquals("Am'ar", profiles.get(0).get("knownAs"));
assertThat(response).containsEntry("http_status", "200 OK");
}

@ParameterizedTest
@ValueSource(strings = { "jrd-system-user","jrd-admin"})
void shouldReturn200WhenUserProfileApostropheStrings(String role) {
UserSearchRequest userSearchRequest = UserSearchRequest.builder()
.searchString("O'j")
.build();
var response = judicialReferenceDataClient.searchUsers(
userSearchRequest, role, false);
var profiles = (List<Map<String, String>>)response.get("body");
assertEquals(1, profiles.size());
assertEquals("[email protected]", profiles.get(0).get("emailId"));
assertEquals("O'jas", profiles.get(0).get("knownAs"));
assertThat(response).containsEntry("http_status", "200 OK");
}

@ParameterizedTest
@ValueSource(strings = { "jrd-system-user","jrd-admin"})
void shouldReturn200WhenUserProfileHyphenString(String role) {
UserSearchRequest userSearchRequest = UserSearchRequest.builder()
.searchString("Li-a")
.build();
var response = judicialReferenceDataClient.searchUsers(
userSearchRequest, role, false);
var profiles = (List<Map<String, String>>)response.get("body");
assertEquals(1, profiles.size());
assertEquals("[email protected]", profiles.get(0).get("emailId"));
assertEquals("Li-am", profiles.get(0).get("knownAs"));
assertThat(response).containsEntry("http_status", "200 OK");
}

@ParameterizedTest
@ValueSource(strings = { "jrd-system-user","jrd-admin"})
void shouldReturn200WhenUserProfileHyphenStrings(String role) {
UserSearchRequest userSearchRequest = UserSearchRequest.builder()
.searchString("V-e")
.build();
var response = judicialReferenceDataClient.searchUsers(
userSearchRequest, role, false);
var profiles = (List<Map<String, String>>)response.get("body");
assertEquals(1, profiles.size());
assertEquals("[email protected]", profiles.get(0).get("emailId"));
assertEquals("V-ed", profiles.get(0).get("knownAs"));
assertThat(response).containsEntry("http_status", "200 OK");
}

@ParameterizedTest
@ValueSource(strings = { "jrd-system-user","jrd-admin"})
void shouldReturn200WhenUserProfileEmptySpace(String role) {
UserSearchRequest userSearchRequest = UserSearchRequest.builder()
.searchString("J Ro")
.build();
var response = judicialReferenceDataClient.searchUsers(
userSearchRequest, role, false);
var profiles = (List<Map<String, String>>)response.get("body");
assertEquals(1, profiles.size());
assertEquals("[email protected]", profiles.get(0).get("emailId"));
assertEquals("J Rock", profiles.get(0).get("knownAs"));
assertThat(response).containsEntry("http_status", "200 OK");
}

@ParameterizedTest
@ValueSource(strings = { "jrd-system-user","jrd-admin"})
void shouldReturn200WhenUserProfileEmptySpaces(String role) {
UserSearchRequest userSearchRequest = UserSearchRequest.builder()
.searchString("To N")
.build();
var response = judicialReferenceDataClient.searchUsers(
userSearchRequest, role, false);
var profiles = (List<Map<String, String>>)response.get("body");
assertEquals(1, profiles.size());
assertEquals("[email protected]", profiles.get(0).get("emailId"));
assertEquals("To Nick", profiles.get(0).get("knownAs"));
assertThat(response).containsEntry("http_status", "200 OK");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,25 @@ last_working_date, active_flag, extracted_date, created_date,
last_loaded_date, object_id, sidam_id, is_judge, is_panel_member, is_magistrate)
VALUES('9001', 'A123', 'Sample_KA_1', 'Sample_SN_1', 'Sample_FN_1', 'Ms', 'No Work Pattern (M to F)', '[email protected]', '2022-03-01', NULL, true,
'2022-03-01 12:25:28.763', '2022-03-01 09:10:44.682', '2022-03-01 09:10:44.682',
'900', '900', true, false, true);
'900', '900', true, false, true),
('8002', 'A124', 'Am''ar', 'Pamet', 'Am''ar Pamet', 'Ms', 'No Work Pattern (M to F)', '[email protected]', '2022-03-01', NULL, true,
'2022-03-01 12:25:28.763', '2022-03-01 09:10:44.682', '2022-03-01 09:10:44.682',
'802', '802', true, false, true),
('8003', 'A125', 'O''jas', 'Baet', 'O''jas Baet', 'Ms', 'No Work Pattern (M to F)', '[email protected]', '2022-03-01', NULL, true,
'2022-03-01 12:25:28.763', '2022-03-01 09:10:44.682', '2022-03-01 09:10:44.682',
'803', '803', true, false, true),
('8004', 'A126', 'Li-am', 'Kate', 'Li-am Kate', 'Ms', 'No Work Pattern (M to F)', '[email protected]', '2022-03-01', NULL, true,
'2022-03-01 12:25:28.763', '2022-03-01 09:10:44.682', '2022-03-01 09:10:44.682',
'804', '804', true, false, true),
('8005', 'A127', 'V-ed', 'Prakasscs', 'V-ed Prakasscs', 'Ms', 'No Work Pattern (M to F)', '[email protected]', '2022-03-01', NULL, true,
'2022-03-01 12:25:28.763', '2022-03-01 09:10:44.682', '2022-03-01 09:10:44.682',
'805', '805', true, false, true),
('8006', 'A128', 'J Rock', 'Brian', 'J Rock Brian', 'Ms', 'No Work Pattern (M to F)', '[email protected]', '2022-03-01', NULL, true,
'2022-03-01 12:25:28.763', '2022-03-01 09:10:44.682', '2022-03-01 09:10:44.682',
'806', '806', true, false, true),
('8007', 'A129', 'To Nick', 'Cruz', 'To Nick Cruz', 'Ms', 'No Work Pattern (M to F)', '[email protected]', '2022-03-01', NULL, true,
'2022-03-01 12:25:28.763', '2022-03-01 09:10:44.682', '2022-03-01 09:10:44.682',
'807', '807', true, false, true);

INSERT INTO judicial_office_appointment
(judicial_office_appointment_id, per_id, base_location_id, region_id, is_prinicple_appointment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Builder
@AllArgsConstructor
Expand All @@ -20,8 +19,8 @@ public class UserSearchRequest {
@JsonProperty("searchString")
@NotNull(message = "cannot be null")
@NotEmpty(message = "cannot be empty")
@Size(min = 3, message = "should have atleast {min} characters")
@Pattern(regexp = "[a-zA-Z]+", message = "should contains letters only")
@Pattern(regexp = "([a-zA-Z\\-\\s']){3,}+", message = "must be at least 3 characters including "
+ "letters, apostrophe, hyphen")
private String searchString;

@JsonProperty("serviceCode")
Expand Down

0 comments on commit 404f4d5

Please sign in to comment.