diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/DocumentController.java b/src/main/java/uk/gov/hmcts/opal/controllers/DocumentController.java index 147a4d68e..3da9e7543 100644 --- a/src/main/java/uk/gov/hmcts/opal/controllers/DocumentController.java +++ b/src/main/java/uk/gov/hmcts/opal/controllers/DocumentController.java @@ -35,7 +35,7 @@ public DocumentController(@Qualifier("documentServiceProxy") DocumentServiceInte @GetMapping(value = "/{documentId}") @Operation(summary = "Returns the Document for the given documentId.") - public ResponseEntity getDocumentById(@PathVariable Long documentId) { + public ResponseEntity getDocumentById(@PathVariable String documentId) { log.info(":GET:getDocumentById: documentId: {}", documentId); diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/LocalJusticeAreaController.java b/src/main/java/uk/gov/hmcts/opal/controllers/LocalJusticeAreaController.java index b19134c2c..31fc334b1 100644 --- a/src/main/java/uk/gov/hmcts/opal/controllers/LocalJusticeAreaController.java +++ b/src/main/java/uk/gov/hmcts/opal/controllers/LocalJusticeAreaController.java @@ -36,7 +36,7 @@ public LocalJusticeAreaController( @GetMapping(value = "/{localJusticeAreaId}") @Operation(summary = "Returns the LocalJusticeArea for the given localJusticeAreaId.") - public ResponseEntity getLocalJusticeAreaById(@PathVariable Long localJusticeAreaId) { + public ResponseEntity getLocalJusticeAreaById(@PathVariable Short localJusticeAreaId) { log.info(":GET:getLocalJusticeAreaById: localJusticeAreaId: {}", localJusticeAreaId); diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/PaymentTermsController.java b/src/main/java/uk/gov/hmcts/opal/controllers/PaymentTermsController.java index 717f6fcd1..a729d2536 100644 --- a/src/main/java/uk/gov/hmcts/opal/controllers/PaymentTermsController.java +++ b/src/main/java/uk/gov/hmcts/opal/controllers/PaymentTermsController.java @@ -46,10 +46,10 @@ public ResponseEntity getPaymentTermsById(@PathVariable Long } @PostMapping(value = "/search", consumes = MediaType.APPLICATION_JSON_VALUE) - @Operation(summary = "Searches PaymentTermss based upon criteria in request body") - public ResponseEntity> postPaymentTermssSearch( + @Operation(summary = "Searches PaymentTerms based upon criteria in request body") + public ResponseEntity> postPaymentTermsSearch( @RequestBody PaymentTermsSearchDto criteria) { - log.info(":POST:postPaymentTermssSearch: query: \n{}", criteria); + log.info(":POST:postPaymentTermsSearch: query: \n{}", criteria); List response = paymentTermsService.searchPaymentTerms(criteria); diff --git a/src/main/java/uk/gov/hmcts/opal/dto/search/DebtorDetailSearchDto.java b/src/main/java/uk/gov/hmcts/opal/dto/search/DebtorDetailSearchDto.java index af311a8d4..e6263de41 100644 --- a/src/main/java/uk/gov/hmcts/opal/dto/search/DebtorDetailSearchDto.java +++ b/src/main/java/uk/gov/hmcts/opal/dto/search/DebtorDetailSearchDto.java @@ -8,7 +8,7 @@ @Builder public class DebtorDetailSearchDto implements ToJsonString { - private String debtorId; + private String partyId; private String email; private String vehicleMake; private String vehicleRegistration; diff --git a/src/main/java/uk/gov/hmcts/opal/dto/search/LocalJusticeAreaSearchDto.java b/src/main/java/uk/gov/hmcts/opal/dto/search/LocalJusticeAreaSearchDto.java index 8aba264c4..9f1c748cd 100644 --- a/src/main/java/uk/gov/hmcts/opal/dto/search/LocalJusticeAreaSearchDto.java +++ b/src/main/java/uk/gov/hmcts/opal/dto/search/LocalJusticeAreaSearchDto.java @@ -1,13 +1,17 @@ package uk.gov.hmcts.opal.dto.search; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import uk.gov.hmcts.opal.dto.ToJsonString; @Data @Builder @EqualsAndHashCode(callSuper = true) +@AllArgsConstructor +@NoArgsConstructor public class LocalJusticeAreaSearchDto extends AddressSearch implements ToJsonString { private String localJusticeAreaId; diff --git a/src/main/java/uk/gov/hmcts/opal/entity/AccountTransferEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/AccountTransferEntity.java index 595b394c9..533c068dd 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/AccountTransferEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/AccountTransferEntity.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -26,6 +27,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class AccountTransferEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitEntity.java index 44bd3f77c..c138e16ee 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitEntity.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; @@ -15,6 +18,8 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "businessUnitId") public class BusinessUnitEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/CommittalWarrantProgressEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/CommittalWarrantProgressEntity.java index 001fe99ec..b7757d421 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/CommittalWarrantProgressEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/CommittalWarrantProgressEntity.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -24,6 +25,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class CommittalWarrantProgressEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/CourtEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/CourtEntity.java index 047824a1b..88b2d4af0 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/CourtEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/CourtEntity.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -20,6 +23,8 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "courtId") public class CourtEntity extends EnforcerCourtBaseEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/DebtorDetailEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/DebtorDetailEntity.java index 5b28d8457..b6339c3a9 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/DebtorDetailEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/DebtorDetailEntity.java @@ -1,12 +1,11 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; @@ -23,15 +22,13 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class DebtorDetailEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long debtorId; - - @ManyToOne - @JoinColumn(name = "party_id", referencedColumnName = "party_id", nullable = false) - private PartyEntity party; + @Column(name = "party_id") + private Long partyId; @Column(name = "telephone_home") private String telephoneHome; diff --git a/src/main/java/uk/gov/hmcts/opal/entity/DefendantAccountEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/DefendantAccountEntity.java index dc8c7227a..925ab22ee 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/DefendantAccountEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/DefendantAccountEntity.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -29,6 +32,8 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "defendantAccountId") public class DefendantAccountEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/DefendantAccountPartiesEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/DefendantAccountPartiesEntity.java index 6b65d12ce..8e441b0fd 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/DefendantAccountPartiesEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/DefendantAccountPartiesEntity.java @@ -1,5 +1,7 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -23,6 +25,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "defendantAccountPartyId") public class DefendantAccountPartiesEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/DocumentEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/DocumentEntity.java index 17af5780b..78adbab46 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/DocumentEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/DocumentEntity.java @@ -1,11 +1,11 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.SequenceGenerator; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; @@ -18,13 +18,13 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "documentId") public class DocumentEntity { @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "document_id_seq_generator") - @SequenceGenerator(name = "document_id_seq_generator", sequenceName = "document_id_seq", allocationSize = 1) - @Column(name = "document_id", nullable = false) - private Long documentId; + @Column(name = "document_id", length = 10, nullable = false) + private String documentId; @Column(name = "recipient", length = 4, nullable = false) private String recipient; diff --git a/src/main/java/uk/gov/hmcts/opal/entity/DocumentInstanceEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/DocumentInstanceEntity.java index 07a866cbc..42bc53468 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/DocumentInstanceEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/DocumentInstanceEntity.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -24,6 +25,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class DocumentInstanceEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/EnforcementEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/EnforcementEntity.java index 4eabe5489..2c9a0cdc5 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/EnforcementEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/EnforcementEntity.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -24,6 +27,8 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "enforcementId") public class EnforcementEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/EnforcerEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/EnforcerEntity.java index 43e923f0e..e6a6f7d59 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/EnforcerEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/EnforcerEntity.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -19,6 +22,8 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "enforcerId") public class EnforcerEntity extends EnforcerCourtBaseEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/LocalJusticeAreaEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/LocalJusticeAreaEntity.java index c7ae091c0..3411e668a 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/LocalJusticeAreaEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/LocalJusticeAreaEntity.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -20,6 +23,8 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "localJusticeAreaId") public class LocalJusticeAreaEntity extends AddressEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/MisDebtorEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/MisDebtorEntity.java index 63025a755..48a3f5282 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/MisDebtorEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/MisDebtorEntity.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -25,6 +26,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class MisDebtorEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/PartyEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/PartyEntity.java index 1ca6f098d..348dd517b 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/PartyEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/PartyEntity.java @@ -1,5 +1,7 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -27,6 +29,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "partyId") public class PartyEntity implements FullNameBuilder { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/PaymentInEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/PaymentInEntity.java index b69eb538a..0cdb2c3dd 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/PaymentInEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/PaymentInEntity.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -25,6 +26,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class PaymentInEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/PaymentTermsEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/PaymentTermsEntity.java index d65014ba6..67b061692 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/PaymentTermsEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/PaymentTermsEntity.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; @@ -22,6 +23,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class PaymentTermsEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/PrisonEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/PrisonEntity.java index 2b8deaf0b..c420bed74 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/PrisonEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/PrisonEntity.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -22,6 +23,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class PrisonEntity extends AddressEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/entity/TillEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/TillEntity.java index 77cf61dd7..02d3b14a4 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/TillEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/TillEntity.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.opal.entity; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -18,6 +21,8 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "tillId") public class TillEntity { @Id diff --git a/src/main/java/uk/gov/hmcts/opal/repository/AccountTransferRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/AccountTransferRepository.java index cbdb548f4..f8306ba22 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/AccountTransferRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/AccountTransferRepository.java @@ -8,6 +8,4 @@ @Repository public interface AccountTransferRepository extends JpaRepository, JpaSpecificationExecutor { - - AccountTransferEntity findByAccountTransferId(Long accountTransferId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/CommittalWarrantProgressRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/CommittalWarrantProgressRepository.java index db9eccf2c..5231775e4 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/CommittalWarrantProgressRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/CommittalWarrantProgressRepository.java @@ -8,6 +8,4 @@ @Repository public interface CommittalWarrantProgressRepository extends JpaRepository, JpaSpecificationExecutor { - - CommittalWarrantProgressEntity findByDefendantAccountId(Long defendantAccountId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/DebtorDetailRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/DebtorDetailRepository.java index f41736cc8..d15a55d13 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/DebtorDetailRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/DebtorDetailRepository.java @@ -4,10 +4,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; import uk.gov.hmcts.opal.entity.DebtorDetailEntity; -import uk.gov.hmcts.opal.entity.PartyEntity; @Repository public interface DebtorDetailRepository extends JpaRepository, JpaSpecificationExecutor { - DebtorDetailEntity findByParty_PartyId(PartyEntity party); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/DocumentInstanceRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/DocumentInstanceRepository.java index 37f9bf434..7358fd45a 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/DocumentInstanceRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/DocumentInstanceRepository.java @@ -8,6 +8,4 @@ @Repository public interface DocumentInstanceRepository extends JpaRepository, JpaSpecificationExecutor { - - DocumentInstanceEntity findByDocumentInstanceId(Long documentInstanceId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/DocumentRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/DocumentRepository.java index 5e8a89073..25df8e680 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/DocumentRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/DocumentRepository.java @@ -6,8 +6,6 @@ import uk.gov.hmcts.opal.entity.DocumentEntity; @Repository -public interface DocumentRepository extends JpaRepository, +public interface DocumentRepository extends JpaRepository, JpaSpecificationExecutor { - - DocumentEntity findByDocumentId(Long documentId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/EnforcementRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/EnforcementRepository.java index e75905d25..3b81b0759 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/EnforcementRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/EnforcementRepository.java @@ -8,6 +8,4 @@ @Repository public interface EnforcementRepository extends JpaRepository, JpaSpecificationExecutor { - - EnforcementEntity findByEnforcementId(Long enforcementId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/LocalJusticeAreaRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/LocalJusticeAreaRepository.java index e6a4fca1e..c8faddef3 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/LocalJusticeAreaRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/LocalJusticeAreaRepository.java @@ -6,8 +6,6 @@ import uk.gov.hmcts.opal.entity.LocalJusticeAreaEntity; @Repository -public interface LocalJusticeAreaRepository extends JpaRepository, +public interface LocalJusticeAreaRepository extends JpaRepository, JpaSpecificationExecutor { - - LocalJusticeAreaEntity findByLocalJusticeAreaId(Long localJusticeAreaId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/MisDebtorRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/MisDebtorRepository.java index b145a10ac..7478cefff 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/MisDebtorRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/MisDebtorRepository.java @@ -8,6 +8,4 @@ @Repository public interface MisDebtorRepository extends JpaRepository, JpaSpecificationExecutor { - - MisDebtorEntity findByMisDebtorId(Long misDebtorId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/PaymentInRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/PaymentInRepository.java index 3884f5916..b207ee0a8 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/PaymentInRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/PaymentInRepository.java @@ -8,6 +8,4 @@ @Repository public interface PaymentInRepository extends JpaRepository, JpaSpecificationExecutor { - - PaymentInEntity findByPaymentInId(Long paymentInId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/PrisonRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/PrisonRepository.java index 67fc5d606..c66b363a4 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/PrisonRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/PrisonRepository.java @@ -8,6 +8,4 @@ @Repository public interface PrisonRepository extends JpaRepository, JpaSpecificationExecutor { - - PrisonEntity findByPrisonId(Long prisonId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/TillRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/TillRepository.java index 9df0c2bff..44ec3c196 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/TillRepository.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/TillRepository.java @@ -8,6 +8,4 @@ @Repository public interface TillRepository extends JpaRepository, JpaSpecificationExecutor { - - TillEntity findByTillId(Long tillId); } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/AccountTransferSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/AccountTransferSpecs.java new file mode 100644 index 000000000..999f5d116 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/AccountTransferSpecs.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.AccountTransferSearchDto; +import uk.gov.hmcts.opal.entity.AccountTransferEntity; +import uk.gov.hmcts.opal.entity.AccountTransferEntity_; + +public class AccountTransferSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(AccountTransferSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getAccountTransferId()).map(AccountTransferSpecs::equalsAccountTransferId) + )); + } + + public static Specification equalsAccountTransferId(String accountTransferId) { + return (root, query, builder) -> builder.equal(root.get(AccountTransferEntity_.accountTransferId), + accountTransferId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitSpecs.java new file mode 100644 index 000000000..a99efbbd5 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitEntity; +import uk.gov.hmcts.opal.entity.BusinessUnitEntity_; + +public class BusinessUnitSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(BusinessUnitSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getBusinessUnitId()).map(BusinessUnitSpecs::equalsBusinessUnitId) + )); + } + + public static Specification equalsBusinessUnitId(String businessUnitId) { + return (root, query, builder) -> builder.equal(root.get(BusinessUnitEntity_.businessUnitId), businessUnitId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/CommittalWarrantProgressSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/CommittalWarrantProgressSpecs.java new file mode 100644 index 000000000..9993d9e97 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/CommittalWarrantProgressSpecs.java @@ -0,0 +1,24 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.CommittalWarrantProgressSearchDto; +import uk.gov.hmcts.opal.entity.CommittalWarrantProgressEntity; +import uk.gov.hmcts.opal.entity.CommittalWarrantProgressEntity_; + +public class CommittalWarrantProgressSpecs extends EntitySpecs { + + public Specification findBySearchCriteria( + CommittalWarrantProgressSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getDefendantAccountId()) + .map(CommittalWarrantProgressSpecs::equalsCommittalWarrantProgressId) + )); + } + + public static Specification equalsCommittalWarrantProgressId( + String committalWarrantProgressId) { + return (root, query, builder) -> builder.equal(root.get(CommittalWarrantProgressEntity_.defendantAccountId), + committalWarrantProgressId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/CourtSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/CourtSpecs.java new file mode 100644 index 000000000..36e22b10a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/CourtSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.CourtSearchDto; +import uk.gov.hmcts.opal.entity.CourtEntity; +import uk.gov.hmcts.opal.entity.CourtEntity_; + +public class CourtSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(CourtSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getCourtId()).map(CourtSpecs::equalsCourtId) + )); + } + + public static Specification equalsCourtId(String courtId) { + return (root, query, builder) -> builder.equal(root.get(CourtEntity_.courtId), courtId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/DebtorDetailSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/DebtorDetailSpecs.java new file mode 100644 index 000000000..bbdc31e69 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/DebtorDetailSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.DebtorDetailSearchDto; +import uk.gov.hmcts.opal.entity.DebtorDetailEntity; +import uk.gov.hmcts.opal.entity.DebtorDetailEntity_; + +public class DebtorDetailSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(DebtorDetailSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getPartyId()).map(DebtorDetailSpecs::equalsPartyId) + )); + } + + public static Specification equalsPartyId(String partyId) { + return (root, query, builder) -> builder.equal(root.get(DebtorDetailEntity_.partyId), partyId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/DocumentInstanceSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/DocumentInstanceSpecs.java new file mode 100644 index 000000000..deeb4cebb --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/DocumentInstanceSpecs.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.DocumentInstanceSearchDto; +import uk.gov.hmcts.opal.entity.DocumentInstanceEntity; +import uk.gov.hmcts.opal.entity.DocumentInstanceEntity_; + +public class DocumentInstanceSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(DocumentInstanceSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getDocumentInstanceId()).map(DocumentInstanceSpecs::equalsDocumentInstanceId) + )); + } + + public static Specification equalsDocumentInstanceId(String documentInstanceId) { + return (root, query, builder) -> builder.equal(root.get(DocumentInstanceEntity_.documentInstanceId), + documentInstanceId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/DocumentSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/DocumentSpecs.java new file mode 100644 index 000000000..fb69e7ba7 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/DocumentSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.DocumentSearchDto; +import uk.gov.hmcts.opal.entity.DocumentEntity; +import uk.gov.hmcts.opal.entity.DocumentEntity_; + +public class DocumentSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(DocumentSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getDocumentId()).map(DocumentSpecs::equalsDocumentId) + )); + } + + public static Specification equalsDocumentId(String documentId) { + return (root, query, builder) -> builder.equal(root.get(DocumentEntity_.documentId), documentId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/EnforcementSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/EnforcementSpecs.java new file mode 100644 index 000000000..eb4343701 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/EnforcementSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.EnforcementSearchDto; +import uk.gov.hmcts.opal.entity.EnforcementEntity; +import uk.gov.hmcts.opal.entity.EnforcementEntity_; + +public class EnforcementSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(EnforcementSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getEnforcementId()).map(EnforcementSpecs::equalsEnforcementId) + )); + } + + public static Specification equalsEnforcementId(String enforcementId) { + return (root, query, builder) -> builder.equal(root.get(EnforcementEntity_.enforcementId), enforcementId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/EnforcerSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/EnforcerSpecs.java new file mode 100644 index 000000000..4b6588456 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/EnforcerSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.EnforcerSearchDto; +import uk.gov.hmcts.opal.entity.EnforcerEntity; +import uk.gov.hmcts.opal.entity.EnforcerEntity_; + +public class EnforcerSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(EnforcerSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getEnforcerId()).map(EnforcerSpecs::equalsEnforcerId) + )); + } + + public static Specification equalsEnforcerId(String enforcerId) { + return (root, query, builder) -> builder.equal(root.get(EnforcerEntity_.enforcerId), enforcerId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/LocalJusticeAreaSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/LocalJusticeAreaSpecs.java new file mode 100644 index 000000000..ae84b9a1e --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/LocalJusticeAreaSpecs.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.LocalJusticeAreaSearchDto; +import uk.gov.hmcts.opal.entity.LocalJusticeAreaEntity; +import uk.gov.hmcts.opal.entity.LocalJusticeAreaEntity_; + +public class LocalJusticeAreaSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(LocalJusticeAreaSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getLocalJusticeAreaId()).map(LocalJusticeAreaSpecs::equalsLocalJusticeAreaId) + )); + } + + public static Specification equalsLocalJusticeAreaId(String localJusticeAreaId) { + return (root, query, builder) -> builder.equal(root.get(LocalJusticeAreaEntity_.localJusticeAreaId), + localJusticeAreaId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/MisDebtorSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/MisDebtorSpecs.java new file mode 100644 index 000000000..ca8120816 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/MisDebtorSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.MisDebtorSearchDto; +import uk.gov.hmcts.opal.entity.MisDebtorEntity; +import uk.gov.hmcts.opal.entity.MisDebtorEntity_; + +public class MisDebtorSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(MisDebtorSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getMisDebtorId()).map(MisDebtorSpecs::equalsMisDebtorId) + )); + } + + public static Specification equalsMisDebtorId(String misDebtorId) { + return (root, query, builder) -> builder.equal(root.get(MisDebtorEntity_.misDebtorId), misDebtorId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/PartySpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/PartySpecs.java new file mode 100644 index 000000000..b8c4289d9 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/PartySpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.PartySearchDto; +import uk.gov.hmcts.opal.entity.PartyEntity; +import uk.gov.hmcts.opal.entity.PartyEntity_; + +public class PartySpecs extends EntitySpecs { + + public Specification findBySearchCriteria(PartySearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getPartyId()).map(PartySpecs::equalsPartyId) + )); + } + + public static Specification equalsPartyId(String partyId) { + return (root, query, builder) -> builder.equal(root.get(PartyEntity_.partyId), partyId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/PaymentInSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/PaymentInSpecs.java new file mode 100644 index 000000000..f6bdc598a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/PaymentInSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.PaymentInSearchDto; +import uk.gov.hmcts.opal.entity.PaymentInEntity; +import uk.gov.hmcts.opal.entity.PaymentInEntity_; + +public class PaymentInSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(PaymentInSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getPaymentInId()).map(PaymentInSpecs::equalsPaymentInId) + )); + } + + public static Specification equalsPaymentInId(String paymentInId) { + return (root, query, builder) -> builder.equal(root.get(PaymentInEntity_.paymentInId), paymentInId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/PaymentTermsSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/PaymentTermsSpecs.java new file mode 100644 index 000000000..7967a323d --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/PaymentTermsSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.PaymentTermsSearchDto; +import uk.gov.hmcts.opal.entity.PaymentTermsEntity; +import uk.gov.hmcts.opal.entity.PaymentTermsEntity_; + +public class PaymentTermsSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(PaymentTermsSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getPaymentTermsId()).map(PaymentTermsSpecs::equalsPaymentTermsId) + )); + } + + public static Specification equalsPaymentTermsId(String paymentTermsId) { + return (root, query, builder) -> builder.equal(root.get(PaymentTermsEntity_.paymentTermsId), paymentTermsId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/PrisonSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/PrisonSpecs.java new file mode 100644 index 000000000..8d8ffbb9f --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/PrisonSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.PrisonSearchDto; +import uk.gov.hmcts.opal.entity.PrisonEntity; +import uk.gov.hmcts.opal.entity.PrisonEntity_; + +public class PrisonSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(PrisonSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getPrisonId()).map(PrisonSpecs::equalsPrisonId) + )); + } + + public static Specification equalsPrisonId(String prisonId) { + return (root, query, builder) -> builder.equal(root.get(PrisonEntity_.prisonId), prisonId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/TillSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/TillSpecs.java new file mode 100644 index 000000000..87ea9731d --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/TillSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.TillSearchDto; +import uk.gov.hmcts.opal.entity.TillEntity; +import uk.gov.hmcts.opal.entity.TillEntity_; + +public class TillSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(TillSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getTillId()).map(TillSpecs::equalsTillId) + )); + } + + public static Specification equalsTillId(String tillId) { + return (root, query, builder) -> builder.equal(root.get(TillEntity_.tillId), tillId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/DocumentServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/DocumentServiceInterface.java index c10dfe44f..2be0e9bde 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/DocumentServiceInterface.java +++ b/src/main/java/uk/gov/hmcts/opal/service/DocumentServiceInterface.java @@ -7,7 +7,7 @@ public interface DocumentServiceInterface { - DocumentEntity getDocument(long documentId); + DocumentEntity getDocument(String documentId); List searchDocuments(DocumentSearchDto criteria); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/LocalJusticeAreaServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/LocalJusticeAreaServiceInterface.java index 70f29ad01..e2ac0171f 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/LocalJusticeAreaServiceInterface.java +++ b/src/main/java/uk/gov/hmcts/opal/service/LocalJusticeAreaServiceInterface.java @@ -7,7 +7,7 @@ public interface LocalJusticeAreaServiceInterface { - LocalJusticeAreaEntity getLocalJusticeArea(long localJusticeAreaId); + LocalJusticeAreaEntity getLocalJusticeArea(short localJusticeAreaId); List searchLocalJusticeAreas(LocalJusticeAreaSearchDto criteria); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentService.java index 748042d09..ab4f36ed5 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentService.java @@ -27,7 +27,7 @@ public Logger getLog() { } @Override - public DocumentEntity getDocument(long documentId) { + public DocumentEntity getDocument(String documentId) { throw new LegacyGatewayResponseException("Not Yet Implemented"); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaService.java index f10e5d738..5088067ea 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaService.java @@ -27,7 +27,7 @@ public Logger getLog() { } @Override - public LocalJusticeAreaEntity getLocalJusticeArea(long localJusticeAreaId) { + public LocalJusticeAreaEntity getLocalJusticeArea(short localJusticeAreaId) { throw new LegacyGatewayResponseException("Not Yet Implemented"); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/AccountTransferService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/AccountTransferService.java index 46f5269f0..b6c63a9c6 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/AccountTransferService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/AccountTransferService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.AccountTransferSearchDto; import uk.gov.hmcts.opal.entity.AccountTransferEntity; import uk.gov.hmcts.opal.repository.AccountTransferRepository; +import uk.gov.hmcts.opal.repository.jpa.AccountTransferSpecs; import uk.gov.hmcts.opal.service.AccountTransferServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class AccountTransferService implements AccountTransferServiceInterface { private final AccountTransferRepository accountTransferRepository; + private final AccountTransferSpecs specs = new AccountTransferSpecs(); + @Override public AccountTransferEntity getAccountTransfer(long accountTransferId) { return accountTransferRepository.getReferenceById(accountTransferId); @@ -23,7 +28,11 @@ public AccountTransferEntity getAccountTransfer(long accountTransferId) { @Override public List searchAccountTransfers(AccountTransferSearchDto criteria) { - return null; + Page page = accountTransferRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/BusinessUnitService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/BusinessUnitService.java index dd4914709..a515ede5a 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/BusinessUnitService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/BusinessUnitService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; import uk.gov.hmcts.opal.entity.BusinessUnitEntity; import uk.gov.hmcts.opal.repository.BusinessUnitRepository; +import uk.gov.hmcts.opal.repository.jpa.BusinessUnitSpecs; import uk.gov.hmcts.opal.service.BusinessUnitServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class BusinessUnitService implements BusinessUnitServiceInterface { private final BusinessUnitRepository businessUnitRepository; + private final BusinessUnitSpecs specs = new BusinessUnitSpecs(); + @Override public BusinessUnitEntity getBusinessUnit(long businessUnitId) { return businessUnitRepository.getReferenceById(businessUnitId); @@ -23,7 +28,11 @@ public BusinessUnitEntity getBusinessUnit(long businessUnitId) { @Override public List searchBusinessUnits(BusinessUnitSearchDto criteria) { - return null; + Page page = businessUnitRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/CommittalWarrantProgressService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/CommittalWarrantProgressService.java index 8b79fcd70..2a96dbf2f 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/CommittalWarrantProgressService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/CommittalWarrantProgressService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.CommittalWarrantProgressSearchDto; import uk.gov.hmcts.opal.entity.CommittalWarrantProgressEntity; import uk.gov.hmcts.opal.repository.CommittalWarrantProgressRepository; +import uk.gov.hmcts.opal.repository.jpa.CommittalWarrantProgressSpecs; import uk.gov.hmcts.opal.service.CommittalWarrantProgressServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class CommittalWarrantProgressService implements CommittalWarrantProgress private final CommittalWarrantProgressRepository committalWarrantProgressRepository; + private final CommittalWarrantProgressSpecs specs = new CommittalWarrantProgressSpecs(); + @Override public CommittalWarrantProgressEntity getCommittalWarrantProgress(long committalWarrantProgressId) { return committalWarrantProgressRepository.getReferenceById(committalWarrantProgressId); @@ -24,7 +29,11 @@ public CommittalWarrantProgressEntity getCommittalWarrantProgress(long committal @Override public List searchCommittalWarrantProgresss( CommittalWarrantProgressSearchDto criteria) { - return null; + Page page = committalWarrantProgressRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/CourtService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/CourtService.java index e19f03a70..0b40294d2 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/CourtService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/CourtService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.CourtSearchDto; import uk.gov.hmcts.opal.entity.CourtEntity; import uk.gov.hmcts.opal.repository.CourtRepository; +import uk.gov.hmcts.opal.repository.jpa.CourtSpecs; import uk.gov.hmcts.opal.service.CourtServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class CourtService implements CourtServiceInterface { private final CourtRepository courtRepository; + private final CourtSpecs specs = new CourtSpecs(); + @Override public CourtEntity getCourt(long courtId) { return courtRepository.getReferenceById(courtId); @@ -23,7 +28,9 @@ public CourtEntity getCourt(long courtId) { @Override public List searchCourts(CourtSearchDto criteria) { - return null; + Page courtsPage = courtRepository + .findBy(specs.findBySearchCriteria(criteria), ffq -> ffq.page(Pageable.unpaged())); + return courtsPage.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/DebtorDetailService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/DebtorDetailService.java index 8d1073b7d..d92b102cb 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/DebtorDetailService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/DebtorDetailService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.DebtorDetailSearchDto; import uk.gov.hmcts.opal.entity.DebtorDetailEntity; import uk.gov.hmcts.opal.repository.DebtorDetailRepository; +import uk.gov.hmcts.opal.repository.jpa.DebtorDetailSpecs; import uk.gov.hmcts.opal.service.DebtorDetailServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class DebtorDetailService implements DebtorDetailServiceInterface { private final DebtorDetailRepository debtorDetailRepository; + private final DebtorDetailSpecs specs = new DebtorDetailSpecs(); + @Override public DebtorDetailEntity getDebtorDetail(long debtorDetailId) { return debtorDetailRepository.getReferenceById(debtorDetailId); @@ -23,7 +28,11 @@ public DebtorDetailEntity getDebtorDetail(long debtorDetailId) { @Override public List searchDebtorDetails(DebtorDetailSearchDto criteria) { - return null; + Page page = debtorDetailRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/DocumentInstanceService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/DocumentInstanceService.java index 3ba89cc96..9f0f04756 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/DocumentInstanceService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/DocumentInstanceService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.DocumentInstanceSearchDto; import uk.gov.hmcts.opal.entity.DocumentInstanceEntity; import uk.gov.hmcts.opal.repository.DocumentInstanceRepository; +import uk.gov.hmcts.opal.repository.jpa.DocumentInstanceSpecs; import uk.gov.hmcts.opal.service.DocumentInstanceServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class DocumentInstanceService implements DocumentInstanceServiceInterface private final DocumentInstanceRepository documentInstanceRepository; + private final DocumentInstanceSpecs specs = new DocumentInstanceSpecs(); + @Override public DocumentInstanceEntity getDocumentInstance(long documentInstanceId) { return documentInstanceRepository.getReferenceById(documentInstanceId); @@ -23,7 +28,11 @@ public DocumentInstanceEntity getDocumentInstance(long documentInstanceId) { @Override public List searchDocumentInstances(DocumentInstanceSearchDto criteria) { - return null; + Page page = documentInstanceRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/DocumentService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/DocumentService.java index d286e365d..8e2ed1de3 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/DocumentService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/DocumentService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.DocumentSearchDto; import uk.gov.hmcts.opal.entity.DocumentEntity; import uk.gov.hmcts.opal.repository.DocumentRepository; +import uk.gov.hmcts.opal.repository.jpa.DocumentSpecs; import uk.gov.hmcts.opal.service.DocumentServiceInterface; import java.util.List; @@ -16,14 +19,20 @@ public class DocumentService implements DocumentServiceInterface { private final DocumentRepository documentRepository; + private final DocumentSpecs specs = new DocumentSpecs(); + @Override - public DocumentEntity getDocument(long documentId) { + public DocumentEntity getDocument(String documentId) { return documentRepository.getReferenceById(documentId); } @Override public List searchDocuments(DocumentSearchDto criteria) { - return null; + Page page = documentRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/EnforcementService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/EnforcementService.java index 39a92f241..6e97830dc 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/EnforcementService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/EnforcementService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.EnforcementSearchDto; import uk.gov.hmcts.opal.entity.EnforcementEntity; import uk.gov.hmcts.opal.repository.EnforcementRepository; +import uk.gov.hmcts.opal.repository.jpa.EnforcementSpecs; import uk.gov.hmcts.opal.service.EnforcementServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class EnforcementService implements EnforcementServiceInterface { private final EnforcementRepository enforcementRepository; + private final EnforcementSpecs specs = new EnforcementSpecs(); + @Override public EnforcementEntity getEnforcement(long enforcementId) { return enforcementRepository.getReferenceById(enforcementId); @@ -23,7 +28,11 @@ public EnforcementEntity getEnforcement(long enforcementId) { @Override public List searchEnforcements(EnforcementSearchDto criteria) { - return null; + Page page = enforcementRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/EnforcerService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/EnforcerService.java index 3bb842803..91fcd754e 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/EnforcerService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/EnforcerService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.EnforcerSearchDto; import uk.gov.hmcts.opal.entity.EnforcerEntity; import uk.gov.hmcts.opal.repository.EnforcerRepository; +import uk.gov.hmcts.opal.repository.jpa.EnforcerSpecs; import uk.gov.hmcts.opal.service.EnforcerServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class EnforcerService implements EnforcerServiceInterface { private final EnforcerRepository enforcerRepository; + private final EnforcerSpecs specs = new EnforcerSpecs(); + @Override public EnforcerEntity getEnforcer(long enforcerId) { return enforcerRepository.getReferenceById(enforcerId); @@ -23,7 +28,11 @@ public EnforcerEntity getEnforcer(long enforcerId) { @Override public List searchEnforcers(EnforcerSearchDto criteria) { - return null; + Page page = enforcerRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/LocalJusticeAreaService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/LocalJusticeAreaService.java index 88dd2bce3..198d58526 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/LocalJusticeAreaService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/LocalJusticeAreaService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.LocalJusticeAreaSearchDto; import uk.gov.hmcts.opal.entity.LocalJusticeAreaEntity; import uk.gov.hmcts.opal.repository.LocalJusticeAreaRepository; +import uk.gov.hmcts.opal.repository.jpa.LocalJusticeAreaSpecs; import uk.gov.hmcts.opal.service.LocalJusticeAreaServiceInterface; import java.util.List; @@ -16,14 +19,20 @@ public class LocalJusticeAreaService implements LocalJusticeAreaServiceInterface private final LocalJusticeAreaRepository localJusticeAreaRepository; + private final LocalJusticeAreaSpecs specs = new LocalJusticeAreaSpecs(); + @Override - public LocalJusticeAreaEntity getLocalJusticeArea(long localJusticeAreaId) { + public LocalJusticeAreaEntity getLocalJusticeArea(short localJusticeAreaId) { return localJusticeAreaRepository.getReferenceById(localJusticeAreaId); } @Override public List searchLocalJusticeAreas(LocalJusticeAreaSearchDto criteria) { - return null; + Page page = localJusticeAreaRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/MisDebtorService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/MisDebtorService.java index df7692316..a8982d18c 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/MisDebtorService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/MisDebtorService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.MisDebtorSearchDto; import uk.gov.hmcts.opal.entity.MisDebtorEntity; import uk.gov.hmcts.opal.repository.MisDebtorRepository; +import uk.gov.hmcts.opal.repository.jpa.MisDebtorSpecs; import uk.gov.hmcts.opal.service.MisDebtorServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class MisDebtorService implements MisDebtorServiceInterface { private final MisDebtorRepository misDebtorRepository; + private final MisDebtorSpecs specs = new MisDebtorSpecs(); + @Override public MisDebtorEntity getMisDebtor(long misDebtorId) { return misDebtorRepository.getReferenceById(misDebtorId); @@ -23,7 +28,11 @@ public MisDebtorEntity getMisDebtor(long misDebtorId) { @Override public List searchMisDebtors(MisDebtorSearchDto criteria) { - return null; + Page page = misDebtorRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/PartyService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/PartyService.java index 90b33c223..dd3589ae0 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/PartyService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/PartyService.java @@ -2,6 +2,8 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.PartyDto; @@ -9,6 +11,7 @@ import uk.gov.hmcts.opal.entity.PartyEntity; import uk.gov.hmcts.opal.entity.PartySummary; import uk.gov.hmcts.opal.repository.PartyRepository; +import uk.gov.hmcts.opal.repository.jpa.PartySpecs; import uk.gov.hmcts.opal.service.PartyServiceInterface; import java.util.List; @@ -19,6 +22,8 @@ public class PartyService implements PartyServiceInterface { private final PartyRepository partyRepository; + private final PartySpecs specs = new PartySpecs(); + @Override public PartyDto getParty(long partyId) { return toDto(partyRepository.getReferenceById(partyId)); @@ -35,7 +40,11 @@ public List searchForParty(AccountSearchDto accountSearchDto) { @Override public List searchParties(PartySearchDto criteria) { - return null; + Page page = partyRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/PaymentInService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/PaymentInService.java index 1fa4d1e08..b153066e6 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/PaymentInService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/PaymentInService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.PaymentInSearchDto; import uk.gov.hmcts.opal.entity.PaymentInEntity; import uk.gov.hmcts.opal.repository.PaymentInRepository; +import uk.gov.hmcts.opal.repository.jpa.PaymentInSpecs; import uk.gov.hmcts.opal.service.PaymentInServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class PaymentInService implements PaymentInServiceInterface { private final PaymentInRepository paymentInRepository; + private final PaymentInSpecs specs = new PaymentInSpecs(); + @Override public PaymentInEntity getPaymentIn(long paymentInId) { return paymentInRepository.getReferenceById(paymentInId); @@ -23,7 +28,11 @@ public PaymentInEntity getPaymentIn(long paymentInId) { @Override public List searchPaymentIns(PaymentInSearchDto criteria) { - return null; + Page page = paymentInRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/PaymentTermsService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/PaymentTermsService.java index 273a67b26..74f077ba7 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/PaymentTermsService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/PaymentTermsService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.PaymentTermsSearchDto; import uk.gov.hmcts.opal.entity.PaymentTermsEntity; import uk.gov.hmcts.opal.repository.PaymentTermsRepository; +import uk.gov.hmcts.opal.repository.jpa.PaymentTermsSpecs; import uk.gov.hmcts.opal.service.PaymentTermsServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class PaymentTermsService implements PaymentTermsServiceInterface { private final PaymentTermsRepository paymentTermsRepository; + private final PaymentTermsSpecs specs = new PaymentTermsSpecs(); + @Override public PaymentTermsEntity getPaymentTerms(long paymentTermsId) { return paymentTermsRepository.getReferenceById(paymentTermsId); @@ -23,7 +28,11 @@ public PaymentTermsEntity getPaymentTerms(long paymentTermsId) { @Override public List searchPaymentTerms(PaymentTermsSearchDto criteria) { - return null; + Page page = paymentTermsRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/PrisonService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/PrisonService.java index 99fe90987..f33daf8ec 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/PrisonService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/PrisonService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.PrisonSearchDto; import uk.gov.hmcts.opal.entity.PrisonEntity; import uk.gov.hmcts.opal.repository.PrisonRepository; +import uk.gov.hmcts.opal.repository.jpa.PrisonSpecs; import uk.gov.hmcts.opal.service.PrisonServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class PrisonService implements PrisonServiceInterface { private final PrisonRepository prisonRepository; + private final PrisonSpecs specs = new PrisonSpecs(); + @Override public PrisonEntity getPrison(long prisonId) { return prisonRepository.getReferenceById(prisonId); @@ -23,7 +28,11 @@ public PrisonEntity getPrison(long prisonId) { @Override public List searchPrisons(PrisonSearchDto criteria) { - return null; + Page page = prisonRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/TillService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/TillService.java index 4b1899541..8ab875038 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/TillService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/TillService.java @@ -2,10 +2,13 @@ import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.TillSearchDto; import uk.gov.hmcts.opal.entity.TillEntity; import uk.gov.hmcts.opal.repository.TillRepository; +import uk.gov.hmcts.opal.repository.jpa.TillSpecs; import uk.gov.hmcts.opal.service.TillServiceInterface; import java.util.List; @@ -16,6 +19,8 @@ public class TillService implements TillServiceInterface { private final TillRepository tillRepository; + private final TillSpecs specs = new TillSpecs(); + @Override public TillEntity getTill(long tillId) { return tillRepository.getReferenceById(tillId); @@ -23,7 +28,11 @@ public TillEntity getTill(long tillId) { @Override public List searchTills(TillSearchDto criteria) { - return null; + Page page = tillRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxy.java index 2674b9f84..b2e72758b 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxy.java @@ -26,7 +26,7 @@ private DocumentServiceInterface getCurrentModeService() { } @Override - public DocumentEntity getDocument(long documentId) { + public DocumentEntity getDocument(String documentId) { return getCurrentModeService().getDocument(documentId); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxy.java index 352515169..c433433ce 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxy.java @@ -26,7 +26,7 @@ private LocalJusticeAreaServiceInterface getCurrentModeService() { } @Override - public LocalJusticeAreaEntity getLocalJusticeArea(long localJusticeAreaId) { + public LocalJusticeAreaEntity getLocalJusticeArea(short localJusticeAreaId) { return getCurrentModeService().getLocalJusticeArea(localJusticeAreaId); } diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/DocumentControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/DocumentControllerTest.java index 8c8f239f4..83b72d708 100644 --- a/src/test/java/uk/gov/hmcts/opal/controllers/DocumentControllerTest.java +++ b/src/test/java/uk/gov/hmcts/opal/controllers/DocumentControllerTest.java @@ -33,15 +33,15 @@ void testGetDocument_Success() { // Arrange DocumentEntity entity = DocumentEntity.builder().build(); //some id assigned by db sequence - when(documentService.getDocument(any(Long.class))).thenReturn(entity); + when(documentService.getDocument(any(String.class))).thenReturn(entity); // Act - ResponseEntity response = documentController.getDocumentById(1L); + ResponseEntity response = documentController.getDocumentById("ID1"); // Assert assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(entity, response.getBody()); - verify(documentService, times(1)).getDocument(any(Long.class)); + verify(documentService, times(1)).getDocument(any(String.class)); } @Test diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/LocalJusticeAreaControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/LocalJusticeAreaControllerTest.java index fb21a8ed9..0ff2514e8 100644 --- a/src/test/java/uk/gov/hmcts/opal/controllers/LocalJusticeAreaControllerTest.java +++ b/src/test/java/uk/gov/hmcts/opal/controllers/LocalJusticeAreaControllerTest.java @@ -15,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyShort; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -33,15 +34,15 @@ void testGetLocalJusticeArea_Success() { // Arrange LocalJusticeAreaEntity entity = LocalJusticeAreaEntity.builder().build(); //some id assigned by db sequence - when(localJusticeAreaService.getLocalJusticeArea(any(Long.class))).thenReturn(entity); + when(localJusticeAreaService.getLocalJusticeArea(anyShort())).thenReturn(entity); // Act - ResponseEntity response = localJusticeAreaController.getLocalJusticeAreaById(1L); + ResponseEntity response = localJusticeAreaController.getLocalJusticeAreaById((short)1); // Assert assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(entity, response.getBody()); - verify(localJusticeAreaService, times(1)).getLocalJusticeArea(any(Long.class)); + verify(localJusticeAreaService, times(1)).getLocalJusticeArea(anyShort()); } @Test diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/PaymentTermsControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/PaymentTermsControllerTest.java index ce4653786..54eeafa54 100644 --- a/src/test/java/uk/gov/hmcts/opal/controllers/PaymentTermsControllerTest.java +++ b/src/test/java/uk/gov/hmcts/opal/controllers/PaymentTermsControllerTest.java @@ -54,7 +54,7 @@ void testSearchPaymentTermss_Success() { // Act PaymentTermsSearchDto searchDto = PaymentTermsSearchDto.builder().build(); - ResponseEntity> response = paymentTermsController.postPaymentTermssSearch(searchDto); + ResponseEntity> response = paymentTermsController.postPaymentTermsSearch(searchDto); // Assert assertEquals(HttpStatus.OK, response.getStatusCode()); diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentServiceTest.java index 6fa11840a..189b255d5 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentServiceTest.java @@ -31,7 +31,7 @@ void testGetDocument() { // Act LegacyGatewayResponseException exception = assertThrows( LegacyGatewayResponseException.class, - () -> legacyDocumentService.getDocument(1) + () -> legacyDocumentService.getDocument("ID1") ); // Assert diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaServiceTest.java index 41725ed0d..a81b82eaf 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaServiceTest.java @@ -31,7 +31,7 @@ void testGetLocalJusticeArea() { // Act LegacyGatewayResponseException exception = assertThrows( LegacyGatewayResponseException.class, - () -> legacyLocalJusticeAreaService.getLocalJusticeArea(1) + () -> legacyLocalJusticeAreaService.getLocalJusticeArea((short)1) ); // Assert diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/AccountTransferServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/AccountTransferServiceTest.java index 0573cd0b8..9345d970c 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/AccountTransferServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/AccountTransferServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.AccountTransferSearchDto; import uk.gov.hmcts.opal.entity.AccountTransferEntity; import uk.gov.hmcts.opal.repository.AccountTransferRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,21 +47,26 @@ void testGetAccountTransfer() { } + @SuppressWarnings("unchecked") @Test void testSearchAccountTransfers() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); AccountTransferEntity accountTransferEntity = AccountTransferEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(accountTransferEntity), Pageable.unpaged(), 999L); - // when(accountTransferRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(accountTransferRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = accountTransferService .searchAccountTransfers(AccountTransferSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(accountTransferEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/BusinessUnitServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/BusinessUnitServiceTest.java index 3b4aa6b9d..3bc329272 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/BusinessUnitServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/BusinessUnitServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; import uk.gov.hmcts.opal.entity.BusinessUnitEntity; import uk.gov.hmcts.opal.repository.BusinessUnitRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,20 +47,25 @@ void testGetBusinessUnit() { } + @SuppressWarnings("unchecked") @Test void testSearchBusinessUnits() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); BusinessUnitEntity businessUnitEntity = BusinessUnitEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(businessUnitEntity), Pageable.unpaged(), 999L); - // when(businessUnitRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(businessUnitRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = businessUnitService .searchBusinessUnits(BusinessUnitSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(businessUnitEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/CommittalWarrantProgressServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/CommittalWarrantProgressServiceTest.java index 25e9ad58b..cdce3e100 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/CommittalWarrantProgressServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/CommittalWarrantProgressServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.CommittalWarrantProgressSearchDto; import uk.gov.hmcts.opal.entity.CommittalWarrantProgressEntity; import uk.gov.hmcts.opal.repository.CommittalWarrantProgressRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -45,22 +49,27 @@ void testGetCommittalWarrantProgress() { } + @SuppressWarnings("unchecked") @Test void testSearchCommittalWarrantProgresss() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); CommittalWarrantProgressEntity committalWarrantProgressEntity = CommittalWarrantProgressEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(committalWarrantProgressEntity), Pageable.unpaged(), 999L); - // when(committalWarrantProgressRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(committalWarrantProgressRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = committalWarrantProgressService .searchCommittalWarrantProgresss(CommittalWarrantProgressSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(committalWarrantProgressEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/CourtServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/CourtServiceTest.java index f5d14de36..6f92a9ce8 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/CourtServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/CourtServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.CourtSearchDto; import uk.gov.hmcts.opal.entity.CourtEntity; import uk.gov.hmcts.opal.repository.CourtRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,19 +47,24 @@ void testGetCourt() { } + @SuppressWarnings("unchecked") @Test void testSearchCourts() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); CourtEntity courtEntity = CourtEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(courtEntity), Pageable.unpaged(), 999L); - // when(courtRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(courtRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = courtService.searchCourts(CourtSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(courtEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/DebtorDetailServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/DebtorDetailServiceTest.java index 71838ac0c..9878a6f28 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/DebtorDetailServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/DebtorDetailServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.DebtorDetailSearchDto; import uk.gov.hmcts.opal.entity.DebtorDetailEntity; import uk.gov.hmcts.opal.repository.DebtorDetailRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,20 +47,25 @@ void testGetDebtorDetail() { } + @SuppressWarnings("unchecked") @Test void testSearchDebtorDetails() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); DebtorDetailEntity debtorDetailEntity = DebtorDetailEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(debtorDetailEntity), Pageable.unpaged(), 999L); - // when(debtorDetailRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(debtorDetailRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = debtorDetailService .searchDebtorDetails(DebtorDetailSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(debtorDetailEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/DocumentInstanceServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/DocumentInstanceServiceTest.java index 3887106d0..2c5cd5d69 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/DocumentInstanceServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/DocumentInstanceServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.DocumentInstanceSearchDto; import uk.gov.hmcts.opal.entity.DocumentInstanceEntity; import uk.gov.hmcts.opal.repository.DocumentInstanceRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,21 +47,26 @@ void testGetDocumentInstance() { } + @SuppressWarnings("unchecked") @Test void testSearchDocumentInstances() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); DocumentInstanceEntity documentInstanceEntity = DocumentInstanceEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(documentInstanceEntity), Pageable.unpaged(), 999L); - // when(documentInstanceRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(documentInstanceRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = documentInstanceService.searchDocumentInstances( DocumentInstanceSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(documentInstanceEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/DocumentServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/DocumentServiceTest.java index ea92399e8..28e7c09b3 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/DocumentServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/DocumentServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.DocumentSearchDto; import uk.gov.hmcts.opal.entity.DocumentEntity; import uk.gov.hmcts.opal.repository.DocumentRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -36,26 +40,31 @@ void testGetDocument() { when(documentRepository.getReferenceById(any())).thenReturn(documentEntity); // Act - DocumentEntity result = documentService.getDocument(1); + DocumentEntity result = documentService.getDocument("ID1"); // Assert assertNotNull(result); } + @SuppressWarnings("unchecked") @Test void testSearchDocuments() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); DocumentEntity documentEntity = DocumentEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(documentEntity), Pageable.unpaged(), 999L); - // when(documentRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(documentRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = documentService.searchDocuments(DocumentSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(documentEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/EnforcementServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/EnforcementServiceTest.java index de6a115a5..e1099d433 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/EnforcementServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/EnforcementServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.EnforcementSearchDto; import uk.gov.hmcts.opal.entity.EnforcementEntity; import uk.gov.hmcts.opal.repository.EnforcementRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,19 +47,24 @@ void testGetEnforcement() { } + @SuppressWarnings("unchecked") @Test void testSearchEnforcements() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); EnforcementEntity enforcementEntity = EnforcementEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(enforcementEntity), Pageable.unpaged(), 999L); - // when(enforcementRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(enforcementRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = enforcementService.searchEnforcements(EnforcementSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(enforcementEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/EnforcerServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/EnforcerServiceTest.java index e97f42f16..e106b9e6e 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/EnforcerServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/EnforcerServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.EnforcerSearchDto; import uk.gov.hmcts.opal.entity.EnforcerEntity; import uk.gov.hmcts.opal.repository.EnforcerRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,19 +47,24 @@ void testGetEnforcer() { } + @SuppressWarnings("unchecked") @Test void testSearchEnforcers() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); EnforcerEntity enforcerEntity = EnforcerEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(enforcerEntity), Pageable.unpaged(), 999L); - // when(enforcerRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(enforcerRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = enforcerService.searchEnforcers(EnforcerSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(enforcerEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/LocalJusticeAreaServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/LocalJusticeAreaServiceTest.java index 0ef948929..91bfc4e43 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/LocalJusticeAreaServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/LocalJusticeAreaServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.LocalJusticeAreaSearchDto; import uk.gov.hmcts.opal.entity.LocalJusticeAreaEntity; import uk.gov.hmcts.opal.repository.LocalJusticeAreaRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -36,28 +40,33 @@ void testGetLocalJusticeArea() { when(localJusticeAreaRepository.getReferenceById(any())).thenReturn(localJusticeAreaEntity); // Act - LocalJusticeAreaEntity result = localJusticeAreaService.getLocalJusticeArea(1); + LocalJusticeAreaEntity result = localJusticeAreaService.getLocalJusticeArea((short)1); // Assert assertNotNull(result); } + @SuppressWarnings("unchecked") @Test void testSearchLocalJusticeAreas() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); LocalJusticeAreaEntity localJusticeAreaEntity = LocalJusticeAreaEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(localJusticeAreaEntity), Pageable.unpaged(), 999L); - // when(localJusticeAreaRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(localJusticeAreaRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = localJusticeAreaService .searchLocalJusticeAreas(LocalJusticeAreaSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(localJusticeAreaEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/MisDebtorServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/MisDebtorServiceTest.java index 607e6001f..e527511ea 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/MisDebtorServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/MisDebtorServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.MisDebtorSearchDto; import uk.gov.hmcts.opal.entity.MisDebtorEntity; import uk.gov.hmcts.opal.repository.MisDebtorRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,19 +47,24 @@ void testGetMisDebtor() { } + @SuppressWarnings("unchecked") @Test void testSearchMisDebtors() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); MisDebtorEntity misDebtorEntity = MisDebtorEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(misDebtorEntity), Pageable.unpaged(), 999L); - // when(misDebtorRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(misDebtorRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = misDebtorService.searchMisDebtors(MisDebtorSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(misDebtorEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/NoteServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/NoteServiceTest.java index 0b73a20ca..ff6de7f90 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/NoteServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/NoteServiceTest.java @@ -5,11 +5,13 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.NoteDto; import uk.gov.hmcts.opal.dto.search.NoteSearchDto; import uk.gov.hmcts.opal.entity.NoteEntity; @@ -17,6 +19,7 @@ import java.time.LocalDateTime; import java.util.List; +import java.util.function.Function; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -103,10 +106,15 @@ void testSaveNoteWithNullPostedDate() { @Test void testSearchNotes() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); + when(ffq.sortBy(any())).thenReturn(ffq); NoteEntity noteEntity = NoteEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(noteEntity), Pageable.unpaged(), 999L); - when(noteRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(noteRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = noteService.searchNotes(NoteSearchDto.builder().build()); diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/PartyServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/PartyServiceTest.java index 755e42230..ff113d5a7 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/PartyServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/PartyServiceTest.java @@ -4,10 +4,13 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.PartyDto; import uk.gov.hmcts.opal.dto.search.PartySearchDto; @@ -19,9 +22,9 @@ import java.time.LocalDateTime; import java.util.Collections; import java.util.List; +import java.util.function.Function; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -83,19 +86,24 @@ void testSearchForParty() { verify(partyRepository, times(1)).findBySurnameContaining(any()); } + @SuppressWarnings("unchecked") @Test void testSearchParties() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); PartyEntity partyEntity = PartyEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(partyEntity), Pageable.unpaged(), 999L); - // when(partyRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(partyRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = partyService.searchParties(PartySearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(partyEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/PaymentInServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/PaymentInServiceTest.java index 3a20cf308..d0f829007 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/PaymentInServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/PaymentInServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.PaymentInSearchDto; import uk.gov.hmcts.opal.entity.PaymentInEntity; import uk.gov.hmcts.opal.repository.PaymentInRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,19 +47,24 @@ void testGetPaymentIn() { } + @SuppressWarnings("unchecked") @Test void testSearchPaymentIns() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); PaymentInEntity paymentInEntity = PaymentInEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(paymentInEntity), Pageable.unpaged(), 999L); - // when(paymentInRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(paymentInRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = paymentInService.searchPaymentIns(PaymentInSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(paymentInEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/PaymentTermsServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/PaymentTermsServiceTest.java index 1434b17e7..926087ae2 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/PaymentTermsServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/PaymentTermsServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.PaymentTermsSearchDto; import uk.gov.hmcts.opal.entity.PaymentTermsEntity; import uk.gov.hmcts.opal.repository.PaymentTermsRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,20 +47,25 @@ void testGetPaymentTerms() { } + @SuppressWarnings("unchecked") @Test void testSearchPaymentTermss() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); PaymentTermsEntity paymentTermsEntity = PaymentTermsEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(paymentTermsEntity), Pageable.unpaged(), 999L); - // when(paymentTermsRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(paymentTermsRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = paymentTermsService .searchPaymentTerms(PaymentTermsSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(paymentTermsEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/PrisonServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/PrisonServiceTest.java index 9b81370ef..5dfb93bd4 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/PrisonServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/PrisonServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.PrisonSearchDto; import uk.gov.hmcts.opal.entity.PrisonEntity; import uk.gov.hmcts.opal.repository.PrisonRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,19 +47,24 @@ void testGetPrison() { } + @SuppressWarnings("unchecked") @Test void testSearchPrisons() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); PrisonEntity prisonEntity = PrisonEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(prisonEntity), Pageable.unpaged(), 999L); - // when(prisonRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(prisonRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = prisonService.searchPrisons(PrisonSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(prisonEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/TillServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/TillServiceTest.java index a7b2de9f7..02fdb3ec4 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/TillServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/TillServiceTest.java @@ -4,18 +4,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; import uk.gov.hmcts.opal.dto.search.TillSearchDto; import uk.gov.hmcts.opal.entity.TillEntity; import uk.gov.hmcts.opal.repository.TillRepository; import java.util.List; +import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,19 +47,24 @@ void testGetTill() { } + @SuppressWarnings("unchecked") @Test void testSearchTills() { // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); TillEntity tillEntity = TillEntity.builder().build(); Page mockPage = new PageImpl<>(List.of(tillEntity), Pageable.unpaged(), 999L); - // when(tillRepository.findBy(any(Specification.class), any())).thenReturn(mockPage); + when(tillRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); // Act List result = tillService.searchTills(TillSearchDto.builder().build()); // Assert - assertNull(result); + assertEquals(List.of(tillEntity), result); } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxyTest.java index cbc147d07..73d6f3087 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxyTest.java @@ -17,7 +17,7 @@ import java.util.List; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; @@ -54,13 +54,13 @@ void shouldUseOpalDocumentServiceWhenModeIsNotLegacy() { DocumentEntity entity = DocumentEntity.builder().build(); AppMode appMode = AppMode.builder().mode("opal").build(); when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalDocumentService.getDocument(anyLong())).thenReturn(entity); + when(opalDocumentService.getDocument(anyString())).thenReturn(entity); // When: saveDocument is called on the proxy - DocumentEntity documentResult = documentServiceProxy.getDocument(1); + DocumentEntity documentResult = documentServiceProxy.getDocument("ID1"); // Then: opalDocumentService should be used, and the returned document should be as expected - verify(opalDocumentService).getDocument(1); + verify(opalDocumentService).getDocument("ID1"); verifyNoInteractions(legacyDocumentService); Assertions.assertEquals(entity, documentResult); @@ -84,13 +84,13 @@ void shouldUseLegacyDocumentServiceWhenModeIsLegacy() { DocumentEntity entity = DocumentEntity.builder().build(); AppMode appMode = AppMode.builder().mode("legacy").build(); when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyDocumentService.getDocument(anyLong())).thenReturn(entity); + when(legacyDocumentService.getDocument(anyString())).thenReturn(entity); // When: saveDocument is called on the proxy - DocumentEntity result = documentServiceProxy.getDocument(1); + DocumentEntity result = documentServiceProxy.getDocument("ID1"); // Then: legacyDocumentService should be used, and the returned document should be as expected - verify(legacyDocumentService).getDocument(1); + verify(legacyDocumentService).getDocument("ID1"); verifyNoInteractions(opalDocumentService); Assertions.assertEquals(entity, result); diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxyTest.java index edfeecf69..fa290a350 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxyTest.java @@ -17,7 +17,7 @@ import java.util.List; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyShort; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; @@ -54,13 +54,13 @@ void shouldUseOpalLocalJusticeAreaServiceWhenModeIsNotLegacy() { LocalJusticeAreaEntity entity = LocalJusticeAreaEntity.builder().build(); AppMode appMode = AppMode.builder().mode("opal").build(); when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalLocalJusticeAreaService.getLocalJusticeArea(anyLong())).thenReturn(entity); + when(opalLocalJusticeAreaService.getLocalJusticeArea(anyShort())).thenReturn(entity); // When: saveLocalJusticeArea is called on the proxy - LocalJusticeAreaEntity localJusticeAreaResult = localJusticeAreaServiceProxy.getLocalJusticeArea(1); + LocalJusticeAreaEntity localJusticeAreaResult = localJusticeAreaServiceProxy.getLocalJusticeArea((short)1); // Then: opalLocalJusticeAreaService should be used, and the returned localJusticeArea should be as expected - verify(opalLocalJusticeAreaService).getLocalJusticeArea(1); + verify(opalLocalJusticeAreaService).getLocalJusticeArea((short)1); verifyNoInteractions(legacyLocalJusticeAreaService); Assertions.assertEquals(entity, localJusticeAreaResult); @@ -84,13 +84,13 @@ void shouldUseLegacyLocalJusticeAreaServiceWhenModeIsLegacy() { LocalJusticeAreaEntity entity = LocalJusticeAreaEntity.builder().build(); AppMode appMode = AppMode.builder().mode("legacy").build(); when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyLocalJusticeAreaService.getLocalJusticeArea(anyLong())).thenReturn(entity); + when(legacyLocalJusticeAreaService.getLocalJusticeArea(anyShort())).thenReturn(entity); // When: saveLocalJusticeArea is called on the proxy - LocalJusticeAreaEntity result = localJusticeAreaServiceProxy.getLocalJusticeArea(1); + LocalJusticeAreaEntity result = localJusticeAreaServiceProxy.getLocalJusticeArea((short)1); // Then: legacyLocalJusticeAreaService should be used, and the returned localJusticeArea should be as expected - verify(legacyLocalJusticeAreaService).getLocalJusticeArea(1); + verify(legacyLocalJusticeAreaService).getLocalJusticeArea((short)1); verifyNoInteractions(opalLocalJusticeAreaService); Assertions.assertEquals(entity, result);