Skip to content

Commit

Permalink
[PPANTT-81] feat: Updated rest call and related tests and interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-cialini committed Sep 13, 2024
1 parent bac28d5 commit 088544a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public class CreditorInstitutionRestClient {
* @param targetHost verify service host
* @param targetPort verify service port
* @param targetPath verify service path
* @param idPsp psp id to be used as parameter for the call
* @param idBrokerPsp broker id to be used as parameter for the call
* @param idStazione station id to be used for the call
* @param fiscalCode fiscal code to be used as input for the call
* @param noticeNumber notice number to be used as input for the call
* @return PaymentOptionResponse
Expand All @@ -47,8 +44,8 @@ public class CreditorInstitutionRestClient {
public PaymentOptionsResponse callEcPaymentOptionsVerify(
String endpoint, String proxyHost, Long proxyPort,
String targetHost, Long targetPort, String targetPath,
String idPsp, String idBrokerPsp,
String idStazione, String fiscalCode, String noticeNumber)
// String idPA, String idBrokerPA, String idStazione,
String fiscalCode, String noticeNumber)
throws MalformedURLException {

RestClientBuilder builder =
Expand All @@ -60,8 +57,10 @@ public PaymentOptionsResponse callEcPaymentOptionsVerify(
CreditorInstitutionRestClientInterface.class);

try (Response response = ecRestClientInterface.verifyPaymentOptions(
fiscalCode, noticeNumber, idPsp, idBrokerPsp, idStazione,
targetHost, targetPort.intValue(), targetPath)) {
fiscalCode, noticeNumber,
// idPA, idBrokerPA, idStazione,
targetHost, targetPort.intValue(),
targetPath)) {

if (response.getStatus() != 200) {
manageErrorResponse(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public interface CreditorInstitutionRestClientInterface {
Response verifyPaymentOptions(
@PathParam("fiscal-code") String fiscalCode,
@PathParam("notice-number") String noticeNumber,
@QueryParam("idPA") String idPA,
@QueryParam("idBrokerPA") String idBrokerPA,
@QueryParam("idStation") String idStation,
// @QueryParam("idPA") String idPA,
// @QueryParam("idBrokerPA") String idBrokerPA,
// @QueryParam("idStation") String idStation,
@HeaderParam("X-Host-Url") String hostUrl,
@HeaderParam("X-Host-Port") Integer hostPort,
@HeaderParam("X-Host-Path") String hostPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public class CreditorInstitutionService {
* The method contains checks regarding the endpoint to use, and attempts to
* extract the REST target params
*
* @param idPsp psp identifier
* @param idBrokerPsp broker psp identifier
// * @param idPA pa identifier
// * @param idBrokerPA broker pa identifier
* @param noticeNumber input notice number
* @param fiscalCode input fiscal code
* @param station station containing the connection config to use
* @return
*/
public PaymentOptionsResponse getPaymentOptions(
String idPsp, String idBrokerPsp,
//String idPA, String idBrokerPA,
String noticeNumber, String fiscalCode, Station station) {

if (station.getConnection().getIp() == null ||
Expand Down Expand Up @@ -85,7 +85,7 @@ public PaymentOptionsResponse getPaymentOptions(
station.getProxy() != null ? station.getProxy().getProxyHost() : null,
station.getProxy() != null ? station.getProxy().getProxyPort() : null,
targetHost, targetPort, targetPath,
idPsp, idBrokerPsp, station.getStationCode(), fiscalCode, noticeNumber
fiscalCode, noticeNumber
);
} catch (MalformedURLException e) {
logger.error("[Payment Options] Malformed URL: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public Map<String, String> start() {

wireMockServer.stubFor(
get(urlEqualTo(
"/payment-options/organizations/77777777777/notices/311111111112222222"
+ "?idPA=88888888888&idBrokerPA=88888888888&idStation=88888888888_01"))
"/payment-options/organizations/77777777777/notices/311111111112222222"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withResponseBody(
Expand All @@ -41,8 +40,7 @@ public Map<String, String> start() {

wireMockServer.stubFor(
get(urlEqualTo(
"/payment-options/organizations/87777777777/notices/311111111112222222"
+ "?idPA=88888888888&idBrokerPA=88888888888&idStation=88888888888_01"))
"/payment-options/organizations/87777777777/notices/311111111112222222"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withStatus(412)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ void callEcPaymentOptionsVerifyShouldReturnData() {
assertDoesNotThrow(() -> creditorInstitutionRestClient.callEcPaymentOptionsVerify(
wiremockUrl, null, null,
"http://externalService", 443L, "/externalPath",
"88888888888", "88888888888", "88888888888_01",
"77777777777", "311111111112222222"));
"88888888888", "88888888888"));
assertNotNull(paymentOptionsResponse);
}

Expand All @@ -47,8 +46,7 @@ void callEcPaymentOptionsVerifyShouldReturnErrorResponse() {
() -> creditorInstitutionRestClient.callEcPaymentOptionsVerify(
wiremockUrl, null, null,
"http://externalService", 443L, "/externalPath",
"88888888888", "88888888888", "88888888888_01",
"87777777777", "311111111112222222"));
"88888888888", "88888888888"));
assertNotNull(exception);
assertEquals(exception.getErrorResponse().getHttpStatusCode(), 500);
}
Expand All @@ -60,8 +58,7 @@ void callEcPaymentOptionsVerifyShouldReturnUnreachableKOWithoutErrorResponse() {
() -> creditorInstitutionRestClient.callEcPaymentOptionsVerify(
wiremockUrl, null, null,
"http://externalService", 443L, "/externalPath",
"08888888888", "88888888888", "88888888888_01",
"87777777777", "311111111112222222"));
"08888888888", "88888888888"));
assertNotNull(exception);
assertEquals(exception.getErrorCode(), AppErrorCodeEnum.ODP_STAZIONE_INT_PA_IRRAGGIUNGIBILE);
}
Expand All @@ -73,8 +70,7 @@ void callEcPaymentOptionsVerifyShouldReturnExceptionOnMalformedUrl() {
() -> creditorInstitutionRestClient.callEcPaymentOptionsVerify(
"AAAAAAA", null, null,
"http://externalService", 443L, "/externalPath",
"88888888888", "88888888888", "88888888888_01",
"87777777777", "311111111112222222"));
"88888888888", "88888888888"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public void init() {
@Test
void getPaymentOptionsShouldReturnData() throws MalformedURLException {
when(creditorInstitutionRestClient.callEcPaymentOptionsVerify(
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())
any(), any(), any(), any(), any(), any(), any(), any())
).thenReturn(PaymentOptionsResponse.builder().build());
PaymentOptionsResponse paymentOptionsResponse =
assertDoesNotThrow(() -> creditorInstitutionService.getPaymentOptions(
"000001","000001","12345","322334",
"000001","000001",
Station.builder().stationCode("000001_01")
.connection(
Connection.builder()
Expand All @@ -58,17 +58,17 @@ void getPaymentOptionsShouldReturnData() throws MalformedURLException {
));
assertNotNull(paymentOptionsResponse);
verify(creditorInstitutionRestClient).callEcPaymentOptionsVerify(
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
any(), any(), any(), any(), any(), any(), any(), any());
}

@Test
void getPaymentOptionsShouldReturnExceptionOnMalformed() throws MalformedURLException {
when(creditorInstitutionRestClient.callEcPaymentOptionsVerify(
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())
any(), any(), any(), any(), any(), any(), any(), any())
).thenThrow(new MalformedURLException());
PaymentOptionsException paymentOptionsException =
assertThrows(PaymentOptionsException.class, () -> creditorInstitutionService.getPaymentOptions(
"000001","000001","12345","322334",
"000001","000001",
Station.builder().stationCode("000001_01")
.connection(
Connection.builder()
Expand All @@ -84,14 +84,15 @@ void getPaymentOptionsShouldReturnExceptionOnMalformed() throws MalformedURLExce
assertNotNull(paymentOptionsException);
assertEquals(paymentOptionsException.getErrorCode(), AppErrorCodeEnum.ODP_SEMANTICA);
verify(creditorInstitutionRestClient).callEcPaymentOptionsVerify(
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
any(), any(), any(), any(), any(), any(), any(), any()
);
}

@Test
void getPaymentOptionsShouldReturnExceptionOnMissingEndpoint() throws MalformedURLException {
PaymentOptionsException paymentOptionsException =
assertThrows(PaymentOptionsException.class, () -> creditorInstitutionService.getPaymentOptions(
"000001","000001","12345","322334",
"000001","000001",
Station.builder().stationCode("000001_01")
.connection(
Connection.builder()
Expand All @@ -113,7 +114,7 @@ void getPaymentOptionsShouldReturnExceptionOnMissingEndpoint() throws MalformedU
void getPaymentOptionsShouldReturnExceptionOnBrokerServiceUrl() throws MalformedURLException {
PaymentOptionsException paymentOptionsException =
assertThrows(PaymentOptionsException.class, () -> creditorInstitutionService.getPaymentOptions(
"000001","000001","12345","322334",
"000001","000001",
Station.builder().stationCode("000001_01")
.connection(
Connection.builder()
Expand Down

0 comments on commit 088544a

Please sign in to comment.