Skip to content

Commit

Permalink
Merge pull request #56 from companieshouse/feature/DSND-2069-fix-tests
Browse files Browse the repository at this point in the history
fix type errors and tests
  • Loading branch information
JAndrewCH authored Nov 20, 2023
2 parents d24639d + 8c3a4c4 commit 2cc56f7
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 124 deletions.
1 change: 1 addition & 0 deletions routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ routes:
8: ^/company/(.*)/persons-with-significant-control/super-secure/(.*)
9: ^/company/(.*)/persons-with-significant-control/legal-person-beneficial-owner/(.*)
10: ^/company/(.*)/persons-with-significant-control/super-secure-beneficial-owner/(.*)
11: ^/company/(.*)/persons-with-significant-control/

Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,9 @@ public void iSendAGETStatementListRequestForCompanyNumberInRegisterView(String c

@And("Company Metrics API is available for company number {string}")
public void companyMetricsAPIIsAvailableForCompanyNumber(String companyNumber) throws IOException {
File metricsFile = new ClassPathResource("resources/json/input/company_metrics_34777777.json").getFile();
MetricsApi metrics = objectMapper.readValue(metricsFile, MetricsApi.class);

String data = FileCopyUtils.copyToString(new InputStreamReader(new FileInputStream("src/itest/resources/json/input/company_metrics_34777777.json")));
MetricsApi metrics = objectMapper.readValue(data, MetricsApi.class);
Optional<MetricsApi> metricsApi = Optional.ofNullable(metrics);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private PscList createPscDocumentList(List<PscDocument> pscDocuments,
List<ListSummary> documents = new ArrayList<>();

for (PscDocument pscDocument : pscDocuments) {
ListSummary listSummary = transformPscDocToListSummary(pscDocument);
ListSummary listSummary = this.transformer.transformPscDocToListSummary(pscDocument);
documents.add(listSummary);

}
Expand Down Expand Up @@ -525,122 +525,5 @@ private PscList createPscDocumentList(List<PscDocument> pscDocuments,

}

private ListSummary transformPscDocToListSummary(PscDocument pscDocument) {

ListSummary listSummary = new ListSummary();

PscData getDocument = pscDocument.getData();

if (getDocument.getEtag() != null) {
listSummary.setEtag(getDocument.getEtag());
}
listSummary.setKind(listSummary.getKind());

if (getDocument.getName() != null) {
listSummary.setName(getDocument.getName());
}
if (getDocument.getNameElements() != null) {
NameElements nameElements = new NameElements();
if (getDocument.getNameElements().getTitle() != null) {
nameElements.setTitle(getDocument.getNameElements().getTitle());
}
if (getDocument.getNameElements().getForename() != null) {
nameElements.setForename(getDocument.getNameElements().getForename());
}
if (getDocument.getNameElements().getMiddleName() != null) {
nameElements.setMiddleName(getDocument
.getNameElements().getMiddleName());
}
if (getDocument.getNameElements().getSurname() != null) {
nameElements.setSurname(getDocument.getNameElements().getSurname());
}
listSummary.setNameElements(nameElements);
}
if (getDocument.getAddress() != null) {
Address address = new Address();

if (getDocument.getAddress().getAddressLine1() != null) {
address.setAddressLine1(getDocument.getAddress().getAddressLine1());
}
if (getDocument.getAddress().getAddressLine2() != null) {
address.setAddressLine2(getDocument.getAddress().getAddressLine2());
}
if (getDocument.getAddress().getCountry() != null) {
address.setCountry(getDocument.getAddress().getCountry());
}
if (getDocument.getAddress().getLocality() != null) {
address.setLocality(getDocument.getAddress().getLocality());
}
if (getDocument.getAddress().getPostalCode() != null) {
address.setPostalCode(getDocument.getAddress().getPostalCode());
}
if (getDocument.getAddress().getPremises() != null) {
address.setPremises(getDocument.getAddress().getPremises());
}
if (getDocument.getAddress().getRegion() != null) {
address.setRegion(getDocument.getAddress().getRegion());
}
if (getDocument.getAddress().getCareOf() != null) {
address.setCareOf(getDocument.getAddress().getCareOf());
}
if (getDocument.getAddress().getPoBox() != null) {
address.setPoBox(getDocument.getAddress().getPoBox());
}
listSummary.setAddress(address);
listSummary.setPrincipalOfficeAddress(address);
}
if (getDocument.getNaturesOfControl() != null) {
listSummary
.setNaturesOfControl(getDocument.getNaturesOfControl());
}
if (getDocument.getLinks() != null) {
listSummary.setLinks(getDocument.getLinks());
}
if (getDocument.getCeasedOn() != null) {
listSummary.setCeasedOn(getDocument.getCeasedOn());
}
if (getDocument.getSanctioned() != null) {
listSummary.setIsSanctioned(getDocument.getSanctioned());
}
if (getDocument.getNationality() != null) {
listSummary.setNationality(getDocument.getNationality());
}
if (getDocument.getCountryOfResidence() != null) {
listSummary.setCountryOfResidence(getDocument.getCountryOfResidence());
}
if (getDocument.getDescription() != null) {
listSummary.setDescription(
ListSummary.DescriptionEnum.SUPER_SECURE_PERSONS_WITH_SIGNIFICANT_CONTROL);
}
if (pscDocument.getIdentification() != null) {
Identification identification = new Identification();
if (pscDocument.getIdentification().getCountryRegistered() != null) {
identification.setCountryRegistered(
pscDocument.getIdentification().getCountryRegistered());
}
if (pscDocument.getIdentification().getLegalAuthority() != null) {
identification.setLegalAuthority(
pscDocument.getIdentification().getLegalAuthority());
}
if (pscDocument.getIdentification().getLegalForm() != null) {
identification.setLegalForm(
pscDocument.getIdentification().getLegalForm());
}
if (pscDocument.getIdentification().getPlaceRegistered() != null) {
identification.setPlaceRegistered(
pscDocument.getIdentification().getPlaceRegistered());
}
if (pscDocument.getIdentification().getRegistrationNumber() != null) {
identification.setRegistrationNumber(
pscDocument.getIdentification().getRegistrationNumber());
}
if (pscDocument.getData().getNaturesOfControl() != null) {
listSummary
.setNaturesOfControl(pscDocument.getData().getNaturesOfControl());
}
listSummary.setIdentification(identification);
}

return listSummary;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,130 @@ public LegalPersonBeneficialOwner transformPscDocToLegalPersonBeneficialOwner(
throw new ResourceNotFoundException(HttpStatus.NOT_FOUND,"PscDocument not found");
}
}

/**
* Transform Legal person Beneficial Owner.
* @param pscDocument PSC.
* @return ListSummary mongo Document.
*/
public ListSummary transformPscDocToListSummary(PscDocument pscDocument) {

ListSummary listSummary = new ListSummary();

PscData getDocument = pscDocument.getData();

if (getDocument.getEtag() != null) {
listSummary.setEtag(getDocument.getEtag());
}
listSummary.setKind(listSummary.getKind());

if (getDocument.getName() != null) {
listSummary.setName(getDocument.getName());
}
if (getDocument.getNameElements() != null) {
NameElements nameElements = new NameElements();
if (getDocument.getNameElements().getTitle() != null) {
nameElements.setTitle(getDocument.getNameElements().getTitle());
}
if (getDocument.getNameElements().getForename() != null) {
nameElements.setForename(getDocument.getNameElements().getForename());
}
if (getDocument.getNameElements().getMiddleName() != null) {
nameElements.setMiddleName(getDocument
.getNameElements().getMiddleName());
}
if (getDocument.getNameElements().getSurname() != null) {
nameElements.setSurname(getDocument.getNameElements().getSurname());
}
listSummary.setNameElements(nameElements);
}
if (getDocument.getAddress() != null) {
Address address = new Address();

if (getDocument.getAddress().getAddressLine1() != null) {
address.setAddressLine1(getDocument.getAddress().getAddressLine1());
}
if (getDocument.getAddress().getAddressLine2() != null) {
address.setAddressLine2(getDocument.getAddress().getAddressLine2());
}
if (getDocument.getAddress().getCountry() != null) {
address.setCountry(getDocument.getAddress().getCountry());
}
if (getDocument.getAddress().getLocality() != null) {
address.setLocality(getDocument.getAddress().getLocality());
}
if (getDocument.getAddress().getPostalCode() != null) {
address.setPostalCode(getDocument.getAddress().getPostalCode());
}
if (getDocument.getAddress().getPremises() != null) {
address.setPremises(getDocument.getAddress().getPremises());
}
if (getDocument.getAddress().getRegion() != null) {
address.setRegion(getDocument.getAddress().getRegion());
}
if (getDocument.getAddress().getCareOf() != null) {
address.setCareOf(getDocument.getAddress().getCareOf());
}
if (getDocument.getAddress().getPoBox() != null) {
address.setPoBox(getDocument.getAddress().getPoBox());
}
listSummary.setAddress(convertAddress(address));
listSummary.setPrincipalOfficeAddress(convertAddress(address));
}
if (getDocument.getNaturesOfControl() != null) {
listSummary
.setNaturesOfControl(getDocument.getNaturesOfControl());
}
if (getDocument.getLinks() != null) {
listSummary.setLinks(getDocument.getLinks());
}
if (getDocument.getCeasedOn() != null) {
listSummary.setCeasedOn(getDocument.getCeasedOn());
}
if (getDocument.getSanctioned() != null) {
listSummary.setIsSanctioned(getDocument.getSanctioned());
}
if (getDocument.getNationality() != null) {
listSummary.setNationality(getDocument.getNationality());
}
if (getDocument.getCountryOfResidence() != null) {
listSummary.setCountryOfResidence(getDocument.getCountryOfResidence());
}
if (getDocument.getDescription() != null) {
listSummary.setDescription(
ListSummary.DescriptionEnum.SUPER_SECURE_PERSONS_WITH_SIGNIFICANT_CONTROL);
}
if (pscDocument.getIdentification() != null) {
Identification identification = new Identification();
if (pscDocument.getIdentification().getCountryRegistered() != null) {
identification.setCountryRegistered(
pscDocument.getIdentification().getCountryRegistered());
}
if (pscDocument.getIdentification().getLegalAuthority() != null) {
identification.setLegalAuthority(
pscDocument.getIdentification().getLegalAuthority());
}
if (pscDocument.getIdentification().getLegalForm() != null) {
identification.setLegalForm(
pscDocument.getIdentification().getLegalForm());
}
if (pscDocument.getIdentification().getPlaceRegistered() != null) {
identification.setPlaceRegistered(
pscDocument.getIdentification().getPlaceRegistered());
}
if (pscDocument.getIdentification().getRegistrationNumber() != null) {
identification.setRegistrationNumber(
pscDocument.getIdentification().getRegistrationNumber());
}
if (pscDocument.getData().getNaturesOfControl() != null) {
listSummary
.setNaturesOfControl(pscDocument.getData().getNaturesOfControl());
}
listSummary.setIdentification(identification);
}

return listSummary;
}

private uk.gov.companieshouse.api.psc.Address convertAddress(
uk.gov.companieshouse.pscdataapi.models.Address inputAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,21 @@ void pscListReturnedByCompanyNumberFromRepository() throws ResourceNotFoundExcep
PscList expectedPscList = testHelper.createPscList();
PscData pscData = new PscData();
document.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(MOCK_COMPANY_NUMBER))
.thenReturn(Optional.ofNullable(testHelper.createMetrics()));
when(repository.getPscDocumentList(anyString(), anyInt(), anyInt())).thenReturn(Optional.of(Collections.singletonList(document)));
when(transformer.transformPscDocToListSummary(document))
.thenReturn(listSummary);

PscList PscDocumentList = service.retrievePscListSummaryFromDb(MOCK_COMPANY_NUMBER,0, false,25);

Expand All @@ -543,12 +553,26 @@ void pscListWithNoMetricsReturnedByCompanyNumberFromRepository() throws Resource
PscList expectedPscList = testHelper.createPscListWithNoMetrics();
PscData pscData = new PscData();
document.setData(pscData);
document.setId("1234");

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(MOCK_COMPANY_NUMBER))
.thenReturn(Optional.empty());
when(repository.getPscDocumentList(anyString(), anyInt(), anyInt())).thenReturn(Optional.of(Collections.singletonList(document)));

when(transformer.transformPscDocToListSummary(document))
.thenReturn(listSummary);

PscList PscDocumentList = service.retrievePscListSummaryFromDb(MOCK_COMPANY_NUMBER,0, false,25);

assertEquals(expectedPscList, PscDocumentList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import uk.gov.companieshouse.api.metrics.*;
import uk.gov.companieshouse.api.psc.*;
import uk.gov.companieshouse.api.psc.InternalData;
import uk.gov.companieshouse.api.psc.ItemLinkTypes;
import uk.gov.companieshouse.api.psc.SensitiveData;
import uk.gov.companieshouse.api.psc.UsualResidentialAddress;
import uk.gov.companieshouse.pscdataapi.models.*;
import uk.gov.companieshouse.pscdataapi.models.Address;
import uk.gov.companieshouse.pscdataapi.models.DateOfBirth;
import uk.gov.companieshouse.pscdataapi.models.NameElements;

public class TestHelper {
public static final String INDIVIDUAL_KIND = "individual-person-with-significant-control";
Expand Down Expand Up @@ -183,7 +183,7 @@ private ListSummary createListSummary() {
nameElements.setMiddleName("Middle");
nameElements.setSurname("Surname");
listSummary.setNameElements(nameElements);
Address address = new Address();
uk.gov.companieshouse.api.psc.Address address = new uk.gov.companieshouse.api.psc.Address();
address.setAddressLine1("1 street");
address.setAddressLine2("2 street");
address.setCountry("uk");
Expand Down

0 comments on commit 2cc56f7

Please sign in to comment.