From 231d5eefa8ccb4e1001ae95655bc558a140b10f0 Mon Sep 17 00:00:00 2001 From: Russell Dodd Date: Mon, 13 May 2024 17:21:12 +0100 Subject: [PATCH 1/5] Tweaks to the Business Unit reference data --- ...BusinessUnitControllerIntegrationTest.java | 6 +-- .../controllers/BusinessUnitController.java | 3 +- .../BusinessUnitReferenceDataResults.java | 6 +-- .../hmcts/opal/entity/BusinessUnitEntity.java | 11 ++++- .../projection/BusinessUnitReferenceData.java | 17 ++++++++ .../repository/jpa/BusinessUnitSpecs.java | 9 ++++- .../service/opal/BusinessUnitService.java | 6 ++- .../BusinessUnitControllerTest.java | 40 ++++++++++++++++++- .../service/opal/BusinessUnitServiceTest.java | 4 +- 9 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 src/main/java/uk/gov/hmcts/opal/entity/projection/BusinessUnitReferenceData.java diff --git a/src/integrationTest/java/uk/gov/hmcts/opal/controllers/BusinessUnitControllerIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/opal/controllers/BusinessUnitControllerIntegrationTest.java index 4488c8d47..0f6aadbac 100644 --- a/src/integrationTest/java/uk/gov/hmcts/opal/controllers/BusinessUnitControllerIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/opal/controllers/BusinessUnitControllerIntegrationTest.java @@ -49,7 +49,7 @@ void testGetBusinessUnitById() throws Exception { .andExpect(jsonPath("$.businessUnitCode").value("AAAA")) .andExpect(jsonPath("$.businessUnitType").value("LARGE UNIT")) .andExpect(jsonPath("$.accountNumberPrefix").value("XX")) - .andExpect(jsonPath("$.parentBusinessUnitId").value(99)); + .andExpect(jsonPath("$.parentBusinessUnit.businessUnitId").value(99)); } @@ -78,7 +78,7 @@ void testPostBusinessUnitsSearch() throws Exception { .andExpect(jsonPath("$[0].businessUnitCode").value("AAAA")) .andExpect(jsonPath("$[0].businessUnitType").value("LARGE UNIT")) .andExpect(jsonPath("$[0].accountNumberPrefix").value("XX")) - .andExpect(jsonPath("$[0].parentBusinessUnitId").value(99)); + .andExpect(jsonPath("$[0].parentBusinessUnit.businessUnitId").value(99)); } @Test @@ -96,7 +96,7 @@ private BusinessUnitEntity createBusinessUnitEntity() { .businessUnitCode("AAAA") .businessUnitType("LARGE UNIT") .accountNumberPrefix("XX") - .parentBusinessUnitId((short)99) + .parentBusinessUnit(BusinessUnitEntity.builder().businessUnitId((short)99).build()) .build(); } } diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/BusinessUnitController.java b/src/main/java/uk/gov/hmcts/opal/controllers/BusinessUnitController.java index bc42356c1..98f86b2db 100644 --- a/src/main/java/uk/gov/hmcts/opal/controllers/BusinessUnitController.java +++ b/src/main/java/uk/gov/hmcts/opal/controllers/BusinessUnitController.java @@ -15,6 +15,7 @@ import uk.gov.hmcts.opal.dto.reference.BusinessUnitReferenceDataResults; import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; import uk.gov.hmcts.opal.entity.BusinessUnitEntity; +import uk.gov.hmcts.opal.entity.projection.BusinessUnitReferenceData; import uk.gov.hmcts.opal.service.BusinessUnitServiceInterface; import uk.gov.hmcts.opal.service.opal.BusinessUnitService; @@ -69,7 +70,7 @@ public ResponseEntity getBusinessUnitRefData( @PathVariable Optional filter) { log.info(":GET:getBusinessUnitRefData: query: \n{}", filter); - List refData = opalBusinessUnitService.getReferenceData(filter); + List refData = opalBusinessUnitService.getReferenceData(filter); log.info(":GET:getBusinessUnitRefData: business unit reference data count: {}", refData.size()); return ResponseEntity.ok(BusinessUnitReferenceDataResults.builder().refData(refData).build()); diff --git a/src/main/java/uk/gov/hmcts/opal/dto/reference/BusinessUnitReferenceDataResults.java b/src/main/java/uk/gov/hmcts/opal/dto/reference/BusinessUnitReferenceDataResults.java index f02e6ec55..2834e9d93 100644 --- a/src/main/java/uk/gov/hmcts/opal/dto/reference/BusinessUnitReferenceDataResults.java +++ b/src/main/java/uk/gov/hmcts/opal/dto/reference/BusinessUnitReferenceDataResults.java @@ -4,7 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import uk.gov.hmcts.opal.entity.BusinessUnitEntity; +import uk.gov.hmcts.opal.entity.projection.BusinessUnitReferenceData; import java.util.List; import java.util.Optional; @@ -15,11 +15,11 @@ @AllArgsConstructor public class BusinessUnitReferenceDataResults { private Integer count; - private List refData; + private List refData; public static class BusinessUnitReferenceDataResultsBuilder { public BusinessUnitReferenceDataResults.BusinessUnitReferenceDataResultsBuilder refData( - List refData) { + List refData) { this.refData = refData; return this.count(Optional.ofNullable(refData).map(List::size).orElse(0)); } 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 b7d095c7a..8d5d621ee 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitEntity.java @@ -6,6 +6,8 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; @@ -38,6 +40,11 @@ public class BusinessUnitEntity { @Column(name = "account_number_prefix", length = 2) private String accountNumberPrefix; - @Column(name = "parent_business_unit_id") - private Short parentBusinessUnitId; + @ManyToOne + @JoinColumn(name = "parent_business_unit_id") + private BusinessUnitEntity parentBusinessUnit; + + @Column(name = "opal_domain", length = 30) + private String opalDomain; + } diff --git a/src/main/java/uk/gov/hmcts/opal/entity/projection/BusinessUnitReferenceData.java b/src/main/java/uk/gov/hmcts/opal/entity/projection/BusinessUnitReferenceData.java new file mode 100644 index 000000000..66ac30414 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/entity/projection/BusinessUnitReferenceData.java @@ -0,0 +1,17 @@ +package uk.gov.hmcts.opal.entity.projection; + +public interface BusinessUnitReferenceData { + + Short getBusinessUnitId(); + + String getBusinessUnitName(); + + String getBusinessUnitCode(); + + String getBusinessUnitType(); + + String getAccountNumberPrefix(); + + String getOpalDomain(); + +} 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 index c53dc1c6b..b22ff853a 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitSpecs.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitSpecs.java @@ -2,6 +2,7 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.From; +import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Predicate; import org.springframework.data.jpa.domain.Specification; import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; @@ -76,9 +77,10 @@ public static Specification equalsParentBusinessUnitId(Short public static Predicate equalsParentBusinessUnitIdPredicate( From from, CriteriaBuilder builder, Short parentBusinessUnitId) { - return builder.equal(from.get(BusinessUnitEntity_.parentBusinessUnitId), parentBusinessUnitId); + return equalsBusinessUnitIdPredicate(joinParentBusinessUnit(from), builder, parentBusinessUnitId); } + public static Specification likeAnyBusinessUnit(String filter) { return Specification.anyOf( likeBusinessUnitName(filter), @@ -86,4 +88,9 @@ public static Specification likeAnyBusinessUnit(String filte likeBusinessUnitType(filter) ); } + + public static Join joinParentBusinessUnit( + From from) { + return from.join(BusinessUnitEntity_.parentBusinessUnit); + } } 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 f9eb1bb2e..5e7fa8ee5 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 @@ -10,6 +10,7 @@ import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; import uk.gov.hmcts.opal.entity.BusinessUnitEntity; import uk.gov.hmcts.opal.entity.BusinessUnitEntity_; +import uk.gov.hmcts.opal.entity.projection.BusinessUnitReferenceData; import uk.gov.hmcts.opal.repository.BusinessUnitRepository; import uk.gov.hmcts.opal.repository.jpa.BusinessUnitSpecs; import uk.gov.hmcts.opal.service.BusinessUnitServiceInterface; @@ -40,14 +41,15 @@ public List searchBusinessUnits(BusinessUnitSearchDto criter return page.getContent(); } - public List getReferenceData(Optional filter) { + public List getReferenceData(Optional filter) { Sort nameSort = Sort.by(Sort.Direction.ASC, BusinessUnitEntity_.BUSINESS_UNIT_NAME); - Page page = businessUnitRepository + Page page = businessUnitRepository .findBy(specs.referenceDataFilter(filter), ffq -> ffq .sortBy(nameSort) + .as(BusinessUnitReferenceData.class) .page(Pageable.unpaged())); return page.getContent(); diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/BusinessUnitControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/BusinessUnitControllerTest.java index 2740f2504..70c142ae5 100644 --- a/src/test/java/uk/gov/hmcts/opal/controllers/BusinessUnitControllerTest.java +++ b/src/test/java/uk/gov/hmcts/opal/controllers/BusinessUnitControllerTest.java @@ -10,6 +10,7 @@ import uk.gov.hmcts.opal.dto.reference.BusinessUnitReferenceDataResults; import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; import uk.gov.hmcts.opal.entity.BusinessUnitEntity; +import uk.gov.hmcts.opal.entity.projection.BusinessUnitReferenceData; import uk.gov.hmcts.opal.service.opal.BusinessUnitService; import java.util.List; @@ -67,8 +68,8 @@ void testSearchBusinessUnits_Success() { @Test void testGetBusinessUnitsRefData_Success() { // Arrange - BusinessUnitEntity entity = BusinessUnitEntity.builder().build(); - List businessUnitList = List.of(entity); + BusinessUnitReferenceData entity = createBusinessUnitReferenceData(); + List businessUnitList = List.of(entity); when(businessUnitService.getReferenceData(any())).thenReturn(businessUnitList); @@ -84,4 +85,39 @@ void testGetBusinessUnitsRefData_Success() { assertEquals(businessUnitList, refDataResults.getRefData()); verify(businessUnitService, times(1)).getReferenceData(any()); } + + private BusinessUnitReferenceData createBusinessUnitReferenceData() { + return new BusinessUnitReferenceData() { + @Override + public Short getBusinessUnitId() { + return (short)1; + } + + @Override + public String getBusinessUnitName() { + return "Main BU"; + } + + @Override + public String getBusinessUnitCode() { + return "MNBU"; + } + + @Override + public String getBusinessUnitType() { + return "Big"; + } + + @Override + public String getAccountNumberPrefix() { + return "Prefix"; + } + + @Override + public String getOpalDomain() { + return "Domain"; + } + }; + + } } 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 549c59832..16ce1eda7 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 @@ -13,6 +13,7 @@ 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.entity.projection.BusinessUnitReferenceData; import uk.gov.hmcts.opal.repository.BusinessUnitRepository; import java.util.List; @@ -75,6 +76,7 @@ void testSearchBusinessUnits() { void testBusinessUnitsReferenceData() { // Arrange FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); + when(ffq.as(any())).thenReturn(ffq); when(ffq.sortBy(any())).thenReturn(ffq); BusinessUnitEntity businessUnitEntity = BusinessUnitEntity.builder().build(); @@ -85,7 +87,7 @@ void testBusinessUnitsReferenceData() { }); // Act - List result = businessUnitService.getReferenceData(Optional.empty()); + List result = businessUnitService.getReferenceData(Optional.empty()); // Assert assertEquals(List.of(businessUnitEntity), result); From 2e0096eced113cbabe8286e50acb26e8d16c1687 Mon Sep 17 00:00:00 2001 From: rajanigandra Date: Thu, 16 May 2024 15:00:49 +0100 Subject: [PATCH 2/5] Completed automation test for business unit ref data --- .../uk/gov/hmcts/opal/config/Constants.java | 6 +++ .../opal/steps/BusinessUnitsStepDef.java | 41 +++++++++++++++++++ .../opalMode/businessUnitFeatures.feature | 10 +++++ 3 files changed, 57 insertions(+) create mode 100644 src/functionalTest/java/uk/gov/hmcts/opal/config/Constants.java create mode 100644 src/functionalTest/java/uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java create mode 100644 src/functionalTest/resources/features/opalMode/businessUnitFeatures.feature diff --git a/src/functionalTest/java/uk/gov/hmcts/opal/config/Constants.java b/src/functionalTest/java/uk/gov/hmcts/opal/config/Constants.java new file mode 100644 index 000000000..9f6e212bc --- /dev/null +++ b/src/functionalTest/java/uk/gov/hmcts/opal/config/Constants.java @@ -0,0 +1,6 @@ +package uk.gov.hmcts.opal.config; + +public class Constants { + + public static final String BUSINESS_UNIT_REF_DATA_URI = "/api/business-unit/ref-data/"; +} diff --git a/src/functionalTest/java/uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java b/src/functionalTest/java/uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java new file mode 100644 index 000000000..6a2b47e34 --- /dev/null +++ b/src/functionalTest/java/uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java @@ -0,0 +1,41 @@ +package uk.gov.hmcts.opal.steps; + +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import net.serenitybdd.rest.SerenityRest; +import org.hamcrest.Matchers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static net.serenitybdd.rest.SerenityRest.then; +import static uk.gov.hmcts.opal.config.Constants.BUSINESS_UNIT_REF_DATA_URI; +import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken; + +public class BusinessUnitsStepDef extends BaseStepDef { + + static Logger log = LoggerFactory.getLogger(BusinessUnitsStepDef.class.getName()); + + @When("I make a request to the business unit ref data api") + public void getRequestToBusinessUnitRefData() { + SerenityRest + .given() + .accept("*/*") + .header("Authorization", "Bearer " + getToken()) + .contentType("application/json") + .when() + .get(getTestUrl() + BUSINESS_UNIT_REF_DATA_URI) + .then().log().all(); + + } + + @Then("the business unit ref data matching to result") + public void theRefDataMatchingToResult() { + int totalCount = then().extract().jsonPath().getInt("count"); + int refDataList = then().extract().jsonPath().getList("refData").size(); + log.info("total count is : " + totalCount); + log.info("Total records in the json response" + refDataList); + then().assertThat() + .statusCode(200) + .body("count", Matchers.equalTo(refDataList)); + } +} diff --git a/src/functionalTest/resources/features/opalMode/businessUnitFeatures.feature b/src/functionalTest/resources/features/opalMode/businessUnitFeatures.feature new file mode 100644 index 000000000..260eb7d66 --- /dev/null +++ b/src/functionalTest/resources/features/opalMode/businessUnitFeatures.feature @@ -0,0 +1,10 @@ + +@Opal @PO-313 +Feature: Verifying the end points for business units + + + Scenario: verifying the end points for API for Business Units Ref Data + Given I am testing as the "opal-test@hmcts.net" user + When I make a request to the business unit ref data api + Then the business unit ref data matching to result + From 63168b6e8865034f56636059212ebd9773a07d6d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 16 May 2024 09:04:04 +0000 Subject: [PATCH 3/5] chore(deps): update plugin org.flywaydb.flyway to v10.13.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9a5af5d47..cd3f41206 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { id 'com.github.ben-manes.versions' version '0.51.0' id 'org.sonarqube' version '5.0.0.4638' id 'uk.gov.hmcts.java' version '0.12.61' - id 'org.flywaydb.flyway' version '10.12.0' + id 'org.flywaydb.flyway' version '10.13.0' id 'net.serenity-bdd.serenity-gradle-plugin' version '4.1.12' } From e3a966206be10adf3f3dd5763643eb3d5a160f41 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 16 May 2024 11:16:01 +0000 Subject: [PATCH 4/5] chore(deps): update helm release java to v5.2.1 --- charts/opal-fines-service/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/opal-fines-service/Chart.yaml b/charts/opal-fines-service/Chart.yaml index abe52ee1c..4f403f8c1 100644 --- a/charts/opal-fines-service/Chart.yaml +++ b/charts/opal-fines-service/Chart.yaml @@ -3,10 +3,10 @@ appVersion: "1.0" description: A Helm chart for opal-fines-service app name: opal-fines-service home: https://github.com/hmcts/opal-fines-service -version: 0.0.32 +version: 0.0.33 maintainers: - name: HMCTS Opal Team dependencies: - name: java - version: 5.2.0 + version: 5.2.1 repository: 'https://hmctspublic.azurecr.io/helm/v1/repo/' From 1be5f114436f2e297ab5258128abbfe5f0437778 Mon Sep 17 00:00:00 2001 From: rajanigandra Date: Fri, 17 May 2024 11:57:01 +0100 Subject: [PATCH 5/5] applied filter to reduce the no.of records displaying on console --- .../uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java | 9 +++++---- .../features/opalMode/businessUnitFeatures.feature | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/functionalTest/java/uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java b/src/functionalTest/java/uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java index 6a2b47e34..6ee36378f 100644 --- a/src/functionalTest/java/uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java +++ b/src/functionalTest/java/uk/gov/hmcts/opal/steps/BusinessUnitsStepDef.java @@ -15,16 +15,16 @@ public class BusinessUnitsStepDef extends BaseStepDef { static Logger log = LoggerFactory.getLogger(BusinessUnitsStepDef.class.getName()); - @When("I make a request to the business unit ref data api") - public void getRequestToBusinessUnitRefData() { + @When("I make a request to the business unit ref data api filtering by business unit type {string}") + public void getRequestToBusinessUnitRefData(String filter) { + SerenityRest .given() .accept("*/*") .header("Authorization", "Bearer " + getToken()) .contentType("application/json") .when() - .get(getTestUrl() + BUSINESS_UNIT_REF_DATA_URI) - .then().log().all(); + .get(getTestUrl() + BUSINESS_UNIT_REF_DATA_URI + filter); } @@ -38,4 +38,5 @@ public void theRefDataMatchingToResult() { .statusCode(200) .body("count", Matchers.equalTo(refDataList)); } + } diff --git a/src/functionalTest/resources/features/opalMode/businessUnitFeatures.feature b/src/functionalTest/resources/features/opalMode/businessUnitFeatures.feature index 260eb7d66..606f339f5 100644 --- a/src/functionalTest/resources/features/opalMode/businessUnitFeatures.feature +++ b/src/functionalTest/resources/features/opalMode/businessUnitFeatures.feature @@ -1,10 +1,9 @@ - @Opal @PO-313 Feature: Verifying the end points for business units Scenario: verifying the end points for API for Business Units Ref Data Given I am testing as the "opal-test@hmcts.net" user - When I make a request to the business unit ref data api + When I make a request to the business unit ref data api filtering by business unit type "area" Then the business unit ref data matching to result