From 6e44af71b33c3873fa4461ea92b9bb037e3f4117 Mon Sep 17 00:00:00 2001 From: SALMANCH007 Date: Thu, 25 Jul 2024 21:32:44 +0100 Subject: [PATCH 1/5] inital commit --- .../config/AbstractIntegrationTest.java | 4 + .../pscdataapi/config/ApplicationConfig.java | 6 ++ .../pscdataapi/models/Links.java | 15 +++- .../pscdataapi/service/CompanyPscService.java | 62 +++++++++++++- .../PscDataApiApplicationTests.java | 6 ++ ...ServiceAspectFeatureFlagDisabledITest.java | 4 + ...iServiceAspectFeatureFlagEnabledITest.java | 4 + .../service/CompanyPscServiceTest.java | 72 ++++++++++++++++ .../pscdataapi/util/TestHelper.java | 85 +++++++++++++++++++ 9 files changed, 255 insertions(+), 3 deletions(-) diff --git a/src/itest/java/uk/gov/companieshouse/pscdataapi/config/AbstractIntegrationTest.java b/src/itest/java/uk/gov/companieshouse/pscdataapi/config/AbstractIntegrationTest.java index d5ab5b68..66c31907 100644 --- a/src/itest/java/uk/gov/companieshouse/pscdataapi/config/AbstractIntegrationTest.java +++ b/src/itest/java/uk/gov/companieshouse/pscdataapi/config/AbstractIntegrationTest.java @@ -4,6 +4,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; import uk.gov.companieshouse.api.api.CompanyMetricsApiService; import uk.gov.companieshouse.pscdataapi.api.ChsKafkaApiService; @@ -21,4 +22,7 @@ public abstract class AbstractIntegrationTest extends AbstractMongoConfig { @MockBean public CompanyMetricsApiService companyMetricsApiService; + @MockBean + CompanyExemptionsApiService companyExemptionsApiService; + } \ No newline at end of file diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/config/ApplicationConfig.java b/src/main/java/uk/gov/companieshouse/pscdataapi/config/ApplicationConfig.java index 373c9948..91eae575 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/config/ApplicationConfig.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/config/ApplicationConfig.java @@ -14,6 +14,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.data.mongodb.core.convert.MongoCustomConversions; import uk.gov.companieshouse.api.InternalApiClient; +import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; import uk.gov.companieshouse.api.api.CompanyMetricsApiService; import uk.gov.companieshouse.api.converter.EnumWriteConverter; import uk.gov.companieshouse.pscdataapi.converter.CompanyPscReadConverter; @@ -54,6 +55,11 @@ public CompanyMetricsApiService companyMetricsApiService() { return new CompanyMetricsApiService(); } +// @Bean +// public CompanyExemptionsApiService companyExemptionsApiService(){ +// return new CompanyExemptionsApiService(); +// } + @Bean @Primary public ObjectMapper objectMapper() { diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/models/Links.java b/src/main/java/uk/gov/companieshouse/pscdataapi/models/Links.java index 5c24bace..f39bb7f7 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/models/Links.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/models/Links.java @@ -11,6 +11,9 @@ public class Links { @Field("statement") private String statement; + @Field("exemptions") + private String exemptions; + public String getSelf() { return self; } @@ -27,6 +30,10 @@ public void setStatement(String statement) { this.statement = statement; } + public String getExemptions() { return exemptions; } + + public void setExemptions(String exemptions) { this.exemptions = exemptions; } + @Override public String toString() { return "Links{" @@ -36,6 +43,9 @@ public String toString() { + ", statement='" + statement + '\'' + + ", exemptions='" + + exemptions + + '\'' + '}'; } @@ -49,11 +59,12 @@ public boolean equals(Object object) { } Links links = (Links) object; return Objects.equals(self, links.self) - && Objects.equals(statement, links.statement); + && Objects.equals(statement, links.statement) + && Objects.equals(exemptions, links.exemptions); } @Override public int hashCode() { - return Objects.hash(self, statement); + return Objects.hash(self, statement, exemptions); } } diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java b/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java index feb1198a..63321660 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java @@ -7,10 +7,14 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; import uk.gov.companieshouse.api.api.CompanyMetricsApiService; +import uk.gov.companieshouse.api.exemptions.CompanyExemptions; import uk.gov.companieshouse.api.metrics.MetricsApi; import uk.gov.companieshouse.api.metrics.RegisterApi; import uk.gov.companieshouse.api.metrics.RegistersApi; @@ -57,16 +61,21 @@ public class CompanyPscService { private final ChsKafkaApiService chsKafkaApiService; private final CompanyMetricsApiService companyMetricsApiService; + @Autowired + CompanyExemptionsApiService companyExemptionsApiService; + public CompanyPscService(Logger logger, CompanyPscTransformer transformer, CompanyPscRepository repository, ChsKafkaApiService chsKafkaApiService, - CompanyMetricsApiService companyMetricsApiService) { + CompanyMetricsApiService companyMetricsApiService, + CompanyExemptionsApiService companyExemptionsApiService) { this.logger = logger; this.transformer = transformer; this.repository = repository; this.chsKafkaApiService = chsKafkaApiService; this.companyMetricsApiService = companyMetricsApiService; + this.companyExemptionsApiService = companyExemptionsApiService; } /** @@ -601,6 +610,12 @@ private PscList createPscDocumentList(List pscDocuments, pscList.setStartIndex(startIndex); pscList.setItems(documents); + if (hasPscExemptions(companyNumber)) { + if(hasExemptFrom(companyNumber) && !hasExemptTo(companyNumber)) { + links.setExemptions(String.format("/company/%s/exemptions", companyNumber)); + } + } + companyMetrics.ifPresentOrElse(metricsApi -> { try { if (registerView) { @@ -632,4 +647,49 @@ private PscList createPscDocumentList(List pscDocuments, return pscList; } + private boolean hasPscExemptions(String companyNumber) { + Optional companyExemptions = companyExemptionsApiService.getCompanyExemptions(companyNumber); + + return companyExemptions.filter(x -> + x.getExemptions() != null && + (x.getExemptions().getPscExemptAsSharesAdmittedOnMarket()!= null || + x.getExemptions().getPscExemptAsTradingOnEuRegulatedMarket() != null || + x.getExemptions().getPscExemptAsTradingOnRegulatedMarket() != null || + x.getExemptions().getPscExemptAsTradingOnUkRegulatedMarket() != null)).isPresent(); + } + + private boolean hasExemptFrom(String companyNumber) { + Optional companyExemptions = companyExemptionsApiService.getCompanyExemptions(companyNumber); + + return companyExemptions + .map(exemptions -> exemptions.getExemptions()) + .filter(exemptions -> exemptions != null) + .map(exemptions -> exemptions.getPscExemptAsSharesAdmittedOnMarket() != null + && exemptions.getPscExemptAsSharesAdmittedOnMarket().getItems().get(0).getExemptFrom() != null || + exemptions.getPscExemptAsTradingOnEuRegulatedMarket() != null + && exemptions.getPscExemptAsTradingOnEuRegulatedMarket().getItems().get(0).getExemptFrom() != null || + exemptions.getPscExemptAsTradingOnRegulatedMarket() != null + && exemptions.getPscExemptAsTradingOnRegulatedMarket().getItems().get(0).getExemptFrom() != null || + exemptions.getPscExemptAsTradingOnUkRegulatedMarket() != null + && exemptions.getPscExemptAsTradingOnUkRegulatedMarket().getItems().get(0).getExemptFrom() != null) + .orElse(false); + } + + private boolean hasExemptTo(String companyNumber) { + Optional companyExemptions = companyExemptionsApiService.getCompanyExemptions(companyNumber); + + return companyExemptions + .map(exemptions -> exemptions.getExemptions()) + .filter(exemptions -> exemptions != null) + .map(exemptions -> exemptions.getPscExemptAsSharesAdmittedOnMarket() != null + && exemptions.getPscExemptAsSharesAdmittedOnMarket().getItems().get(0).getExemptTo() != null || + exemptions.getPscExemptAsTradingOnEuRegulatedMarket() != null + && exemptions.getPscExemptAsTradingOnEuRegulatedMarket().getItems().get(0).getExemptTo() != null || + exemptions.getPscExemptAsTradingOnRegulatedMarket() != null + && exemptions.getPscExemptAsTradingOnRegulatedMarket().getItems().get(0).getExemptTo() != null || + exemptions.getPscExemptAsTradingOnUkRegulatedMarket() != null + && exemptions.getPscExemptAsTradingOnUkRegulatedMarket().getItems().get(0).getExemptTo() != null) + .orElse(false); + } + } diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java b/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java index e699d963..fde0c197 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java @@ -1,11 +1,17 @@ package uk.gov.companieshouse.pscdataapi; import org.junit.jupiter.api.Test; +import org.mockito.Mock; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; @SpringBootTest class PscDataApiApplicationTests { + @MockBean + CompanyExemptionsApiService companyExemptionsApiService; + @Test void contextLoads() { } diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java index 89ef83db..288a4490 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java @@ -16,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import uk.gov.companieshouse.api.InternalApiClient; +import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; import uk.gov.companieshouse.api.chskafka.ChangedResource; import uk.gov.companieshouse.api.error.ApiErrorResponseException; import uk.gov.companieshouse.api.handler.chskafka.PrivateChangedResourceHandler; @@ -53,6 +54,9 @@ class ResourceChangedApiServiceAspectFeatureFlagDisabledITest { @MockBean private ChsKafkaApiService mapper; + @MockBean + CompanyExemptionsApiService companyExemptionsApiService; + @Captor ArgumentCaptor changedResourceCaptor; diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java index f134eab0..515f1ccd 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java @@ -12,6 +12,7 @@ import org.springframework.test.context.ActiveProfiles; import uk.gov.companieshouse.api.InternalApiClient; +import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; import uk.gov.companieshouse.api.chskafka.ChangedResource; import uk.gov.companieshouse.api.error.ApiErrorResponseException; import uk.gov.companieshouse.api.handler.chskafka.PrivateChangedResourceHandler; @@ -49,6 +50,9 @@ class ResourceChangedApiServiceAspectFeatureFlagEnabledITest { @Mock private RequestExecutor requestExecutor; + @MockBean + CompanyExemptionsApiService companyExemptionsApiService; + @Test void testThatAspectShouldNotProceedWhenFeatureFlagEnabled() throws ServiceUnavailableException, ApiErrorResponseException { diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java index 2614d313..542f09a7 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java @@ -1,6 +1,7 @@ package uk.gov.companieshouse.pscdataapi.service; import static com.mongodb.internal.connection.tlschannel.util.Util.assertTrue; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; @@ -29,7 +30,11 @@ import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; import uk.gov.companieshouse.api.api.CompanyMetricsApiService; +import uk.gov.companieshouse.api.exemptions.CompanyExemptions; +import uk.gov.companieshouse.api.exemptions.Exemptions; +import uk.gov.companieshouse.api.exemptions.PscExemptAsTradingOnUkRegulatedMarketItem; import uk.gov.companieshouse.api.metrics.MetricsApi; import uk.gov.companieshouse.api.metrics.RegisterApi; import uk.gov.companieshouse.api.metrics.RegistersApi; @@ -50,6 +55,7 @@ import uk.gov.companieshouse.pscdataapi.exceptions.BadRequestException; import uk.gov.companieshouse.pscdataapi.exceptions.ResourceNotFoundException; import uk.gov.companieshouse.pscdataapi.models.Created; +import uk.gov.companieshouse.pscdataapi.models.Links; import uk.gov.companieshouse.pscdataapi.models.PscData; import uk.gov.companieshouse.pscdataapi.models.PscDocument; import uk.gov.companieshouse.pscdataapi.repository.CompanyPscRepository; @@ -74,6 +80,8 @@ class CompanyPscServiceTest { private CompanyPscTransformer transformer; @Mock private ChsKafkaApiService chsKafkaApiService; + @Mock + CompanyExemptionsApiService companyExemptionsApiService; @Captor private ArgumentCaptor dateCaptor; @Spy @@ -88,6 +96,9 @@ class CompanyPscServiceTest { private OffsetDateTime date; private OffsetDateTime laterDate; + private TestHelper testHelper; + private PscExemptAsTradingOnUkRegulatedMarketItem pscExemptAsTradingOnUkRegulatedMarketItem; + @BeforeEach void setUp() { date = TestHelper.createOffsetDateTime(); @@ -96,6 +107,9 @@ void setUp() { request = TestHelper.buildBasicFullRecordPsc(); pscDocument = TestHelper.buildBasicDocument(); + + testHelper = new TestHelper(); + pscExemptAsTradingOnUkRegulatedMarketItem = new PscExemptAsTradingOnUkRegulatedMarketItem(); } @Test @@ -716,4 +730,62 @@ void whenCompanyNotInPublicRegisterGetPSCListShouldThrow() throws ResourceNotFou verify(repository, times(0)).getListSummaryRegisterView(COMPANY_NUMBER, 0, OffsetDateTime.parse("2020-12-20T06:00Z"), 25); } + @Test + void pscListReturnedByCompanyNumberFromRepositoryWithExemptions() throws ResourceNotFoundException { + PscList expectedPscList = TestHelper.createPscListWithExemptions(); + PscData pscData = new PscData(); + pscDocument.setData(pscData); + ListSummary listSummary = new ListSummary(); + Identification identification = new Identification(); + identification.setPlaceRegistered("x"); + identification.setCountryRegistered("x"); + identification.setRegistrationNumber("x"); + identification.setLegalAuthority("x"); + identification.setLegalForm("x"); + listSummary.setIdentification(identification); + + when(companyMetricsApiService.getCompanyMetrics(COMPANY_NUMBER)) + .thenReturn(Optional.of(TestHelper.createMetrics())); + when(repository.getPscDocumentList(anyString(), anyInt(), anyInt())).thenReturn(Optional.of(Collections.singletonList(pscDocument))); + when(transformer.transformPscDocToListSummary(pscDocument, false)) + .thenReturn(listSummary); + when(companyExemptionsApiService.getCompanyExemptions(any())).thenReturn(Optional.ofNullable(testHelper.createExemptions())); + + PscList PscDocumentList = service.retrievePscListSummaryFromDb(COMPANY_NUMBER, 0, false, 25); + + Assertions.assertEquals(expectedPscList, PscDocumentList); + verify(repository, times(1)).getPscDocumentList(COMPANY_NUMBER, 0, 25); + } + + @Test + void hasPscExemptionsReturnsTrueWhenTradingOnUkRegulatedMarket() { + PscData pscData = new PscData(); + pscDocument.setData(pscData); + ListSummary listSummary = new ListSummary(); + Identification identification = new Identification(); + identification.setPlaceRegistered("x"); + identification.setCountryRegistered("x"); + identification.setRegistrationNumber("x"); + identification.setLegalAuthority("x"); + identification.setLegalForm("x"); + listSummary.setIdentification(identification); + when(repository.getPscDocumentList(anyString(), anyInt(), anyInt())).thenReturn(Optional.of(Collections.singletonList(pscDocument))); + when(transformer.transformPscDocToListSummary(pscDocument, false)) + .thenReturn(listSummary); + + CompanyExemptions companyExemptions = new CompanyExemptions(); + Exemptions exemptions = new Exemptions(); + exemptions.setPscExemptAsTradingOnUkRegulatedMarket(pscExemptAsTradingOnUkRegulatedMarketItem); + companyExemptions.setExemptions(testHelper.getUkExemptions()); + when(companyExemptionsApiService.getCompanyExemptions(any())).thenReturn(Optional.ofNullable(testHelper.createExemptions())); + + PscList PscDocumentList = service.retrievePscListSummaryFromDb(COMPANY_NUMBER, 0, false, 25); + + Links links = new Links(); + links.setSelf("/company/" + COMPANY_NUMBER + "/persons-with-significant-control"); + links.setExemptions("/company/" + COMPANY_NUMBER + "/exemptions"); + + assertEquals(PscDocumentList.getLinks(), links); + } + } \ No newline at end of file diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java b/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java index 50ac6478..050265d2 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java @@ -12,6 +12,7 @@ import java.util.Collections; import java.util.List; import org.springframework.util.FileCopyUtils; +import uk.gov.companieshouse.api.exemptions.*; import uk.gov.companieshouse.api.metrics.CountsApi; import uk.gov.companieshouse.api.metrics.MetricsApi; import uk.gov.companieshouse.api.metrics.PscApi; @@ -35,6 +36,9 @@ import uk.gov.companieshouse.pscdataapi.models.PscSensitiveData; import uk.gov.companieshouse.pscdataapi.models.Updated; +import static uk.gov.companieshouse.api.exemptions.PscExemptAsTradingOnRegulatedMarketItem.ExemptionTypeEnum.PSC_EXEMPT_AS_TRADING_ON_REGULATED_MARKET; +import static uk.gov.companieshouse.api.exemptions.PscExemptAsTradingOnUkRegulatedMarketItem.ExemptionTypeEnum.PSC_EXEMPT_AS_TRADING_ON_UK_REGULATED_MARKET; + public class TestHelper { public static final String INDIVIDUAL_KIND = "individual-person-with-significant-control"; public static final String CORPORATE_KIND = "corporate-entity-person-with-significant-control"; @@ -46,6 +50,7 @@ public class TestHelper { public static final String PSC_ID = "pscId"; public static final String PSC_STATEMENT_ID = "pscStatementId"; public static final String X_REQUEST_ID = "654321"; + private static final LocalDate EXEMPTION_DATE = LocalDate.of(2022, 11, 3); public TestHelper(){} @@ -366,6 +371,33 @@ private static Links createLinks() { return links; } + public static PscList createPscListWithExemptions() { + ListSummary listSummary = new ListSummary(); + Identification identification = new Identification(); + identification.setPlaceRegistered("x"); + identification.setCountryRegistered("x"); + identification.setRegistrationNumber("x"); + identification.setLegalAuthority("x"); + identification.setLegalForm("x"); + listSummary.setIdentification(identification); + PscList pscList = new PscList(); + pscList.setItems(Collections.singletonList(listSummary)); + pscList.setActiveCount(1); + pscList.setCeasedCount(1); + pscList.setTotalResults(2); + pscList.setStartIndex(0); + pscList.setItemsPerPage(25); + pscList.setLinks(createLinksWithExemptions()); + return pscList; + } + + private static Links createLinksWithExemptions() { + Links links = new Links(); + links.setSelf(String.format("/company/%s/persons-with-significant-control", COMPANY_NUMBER)); + links.setExemptions(String.format("/company/%s/exemptions", COMPANY_NUMBER)); + return links; + } + public static MetricsApi createMetrics() { MetricsApi metrics = new MetricsApi(); CountsApi counts = new CountsApi(); @@ -407,4 +439,57 @@ public static OffsetDateTime createLaterOffsetDateTime() { return OffsetDateTime.of(laterLocalDate, offset); } + public Exemptions getUkExemptions() { + ExemptionItem exemptionItem = new ExemptionItem(); + exemptionItem.exemptFrom(EXEMPTION_DATE); + exemptionItem.exemptTo(null); + + List exemptionItems = Collections.singletonList(exemptionItem); + + + PscExemptAsTradingOnUkRegulatedMarketItem nonUkEeaStateMarket = new PscExemptAsTradingOnUkRegulatedMarketItem(); + + nonUkEeaStateMarket.setItems(exemptionItems); + nonUkEeaStateMarket.setExemptionType(PSC_EXEMPT_AS_TRADING_ON_UK_REGULATED_MARKET); + + PscExemptAsTradingOnUkRegulatedMarketItem ukEeaStateMarket = new PscExemptAsTradingOnUkRegulatedMarketItem(); + ukEeaStateMarket.setItems(exemptionItems); + ukEeaStateMarket.setExemptionType(PSC_EXEMPT_AS_TRADING_ON_UK_REGULATED_MARKET); + + Exemptions exemptions = new Exemptions(); + exemptions.setPscExemptAsTradingOnUkRegulatedMarket(nonUkEeaStateMarket); + exemptions.setPscExemptAsTradingOnUkRegulatedMarket(ukEeaStateMarket); + + return exemptions; + } + + public CompanyExemptions createExemptions () { + CompanyExemptions exemptions = new CompanyExemptions(); + exemptions.setExemptions(getExemptions()); + return exemptions; + } + + private Exemptions getExemptions() { + ExemptionItem exemptionItem = new ExemptionItem(); + exemptionItem.exemptFrom(EXEMPTION_DATE); + exemptionItem.exemptTo(null); + + List exemptionItems = Collections.singletonList(exemptionItem); + + + PscExemptAsTradingOnRegulatedMarketItem nonUkEeaStateMarket = new PscExemptAsTradingOnRegulatedMarketItem(); + nonUkEeaStateMarket.setItems(exemptionItems); + nonUkEeaStateMarket.setExemptionType(PSC_EXEMPT_AS_TRADING_ON_REGULATED_MARKET); + + PscExemptAsTradingOnUkRegulatedMarketItem ukEeaStateMarket = new PscExemptAsTradingOnUkRegulatedMarketItem(); + ukEeaStateMarket.setItems(exemptionItems); + ukEeaStateMarket.setExemptionType(PSC_EXEMPT_AS_TRADING_ON_UK_REGULATED_MARKET); + + Exemptions exemptions = new Exemptions(); + exemptions.setPscExemptAsTradingOnRegulatedMarket(nonUkEeaStateMarket); + exemptions.setPscExemptAsTradingOnUkRegulatedMarket(ukEeaStateMarket); + + return exemptions; + } + } From d66040a8691c25dfc07f8f112111307cd841f1c0 Mon Sep 17 00:00:00 2001 From: SALMANCH007 Date: Thu, 25 Jul 2024 22:04:56 +0100 Subject: [PATCH 2/5] appended application.properties for exemptions --- .../pscdataapi/config/ApplicationConfig.java | 8 ++++---- src/main/resources/application.properties | 1 + .../pscdataapi/PscDataApiApplicationTests.java | 5 ++--- ...ceChangedApiServiceAspectFeatureFlagDisabledITest.java | 4 ++-- ...rceChangedApiServiceAspectFeatureFlagEnabledITest.java | 4 ++-- .../resources/application-feature_flag_enabled.properties | 1 + src/test/resources/application.properties | 1 + 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/config/ApplicationConfig.java b/src/main/java/uk/gov/companieshouse/pscdataapi/config/ApplicationConfig.java index 91eae575..14f601ca 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/config/ApplicationConfig.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/config/ApplicationConfig.java @@ -55,10 +55,10 @@ public CompanyMetricsApiService companyMetricsApiService() { return new CompanyMetricsApiService(); } -// @Bean -// public CompanyExemptionsApiService companyExemptionsApiService(){ -// return new CompanyExemptionsApiService(); -// } + @Bean + public CompanyExemptionsApiService companyExemptionsApiService(){ + return new CompanyExemptionsApiService(); + } @Bean @Primary diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fe6ca712..cedb20c8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,7 @@ management.endpoints.web.path-mapping.health=/healthcheck chs.api.kafka.url=${CHS_KAFKA_API_URL:localhost} chs.api.kafka.resource-changed.uri=${PSC_API_RESOURCE_CHANGED_URI:/private/resource-changed} chs.api.metrics.url=${API_LOCAL_URL:localhost} +chs.api.exemptions.url=${COMPANY_EXEMPTIONS_API_LOCAL_URL:https://localhost} spring.data.mongodb.uri=${MONGODB_URL:mongodb://mongo:27017} spring.data.mongodb.name=company_pscs diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java b/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java index fde0c197..9c100977 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java @@ -1,7 +1,6 @@ package uk.gov.companieshouse.pscdataapi; import org.junit.jupiter.api.Test; -import org.mockito.Mock; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; @@ -9,8 +8,8 @@ @SpringBootTest class PscDataApiApplicationTests { - @MockBean - CompanyExemptionsApiService companyExemptionsApiService; +// @MockBean +// CompanyExemptionsApiService companyExemptionsApiService; @Test void contextLoads() { diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java index 288a4490..75716d4c 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java @@ -54,8 +54,8 @@ class ResourceChangedApiServiceAspectFeatureFlagDisabledITest { @MockBean private ChsKafkaApiService mapper; - @MockBean - CompanyExemptionsApiService companyExemptionsApiService; +// @MockBean +// CompanyExemptionsApiService companyExemptionsApiService; @Captor ArgumentCaptor changedResourceCaptor; diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java index 515f1ccd..79dc9c87 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java @@ -50,8 +50,8 @@ class ResourceChangedApiServiceAspectFeatureFlagEnabledITest { @Mock private RequestExecutor requestExecutor; - @MockBean - CompanyExemptionsApiService companyExemptionsApiService; +// @MockBean +// CompanyExemptionsApiService companyExemptionsApiService; @Test void testThatAspectShouldNotProceedWhenFeatureFlagEnabled() throws ServiceUnavailableException, ApiErrorResponseException { diff --git a/src/test/resources/application-feature_flag_enabled.properties b/src/test/resources/application-feature_flag_enabled.properties index a7adfe63..7bdc962e 100644 --- a/src/test/resources/application-feature_flag_enabled.properties +++ b/src/test/resources/application-feature_flag_enabled.properties @@ -5,6 +5,7 @@ chs.kafka.api.key=chsApiKey chs.api.kafka.url=${CHS_KAFKA_API_URL:localhost} chs.api.kafka.resource-changed.uri=${PSC_API_RESOURCE_CHANGED_URI:/private/resource-changed} chs.api.metrics.url=${API_LOCAL_URL:localhost} +chs.api.exemptions.url=${COMPANY_EXEMPTIONS_API_LOCAL_URL:https://localhost} api.api-url=${API_URL:localhost} api.api-key=${CHS_API_KEY:chsApiKey} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 91b2b793..08376d6b 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -5,6 +5,7 @@ chs.kafka.api.key=chsApiKey chs.api.kafka.url=${CHS_KAFKA_API_URL:localhost} chs.api.kafka.resource-changed.uri=${PSC_API_RESOURCE_CHANGED_URI:/private/resource-changed} chs.api.metrics.url=${API_LOCAL_URL:localhost} +chs.api.exemptions.url=${COMPANY_EXEMPTIONS_API_LOCAL_URL:https://localhost} api.api-url=${API_URL:localhost} api.api-key=${CHS_API_KEY:chsApiKey} From 7672be8bce0cdc3b326d4b5e8f9402d7b4c13289 Mon Sep 17 00:00:00 2001 From: SALMANCH007 Date: Fri, 26 Jul 2024 15:08:56 +0100 Subject: [PATCH 3/5] abstractmongo symbol not found fixed --- .../uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java index 3958f41e..00d36120 100644 --- a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java +++ b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java @@ -41,6 +41,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.util.FileCopyUtils; +import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; import uk.gov.companieshouse.api.api.CompanyMetricsApiService; import uk.gov.companieshouse.api.metrics.MetricsApi; import uk.gov.companieshouse.api.psc.CorporateEntity; @@ -84,6 +85,9 @@ public class PscDataSteps { @Autowired private CompanyPscTransformer transformer; +// @Autowired +// private CompanyExemptionsApiService companyExemptionsApiService; + @InjectMocks private CompanyPscService companyPscService; From e1d463fb5cc06e6f671a1bc18b33650aed6e14cf Mon Sep 17 00:00:00 2001 From: SALMANCH007 Date: Mon, 29 Jul 2024 16:49:48 +0100 Subject: [PATCH 4/5] tidy up --- .../uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java index 00d36120..9dbac0da 100644 --- a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java +++ b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java @@ -84,10 +84,6 @@ public class PscDataSteps { private ChsKafkaApiService chsKafkaApiService; @Autowired private CompanyPscTransformer transformer; - -// @Autowired -// private CompanyExemptionsApiService companyExemptionsApiService; - @InjectMocks private CompanyPscService companyPscService; From dba56c4496579f36374700dfc6018bcfcabfee1f Mon Sep 17 00:00:00 2001 From: SALMANCH007 Date: Tue, 30 Jul 2024 07:50:07 +0100 Subject: [PATCH 5/5] tided up code --- .../pscdataapi/PscDataApiApplicationTests.java | 6 ------ ...urceChangedApiServiceAspectFeatureFlagDisabledITest.java | 3 --- ...ourceChangedApiServiceAspectFeatureFlagEnabledITest.java | 3 --- 3 files changed, 12 deletions(-) diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java b/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java index 9c100977..ad57fd98 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/PscDataApiApplicationTests.java @@ -2,15 +2,9 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import uk.gov.companieshouse.api.api.CompanyExemptionsApiService; @SpringBootTest class PscDataApiApplicationTests { - -// @MockBean -// CompanyExemptionsApiService companyExemptionsApiService; - @Test void contextLoads() { } diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java index 75716d4c..4e6334fc 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagDisabledITest.java @@ -54,9 +54,6 @@ class ResourceChangedApiServiceAspectFeatureFlagDisabledITest { @MockBean private ChsKafkaApiService mapper; -// @MockBean -// CompanyExemptionsApiService companyExemptionsApiService; - @Captor ArgumentCaptor changedResourceCaptor; diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java index 79dc9c87..8ffb52c0 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/api/ResourceChangedApiServiceAspectFeatureFlagEnabledITest.java @@ -50,9 +50,6 @@ class ResourceChangedApiServiceAspectFeatureFlagEnabledITest { @Mock private RequestExecutor requestExecutor; -// @MockBean -// CompanyExemptionsApiService companyExemptionsApiService; - @Test void testThatAspectShouldNotProceedWhenFeatureFlagEnabled() throws ServiceUnavailableException, ApiErrorResponseException {