Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Po 476 debtor profile search #483

Merged
merged 9 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package uk.gov.hmcts.opal.controllers;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.gov.hmcts.opal.dto.OpalS2SRequestWrapper;
import uk.gov.hmcts.opal.dto.OpalS2SResponseWrapper;

@RestController
@RequestMapping("/api/create-fine-accounts")
@Slf4j(topic = "CreateFineAccountController")
@Tag(name = "Create Fine Account Controller")
public class CreateFineAccountsController {

@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<OpalS2SResponseWrapper> createFineAccounts(OpalS2SRequestWrapper createFineAccountsRequest) {

log.info(":POST:createFineAccounts: request: \n{}", createFineAccountsRequest);
OpalS2SResponseWrapper response = OpalS2SResponseWrapper.builder()
.opalResponsePayload(responseXML)
.build();
return new ResponseEntity<>(response, HttpStatus.OK);
}

private String responseXML = """
<?xml version="1.0" encoding="UTF-8"?>
<CreateFineAccountsResponse
xmlns="http://www.justice.gov.uk/magistrates/atcm/CreateFineAccountsResponse"
xmlns:lg="http://www.justice.gov.uk/magistrates/atcm/CreatedFineAccount">
<lg:CreatedFineAccount>
<CPPID xmlns="">12345</CPPID>
<CPPUUID xmlns="">12345</CPPUUID>
</lg:CreatedFineAccount>
<NumberOfFineAccounts xmlns="">1</NumberOfFineAccounts>
<ErrorCode xmlns=""></ErrorCode>
<ErrorMessage xmlns=""></ErrorMessage>
</CreateFineAccountsResponse>
""";

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package uk.gov.hmcts.opal.controllers;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.gov.hmcts.opal.dto.OpalS2SRequestWrapper;
import uk.gov.hmcts.opal.dto.OpalS2SResponseWrapper;

@RestController
@RequestMapping("/api/debtor-profile")
@Slf4j(topic = "DebtorProfileSearchController")
@Tag(name = "Debtor Profile Search Controller")
public class DebtorProfileSearchController {

@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<OpalS2SResponseWrapper> searchDebtorProfile(OpalS2SRequestWrapper debtorProfileRequest) {

log.info(":POST:searchDebtorProfile: request: \n{}", debtorProfileRequest);
OpalS2SResponseWrapper response = OpalS2SResponseWrapper.builder()
.opalResponsePayload(responseXML)
.build();
return new ResponseEntity<>(response, HttpStatus.OK);
}

private String responseXML = """
<?xml version="1.0" encoding="UTF-8"?>
<DebtorProfileResponse xmlns="http://www.justice.gov.uk/magistrates/atcm/DebtorProfileResponse"
xmlns:lgsr="http://www.justice.gov.uk/magistrates/atcm/SearchResponseType"
xmlns:lgsm="http://www.justice.gov.uk/magistrates/atcm/SearchMetadataType">
<lgsr:SearchResponseType>
<lgsm:SearchMetadataType>
<SequenceNumber>123</SequenceNumber>
<CPPDefendantID>DEF123</CPPDefendantID>
<CPPCaseID>CASE123</CPPCaseID>
<CourtOUCode>COURT01</CourtOUCode>
<DateOfHearing>2023-10-01</DateOfHearing>
<TimeOfHearing>10:00</TimeOfHearing>
</lgsm:SearchMetadataType>
<AccountMatch>
<Matches>
<Account>
<OrganisationName>Sample Org</OrganisationName>
<Forenames>John</Forenames>
<Surname>Doe</Surname>
<DOB>1980-01-01</DOB>
<NationalInsuranceNumber>AB123456C</NationalInsuranceNumber>
<AccountNumber>12345678</AccountNumber>
<AddressLine1>123 Sample Street</AddressLine1>
<AddressLine2>Sample Area</AddressLine2>
<AddressLine3>Sample City</AddressLine3>
<Postcode>AB12 3CD</Postcode>
<LastEnforcementAction>None</LastEnforcementAction>
<BalanceOutstanding>1000.00</BalanceOutstanding>
<CollectionOrderMade>Y</CollectionOrderMade>
<PaymentTerms>Monthly</PaymentTerms>
<AmountImposed>1500.00</AmountImposed>
<AmountPaid>500.00</AmountPaid>
<DaysInDefault>30</DaysInDefault>
<MasterAccount>N</MasterAccount>
<OriginatingCT>CT123</OriginatingCT>
<ParentGuardianFlag>N</ParentGuardianFlag>
<ProsecutorCaseReference>REF123</ProsecutorCaseReference>
</Account>
</Matches>
</AccountMatch>
</lgsr:SearchResponseType>
<UnprocessedRequests>
<lgsm:SearchMetadataType>
<SequenceNumber>456</SequenceNumber>
<CPPDefendantID>DEF456</CPPDefendantID>
<CPPCaseID>CASE456</CPPCaseID>
<CourtOUCode>COURT02</CourtOUCode>
<DateOfHearing>2023-11-01</DateOfHearing>
<TimeOfHearing>11:00</TimeOfHearing>
</lgsm:SearchMetadataType>
</UnprocessedRequests>
<ErrorCode>12345</ErrorCode>
<ErrorMessage>Sample error message</ErrorMessage>
</DebtorProfileResponse>
""";

}

11 changes: 11 additions & 0 deletions src/main/java/uk/gov/hmcts/opal/dto/OpalS2SRequestWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.gov.hmcts.opal.dto;

import lombok.Data;

@Data
public class OpalS2SRequestWrapper {

String externalApiPayload;


}
13 changes: 13 additions & 0 deletions src/main/java/uk/gov/hmcts/opal/dto/OpalS2SResponseWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package uk.gov.hmcts.opal.dto;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class OpalS2SResponseWrapper {

String opalResponsePayload;

String errorDetail;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package uk.gov.hmcts.opal.controllers;

import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import uk.gov.hmcts.opal.dto.OpalS2SRequestWrapper;
import uk.gov.hmcts.opal.dto.OpalS2SResponseWrapper;

import static org.junit.jupiter.api.Assertions.assertEquals;


class CreateFineAccountsControllerTest {

private CreateFineAccountsController createFineAccountsController = new CreateFineAccountsController();

@Test
void testSearchDebtorProfile_Success() {
// Arrange
OpalS2SRequestWrapper request = new OpalS2SRequestWrapper();
OpalS2SResponseWrapper response = OpalS2SResponseWrapper.builder()
.opalResponsePayload("""
<?xml version="1.0" encoding="UTF-8"?>
<CreateFineAccountsResponse
xmlns="http://www.justice.gov.uk/magistrates/atcm/CreateFineAccountsResponse"
xmlns:lg="http://www.justice.gov.uk/magistrates/atcm/CreatedFineAccount">
<lg:CreatedFineAccount>
<CPPID xmlns="">12345</CPPID>
<CPPUUID xmlns="">12345</CPPUUID>
</lg:CreatedFineAccount>
<NumberOfFineAccounts xmlns="">1</NumberOfFineAccounts>
<ErrorCode xmlns=""></ErrorCode>
<ErrorMessage xmlns=""></ErrorMessage>
</CreateFineAccountsResponse>
""")
.build();

ResponseEntity<OpalS2SResponseWrapper> responseEntity = new ResponseEntity<>(response, HttpStatus.OK);

// Act
ResponseEntity<OpalS2SResponseWrapper> actualResponse = createFineAccountsController
.createFineAccounts(request);

// Assert
assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
assertEquals(response, actualResponse.getBody());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package uk.gov.hmcts.opal.controllers;

import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import uk.gov.hmcts.opal.dto.OpalS2SRequestWrapper;
import uk.gov.hmcts.opal.dto.OpalS2SResponseWrapper;

import static org.junit.jupiter.api.Assertions.assertEquals;


class DebtorProfileSearchControllerTest {

private DebtorProfileSearchController debtorProfileSearchController = new DebtorProfileSearchController();

@Test
void testSearchDebtorProfile_Success() {
// Arrange
OpalS2SRequestWrapper request = new OpalS2SRequestWrapper();
OpalS2SResponseWrapper response = OpalS2SResponseWrapper.builder()
.opalResponsePayload("""
<?xml version="1.0" encoding="UTF-8"?>
<DebtorProfileResponse xmlns="http://www.justice.gov.uk/magistrates/atcm/DebtorProfileResponse"
xmlns:lgsr="http://www.justice.gov.uk/magistrates/atcm/SearchResponseType"
xmlns:lgsm="http://www.justice.gov.uk/magistrates/atcm/SearchMetadataType">
<lgsr:SearchResponseType>
<lgsm:SearchMetadataType>
<SequenceNumber>123</SequenceNumber>
<CPPDefendantID>DEF123</CPPDefendantID>
<CPPCaseID>CASE123</CPPCaseID>
<CourtOUCode>COURT01</CourtOUCode>
<DateOfHearing>2023-10-01</DateOfHearing>
<TimeOfHearing>10:00</TimeOfHearing>
</lgsm:SearchMetadataType>
<AccountMatch>
<Matches>
<Account>
<OrganisationName>Sample Org</OrganisationName>
<Forenames>John</Forenames>
<Surname>Doe</Surname>
<DOB>1980-01-01</DOB>
<NationalInsuranceNumber>AB123456C</NationalInsuranceNumber>
<AccountNumber>12345678</AccountNumber>
<AddressLine1>123 Sample Street</AddressLine1>
<AddressLine2>Sample Area</AddressLine2>
<AddressLine3>Sample City</AddressLine3>
<Postcode>AB12 3CD</Postcode>
<LastEnforcementAction>None</LastEnforcementAction>
<BalanceOutstanding>1000.00</BalanceOutstanding>
<CollectionOrderMade>Y</CollectionOrderMade>
<PaymentTerms>Monthly</PaymentTerms>
<AmountImposed>1500.00</AmountImposed>
<AmountPaid>500.00</AmountPaid>
<DaysInDefault>30</DaysInDefault>
<MasterAccount>N</MasterAccount>
<OriginatingCT>CT123</OriginatingCT>
<ParentGuardianFlag>N</ParentGuardianFlag>
<ProsecutorCaseReference>REF123</ProsecutorCaseReference>
</Account>
</Matches>
</AccountMatch>
</lgsr:SearchResponseType>
<UnprocessedRequests>
<lgsm:SearchMetadataType>
<SequenceNumber>456</SequenceNumber>
<CPPDefendantID>DEF456</CPPDefendantID>
<CPPCaseID>CASE456</CPPCaseID>
<CourtOUCode>COURT02</CourtOUCode>
<DateOfHearing>2023-11-01</DateOfHearing>
<TimeOfHearing>11:00</TimeOfHearing>
</lgsm:SearchMetadataType>
</UnprocessedRequests>
<ErrorCode>12345</ErrorCode>
<ErrorMessage>Sample error message</ErrorMessage>
</DebtorProfileResponse>
""")
.build();

ResponseEntity<OpalS2SResponseWrapper> responseEntity = new ResponseEntity<>(response, HttpStatus.OK);

// Act
ResponseEntity<OpalS2SResponseWrapper> actualResponse = debtorProfileSearchController
.searchDebtorProfile(request);

// Assert
assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
assertEquals(response, actualResponse.getBody());
}
}