Skip to content

Commit

Permalink
Temp change to service to allow FE testing
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyHMCTS committed Dec 8, 2023
1 parent 6c5acfc commit 033f24a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/uk/gov/hmcts/opal/dto/AccountSummaryDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/uk/gov/hmcts/opal/dto/ToJsonString.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -39,6 +43,20 @@ public List<DefendantAccountEntity> 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)
Expand Down
44 changes: 22 additions & 22 deletions src/main/resources/tempData.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 033f24a

Please sign in to comment.