Skip to content

Commit

Permalink
[PPANTT-153] fix error handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gioelemella committed Oct 10, 2024
1 parent 730d91f commit 111a5e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,22 @@ public void deleteCreditorInstitutionStationRelationship(
String institutionId,
String brokerTaxCode
) {
CreditorInstitutions ciForRollback =
this.apiConfigClient.getCreditorInstitutionsByStation(stationCode, 1, 0, ciTaxCode);
this.apiConfigClient.deleteCreditorInstitutionStationRelationship(ciTaxCode, stationCode);
try {
this.apiManagementService.updateBrokerAuthorizerSegregationCodesMetadata(institutionId, brokerTaxCode);
} catch (Exception e) {
log.error("Failed to update broker {} API key authorizations, revert dissociate station to CI operation",
sanitizeLogParam(brokerTaxCode), e);
CreditorInstitutions creditorInstitutions =
this.apiConfigClient.getCreditorInstitutionsByStation(stationCode, 1, 0, ciTaxCode);
CreditorInstitutionStationEdit dto =
this.modelMapper.map(creditorInstitutions.getCreditorInstitutionList().get(0), CreditorInstitutionStationEdit.class);
dto.setStationCode(stationCode);
this.apiConfigClient.createCreditorInstitutionStationRelationship(ciTaxCode, dto);
if (ciForRollback != null && ciForRollback.getCreditorInstitutionList() != null && ciForRollback.getCreditorInstitutionList().size() == 1) {
CreditorInstitutionStationEdit dto =
this.modelMapper.map(ciForRollback.getCreditorInstitutionList().get(0), CreditorInstitutionStationEdit.class);
dto.setStationCode(stationCode);
this.apiConfigClient.createCreditorInstitutionStationRelationship(ciTaxCode, dto);
} else {
log.error("Unable to rollback dissociate station ({}) to CI ({}) operation", stationCode, ciTaxCode);

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
}
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ void deleteCreditorInstitutionStationRelationship_ok() {

verify(apiConfigClient).deleteCreditorInstitutionStationRelationship(anyString(), anyString());
verify(apiManagementService).updateBrokerAuthorizerSegregationCodesMetadata(INSTITUTION_ID, BROKER_TAX_CODE);
verify(apiConfigClient).getCreditorInstitutionsByStation(STATION_CODE1, 1, 0, CI_TAX_CODE);
verify(apiConfigClient, never()).createCreditorInstitutionStationRelationship(anyString(), any());
}

@Test
Expand All @@ -287,6 +289,9 @@ void deleteCreditorInstitutionStationRelationship_ko() {

assertThrows(FeignException.class, () ->
service.deleteCreditorInstitutionStationRelationship(CI_TAX_CODE, STATION_CODE1, INSTITUTION_ID, BROKER_TAX_CODE));

verify(apiConfigClient).getCreditorInstitutionsByStation(STATION_CODE1, 1, 0, CI_TAX_CODE);
verify(apiConfigClient, never()).createCreditorInstitutionStationRelationship(anyString(), any());
}

@Test
Expand All @@ -301,6 +306,16 @@ void deleteCreditorInstitutionStationRelationshipFailOnAuthorizerUpdateExpectRol
verify(apiConfigClient).createCreditorInstitutionStationRelationship(anyString(), any());
}

@Test
void deleteCreditorInstitutionStationRelationshipFailOnAuthorizerUpdateNoRollback() {
doThrow(AppException.class).when(apiManagementService).updateBrokerAuthorizerSegregationCodesMetadata(anyString(), anyString());
assertThrows(AppException.class, () ->
service.deleteCreditorInstitutionStationRelationship(CI_TAX_CODE, STATION_CODE1, INSTITUTION_ID, BROKER_TAX_CODE));

verify(apiConfigClient).getCreditorInstitutionsByStation(STATION_CODE1, 1, 0, CI_TAX_CODE);
verify(apiConfigClient, never()).createCreditorInstitutionStationRelationship(anyString(), any());
}

@Test
void createCreditorInstitution_ok() throws IOException {
when(apiConfigClient.createCreditorInstitution(any(CreditorInstitutionDetails.class)))
Expand Down

0 comments on commit 111a5e4

Please sign in to comment.