diff --git a/src/main/java/uk/gov/hmcts/opal/dto/AccountSearchResultsDto.java b/src/main/java/uk/gov/hmcts/opal/dto/AccountSearchResultsDto.java index f38c5c3ec..4b31fcf42 100644 --- a/src/main/java/uk/gov/hmcts/opal/dto/AccountSearchResultsDto.java +++ b/src/main/java/uk/gov/hmcts/opal/dto/AccountSearchResultsDto.java @@ -3,13 +3,17 @@ import java.util.List; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NoArgsConstructor; @Builder @Getter +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode public class AccountSearchResultsDto implements ToJsonString { diff --git a/src/main/java/uk/gov/hmcts/opal/dto/AccountSummaryDto.java b/src/main/java/uk/gov/hmcts/opal/dto/AccountSummaryDto.java index fc3e3ea05..f18573360 100644 --- a/src/main/java/uk/gov/hmcts/opal/dto/AccountSummaryDto.java +++ b/src/main/java/uk/gov/hmcts/opal/dto/AccountSummaryDto.java @@ -4,10 +4,14 @@ import java.math.BigDecimal; import java.time.LocalDate; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@NoArgsConstructor +@AllArgsConstructor @Builder public class AccountSummaryDto implements ToJsonString { /** The defendant account number. */ diff --git a/src/main/java/uk/gov/hmcts/opal/dto/ToJsonString.java b/src/main/java/uk/gov/hmcts/opal/dto/ToJsonString.java index d307b1be0..c81ba0b03 100644 --- a/src/main/java/uk/gov/hmcts/opal/dto/ToJsonString.java +++ b/src/main/java/uk/gov/hmcts/opal/dto/ToJsonString.java @@ -23,7 +23,7 @@ default JsonNode toJsonNode() throws JsonProcessingException { .readTree(this.toJsonString()); } - private static ObjectMapper newObjectMapper() { + static ObjectMapper newObjectMapper() { return new ObjectMapper() .registerModule(new JavaTimeModule()); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/DefendantAccountService.java b/src/main/java/uk/gov/hmcts/opal/service/DefendantAccountService.java index 45f4d8506..4fc8a1583 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/DefendantAccountService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/DefendantAccountService.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.opal.service; +import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -11,8 +12,11 @@ import uk.gov.hmcts.opal.entity.DefendantAccountEntity; import uk.gov.hmcts.opal.repository.DefendantAccountRepository; +import java.io.InputStream; import java.util.List; +import static uk.gov.hmcts.opal.dto.ToJsonString.newObjectMapper; + @Service @Transactional @Slf4j @@ -39,6 +43,20 @@ public List getDefendantAccountsByBusinessUnit(Short bus } public AccountSearchResultsDto searchDefendantAccounts(AccountSearchDto accountSearchDto) { + + if ("test".equalsIgnoreCase(accountSearchDto.getCourt())) { + + try (InputStream in = Thread.currentThread().getContextClassLoader() + .getResourceAsStream("tempData.json")) { + ObjectMapper mapper = newObjectMapper(); + AccountSearchResultsDto dto = mapper.readValue(in, AccountSearchResultsDto.class); + log.info(":searchDefendantAccounts: temporary Hack for Front End testing. Read JSON file: \n{}", + dto.toPrettyJsonString()); + return dto; + } catch (Exception e) { + throw new RuntimeException(e); + } + } return AccountSearchResultsDto.builder() .searchResults(List.of(AccountSummaryDto.builder().build())) .totalCount(999) diff --git a/src/main/resources/tempData.json b/src/main/resources/tempData.json index 36a51b9e5..ef2057880 100644 --- a/src/main/resources/tempData.json +++ b/src/main/resources/tempData.json @@ -7,89 +7,89 @@ { "accountNo": "16000621W ", "name": "SMITH, AAA Mr ", - "dateOfBirth": "01/01/1970 ", + "dateOfBirth": [ 2001, 8, 16 ], "addressLine1": "ASDF ", - "balance": "£0.34 ", + "balance": 0.34, "court": "West London " }, { "accountNo": "18000027D ", "name": "Smith, David Mr ", - "dateOfBirth": "01/09/2003 ", + "dateOfBirth": [ 1995, 8, 16 ], "addressLine1": "1 St. Kilda Road ", - "balance": "£200.00 ", + "balance": 200.00, "court": "West London " }, { "accountNo": "16000398C ", "name": "Smith, Joe Mr ", - "dateOfBirth": "18/01/1995 ", + "dateOfBirth": [ 1955, 8, 16 ], "addressLine1": "123 The Road ", - "balance": "£1,000.00 ", + "balance": 1000.00, "court": "West London " }, { "accountNo": "16000379A ", "name": "Smith, John Mr ", - "dateOfBirth": "01/08/1995 ", + "dateOfBirth": [ 1966, 8, 16 ], "addressLine1": "1 London Rd ", - "balance": "£1,100.00 ", + "balance": 1100.00, "court": "West London " }, { "accountNo": "15000284C ", "name": "Smith, Johnny Mr ", - "dateOfBirth": "18/01/1954 ", + "dateOfBirth": [ 1989, 8, 16 ], "addressLine1": "1 dahidsah dhsia ", - "balance": "£100.00 ", + "balance": 100.00, "court": "West London " }, { "accountNo": "19000245V ", "name": "Smith, Patrick Mr ", - "dateOfBirth": "07/02/1966 ", + "dateOfBirth": [ 1977, 8, 16 ], "addressLine1": "55 Queens Road ", - "balance": "£220.00 ", + "balance": 220.00, "court": "West London " }, { "accountNo": "19000258I ", "name": "Smith, Paul Mr ", - "dateOfBirth": "07/02/1965 ", + "dateOfBirth": [ 1979, 8, 16 ], "addressLine1": "55 Queens Road ", - "balance": "£100.00 ", + "balance": 100.00, "court": "West London " }, { "accountNo": "15000302N ", "name": "smith, Rocky Mr ", - "dateOfBirth": "01/01/1980 ", + "dateOfBirth": [ 1984, 8, 16 ], "addressLine1": "adsad ", - "balance": "£90,898.09 ", + "balance": 90898.09, "court": "West London " }, { "accountNo": "16000417J ", "name": "SMITH1, Kwame Mr ", - "dateOfBirth": "26/11/1997 ", + "dateOfBirth": [ 1990, 8, 16 ], "addressLine1": "Flat 2 ", - "balance": "£100.00 ", + "balance": 100.00, "court": "West London " }, { "accountNo": "16000418F ", "name": "SMITH2, Ahmed Hady Marian ", - "dateOfBirth": "28/06/1991 ", + "dateOfBirth": [ 1998, 8, 16 ], "addressLine1": "Flat 3 ", - "balance": "£100.00 ", + "balance": 100.00, "court": "West London " }, { "accountNo": "18000035K ", "name": "Smithen, David Mr ", - "dateOfBirth": "10/12/1980 ", + "dateOfBirth": [ 2004, 8, 16 ], "addressLine1": "12 Havens Crescent ", - "balance": "£100.67 ", + "balance": 100.67, "court": "West London" } ] diff --git a/src/test/java/uk/gov/hmcts/opal/service/DefendantAccountServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/DefendantAccountServiceTest.java index 8014bd401..024eff17a 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/DefendantAccountServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/DefendantAccountServiceTest.java @@ -13,6 +13,7 @@ import uk.gov.hmcts.opal.repository.DefendantAccountRepository; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -99,4 +100,21 @@ void testSearchDefendantAccounts() { // Assert assertEquals(expectedResponse, result); } + + @Test + void testSearchDefendantAccountsTemporary() { + // Arrange + AccountSearchDto mockSearch = AccountSearchDto.builder().court("test").build(); + AccountSearchResultsDto expectedResponse = AccountSearchResultsDto.builder() + .searchResults(List.of(AccountSummaryDto.builder().build())) + .totalCount(999) + .cursor(0) + .build(); + + // Act + AccountSearchResultsDto result = defendantAccountService.searchDefendantAccounts(mockSearch); + + // Assert + assertNotNull(result); + } }