diff --git a/openapi/openapi.json b/openapi/openapi.json index f996b382..cd9cb5e1 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -1,248 +1,216 @@ { - "openapi": "3.0.1", - "info": { - "description": "A service that permits to handle nodoInviaRPT and nodoInviaCarrelloRPT request from WISP, converting them in NMU payments.\n\n# OPERATIVE INFO\n\n\n## EVENT MAPPING IN RE\n\n
Details\nFIELD | SCOPE | DESCRIPTION\n- | - | -\n**requestId** | BOTH | The identifier, set by X-Request-ID, from which the events can be grouped.\n**operationId** | BOTH | The identifier associated to a request identifier\n**clientOperationId** | BOTH | The identifier that associate a client to an operation identifier.\n**component** | BOTH | The applicative component from which the event is generated.
In NDP it is mapped with field 'componente'.
Values:
_WISP_SOAP_CONVERTER_
_WISP_CONVERTER_\n**insertedTimestamp** | BOTH | The time on which the event is inserted in RE storage\n**eventCategory** | BOTH | The category on which the event can be grouped.
In NDP it is mapped with field 'categoriaEvento'.
Values:
_INTERFACE_
_INTERNAL_\n**eventSubcategory** | BOTH | The subcategory related to the specific nature of the event.
In NDP it is mapped with field 'sottoTipoEvento'.
Values:
_REQ_
_RESP_
_INTERN_\n**callType** | INTERFACE | The type of role that the application has in the communication with the remote endpoint.
Values:
_SERVER_
_CLIENT_\n**consumer** | INTERFACE | The service that is consumer in the step execution.
In NDP it is mapped with field 'fruitore'.\n**provider** | INTERFACE | The service that provide to the step execution.
In NDP it is mapped with field 'erogatore'.\n**outcome** | INTERFACE | The outcome of the operation described by the event.
In NDP it is mapped with field 'esito'.
Values:
_SEND_: Correctly sent request to HTTP endpoint. In NDP it is mapped with value 'INVIATA'.
_SEND_FAILURE_: Failed to send request to HTTP endpoint. In NDP it is mapped with value 'INVIATA_KO'
_RECEIVED_: Received an OK response from HTTP endpoint. In NDP it is mapped with value 'RICEVUTA_KO'
_RECEIVED_FAILURE_: Received a failure response from endpoint. In NDP it is mapped with value 'RICEVUTA_KO'
_NEVER_RECEIVED_: Failed to receive response at all from endpoint. In NDP it is mapped with value 'NO_RICEVUTA'
_EXECUTED_INTERNAL_STEP_: Executed internal step on execution. In NDP it is mapped with value 'CAMBIO_STATO'\n**httpMethod** | INTERFACE | The HTTP method of the endpoint related to the event.
This field is set only if the events that describe an HTTP communication with an external service.\n**httpUri** | INTERFACE | The URI related to the called endpoint.
This field is set only if the events that describe an HTTP communication with an external service.\n**httpHeaders** | INTERFACE | The list of HTTP headers extracted from the request/response analyzed by the event.
This field is set only if the events that describe an HTTP communication with an external service.\n**httpCallRemoteAddress** | INTERFACE | The remote IP address extracted from the called endpoint.
This field is set only if the events that describe an HTTP communication with an external service.\n**httpStatusCode** | INTERFACE | The status code extracted from the called endpoint.
This field is set only if the events that describe an HTTP communication with an external service.\n**executionTimeMs** | INTERFACE | The duration time of the invocation of the endpoint related to the event.
This field is set only if the events that describe an HTTP communication with an external service.\n**compressedPayload** | INTERFACE | The payload of the request/response analyzed by the event.
This value is zipped using GZip compression algorithm.\n**compressedPayloadLength** | INTERFACE | The length (in number of characters) of the compressed payload.\n**businessProcess** | INTERFACE | The descriptive label associated to the endpoint called by user and related to the whole process.\n**operationStatus** | INTERFACE | The final status of the whole operation.
This is set only in the events that describe the response in output to user.\n**operationErrorTitle** | INTERFACE | The error title extracted from the computation that refers to the error occurred during computation.
This is set only in the events that describe the response in output to user if there is an error.\n**operationErrorDetail** | INTERFACE | The error detail message extracted from the computation that refers to the error occurred during computation.
This is set only in the events that describe the response in output to user if there is an error.\n**operationErrorCode** | INTERFACE | The error code extracted from the computation that refers to the error occurred during computation.
This is set only in the events that describe the response in output to user if there is an error.\n**primitive** | INTERNAL | The typology of primitive analyzed and tracked by the event.
In NDP it is mapped with field 'eventType'.\n**sessionId** | INTERNAL | The session identifier generated by WISP SOAP Converter and used in the request.\n**cartId** | INTERNAL | The cart identifier used in the request.\n**iuv** | INTERNAL | The 'identificativo univoco pagamento' used in the request.\n**noticeNumber** | INTERNAL | The notice number (aka NAV code) used in the request.\n**domainId** | INTERNAL | The creditor institution identifier used in the request.\n**ccp** | INTERNAL | The 'codice contesto pagamento' used in the request.\n**psp** | INTERNAL | The payment service provider used in the request.\n**station** | INTERNAL | The station used in the request.\n**channel** | INTERNAL | The channel used in the request.\n**status** | INTERNAL | The state of the internal step executed.
Values:
_FOUND_RPT_IN_STORAGE_
_EXTRACTED_DATA_FROM_RPT_
_CREATED_NEW_PAYMENT_POSITION_IN_GPD_
_UPDATED_EXISTING_PAYMENT_POSITION_IN_GPD_
_FOUND_INVALID_PAYMENT_POSITION_IN_GPD_
_GENERATED_CACHE_FOR_DECOUPLER_ABOUT_RPT_
_RECEIVED_REDIRECT_URL_FROM_CHECKOUT_
_GENERATED_NEW_RT_
_NEGATIVE_RT_NOT_GENERABLE_
_NEGATIVE_RT_GENERATION_SKIPPED_
_RT_SEND_SUCCESS_
_RT_SEND_FAILURE_\n**info** | INTERNAL | The other information that can be inserted for the tracing.\n**paymentToken** | INTERNAL | The payment token.\n\n
\n\n\n## OPERATIONAL ERROR CODES\n\n
Details\nNAME | CODE | DESCRIPTION\n- | - | -\n**WIC-500** | *ERROR* | A not documented generic error occurred while execution. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-1000** | *GENERIC_ERROR* | A generic error occurred while executing conversion flow. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-1001** | *PARSING_GENERIC_ERROR* | A generic error occurred while parsing of the content associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-1002** | *PARSING_INVALID_HEADER* | An error occurred while parsing of the content header, associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT.\n**WIC-1003** | *PARSING_INVALID_BODY* | An error occurred while parsing of the content payload, associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT.\n**WIC-1004** | *PARSING_INVALID_XML_NODES* | An error occurred while parsing of the of the content associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT. The XML content extracted, either from payload or from header, is invalid because it is not possible to extract tag nodes from document. So, the document is probably empty.\n**WIC-1005** | *PARSING_INVALID_ZIPPED_PAYLOAD* | An error occurred while parsing of the content associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT. The SOAP request analyzed and stored in dedicated storage is not usable for convert the debt positions in GPD system. This is probably due to an invalid conversion of the SOAP request via GZip algorithm executed before the same is stored in its storage.\n**WIC-1006** | *PARSING_RPT_PRIMITIVE_NOT_VALID* | An error occurred while parsing of the content associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT. The primitive (the content related to header 'soapaction') cannot be handled by WISP Converter application in redirect process: only one of nodoInviaRPT and nodoInviaCarrelloRPT can be accepted.\n**WIC-1100** | *VALIDATION_INVALID_MULTIBENEFICIARY_CART* | An error occurred while analyzing the RPTs extracted from SOAP request. In particular, the request is arrived as nodoInviaCarrelloRPT as multi-beneficiary cart, but the number of RPTs in the request is lower than two, so it cannot be correctly handled as multi-beneficiary.\n**WIC-1101** | *VALIDATION_INVALID_IBANS* | An error occurred while analyzing the RPTs extracted from SOAP request. An IBAN must always be set in RPT transfers if they aren't related to digital stamps (which don't require an IBAN, because they will be reported to specific subject). In this case, in one or more RPT transfers not related to digital stamp, the IBAN is not correctly set.\n**WIC-1102** | *VALIDATION_INVALID_DEBTOR* | An error occurred while analyzing the RPTs extracted from SOAP request. In particular, in a cart there are different debtor subjects and this is not permitted for this flow. So, the whole cart is discarded.\n**WIC-1103** | *VALIDATION_INVALID_CREDITOR_INSTITUTION* | An error occurred while analyzing the RPTs extracted from SOAP request. In particular, in a cart there are different RPT that refers to different payees, but this is not permitted when the cart is not for multi-beneficiary. So, the whole cart is discarded.\n**WIC-1200** | *CONFIGURATION_INVALID_CACHE* | An error occurred while trying to access data from cached configuration. It is possible that the cache is not retrieved yet by this service or a corrupted configuration was returned from APIConfig Cache internal service. If this problem still occurs, please check the connectivity with APIConfig Cache.\n**WIC-1201** | *CONFIGURATION_INVALID_STATION* | An error occurred while retrieving data from local cached configuration. In particular, it is not possible to retrieve the configuration about the station because it does not exists in cache, and maybe also in general configuration. So, a change in whole configuration and/or a refresh on cache is required.\n**WIC-1202** | *CONFIGURATION_INVALID_CREDITOR_INSTITUTION_STATION* | An error occurred while checking the station that will be used for the payment process. In particular, analyzing the station that is related to the segregation code extracted from a payment option's notice number, it turns out that the required station does not exists in cached configuration. So, a change in whole configuration and/or a refresh on cache is required.\n**WIC-1203** | *CONFIGURATION_INVALID_STATION_REDIRECT_URL* | An error occurred while checking the station that will be used for the payment process. In particular, analyzing the station that is related to the segregation code extracted from a payment option's notice number, it turns out that the configuration about redirection in error cases is not correctly set to points towards some creditor institution's endpoint. So, a change in configuration is required.\n**WIC-1204** | *CONFIGURATION_INVALID_STATION_SERVICE_URL* | An error occurred while checking the station that will be used for the payment process. In particular, analyzing the station that is related to the segregation code extracted from a payment option's notice number, it turns out that the configuration is not correctly set to points towards GPD service endpoint for RT generator. So, a change in configuration is required.\n**WIC-1205** | *CONFIGURATION_INVALID_GPD_STATION* | An error occurred while checking the station that will be used for the payment process. In particular, analyzing the station that is related to the segregation code extracted from a payment option's notice number, it turns out that the configuration is correctly set to points towards GPD service endpoint but uses the 'v1' primitive version (and it must use the 'v2' version). So, a change in configuration is required.\n**WIC-1300** | *PAYMENT_POSITION_NOT_IN_PAYABLE_STATE* | An error occurred while checking an existing payment position. One or more RPTs extracted from the request refers to existing payment positions in GPD that have a state from which it is impossible to execute a payment flow. If the execution of this flow is related to a RPT cart, all the payments that can be retrieved or generated ex novo from those RPTs are declared as atomically invalid (if one RPT in cart is bad, all RPTs in cart are bad) and not payable with this flow.\n**WIC-1301** | *PAYMENT_POSITION_IN_INCONSISTENT_STATE* | An error occurred while checking an existing payment position in GPD system. The retrieved payment position, previously inserted in GPD by this same flow or by other procedures, is in an invalid state, not mappable to an existing value. This can be related to a wrong setting in GPD or a corruption of the retrieved data.\n**WIC-1302** | *PAYMENT_POSITION_NOT_VALID* | An error occurred while generating a payment position. In particular, something during the generation of a new payment position or the analysis of an existing payment position went wrong and the operation cannot be completed. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-1303** | *PAYMENT_OPTION_NOT_EXTRACTABLE* | An error occurred while extracting a payment option from a payment position. This can be caused by a malformed payment position that does not have a payment option. Remember that a payment position in this flow must have one and only one payment option.\n**WIC-1400** | *RECEIPT_KO_NOT_GENERATED* | An error occurred while generating a negative RT (aka a KO receipt). So, no receipt can be sent lately to creditor institution and probably the process must be executed manually. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-2000** | *PERSISTENCE_SAVING_RE_ERROR* | An error occurred wile trying to store a new event in the Registro Eventi storage. The error is somewhat related to a persistence problem of the used storage and in the majority of the cases is temporary (maybe a 429 HTTP code). This error currently blocks the entire flow because that can lead to untraceable requests. For better understanding the cause, please execute a search in the log provider (Application Insights, Kibana, etc).\n**WIC-2001** | *PERSISTENCE_RPT_NOT_FOUND* | An error occurred while trying to retrieve the RPT content saved in storage by WISP SOAP Converter. This can be related either with the use of a wrong sessionId or a missed persistence from WISP SOAP Converter, so it is better to analyze the entire flow using Technical Support's APIs. This block totally the conversion of the RPTs in GPD's payment positions, so the whole process is discarded.\n**WIC-2002** | *PERSISTENCE_REQUESTID_CACHING_ERROR* | An error occurred while trying to retrieve data from internal cache. Specifically, the cached key, defined in format wisp_nav2iuv__
\n", - "termsOfService": "https://www.pagopa.gov.it/", - "title": "WISP Converter", - "version": "0.0.22" + "openapi" : "3.0.1", + "info" : { + "description" : "A service that permits to handle nodoInviaRPT and nodoInviaCarrelloRPT request from WISP, converting them in NMU payments.\n\n# OPERATIVE INFO\n\n\n## EVENT MAPPING IN RE\n\n
Details\nFIELD | SCOPE | DESCRIPTION\n- | - | -\n**requestId** | BOTH | The identifier, set by X-Request-ID, from which the events can be grouped.\n**operationId** | BOTH | The identifier associated to a request identifier\n**clientOperationId** | BOTH | The identifier that associate a client to an operation identifier.\n**component** | BOTH | The applicative component from which the event is generated.
In NDP it is mapped with field 'componente'.
Values:
_WISP_SOAP_CONVERTER_
_WISP_CONVERTER_\n**insertedTimestamp** | BOTH | The time on which the event is inserted in RE storage\n**eventCategory** | BOTH | The category on which the event can be grouped.
In NDP it is mapped with field 'categoriaEvento'.
Values:
_INTERFACE_
_INTERNAL_\n**eventSubcategory** | BOTH | The subcategory related to the specific nature of the event.
In NDP it is mapped with field 'sottoTipoEvento'.
Values:
_REQ_
_RESP_
_INTERN_\n**callType** | INTERFACE | The type of role that the application has in the communication with the remote endpoint.
Values:
_SERVER_
_CLIENT_\n**consumer** | INTERFACE | The service that is consumer in the step execution.
In NDP it is mapped with field 'fruitore'.\n**provider** | INTERFACE | The service that provide to the step execution.
In NDP it is mapped with field 'erogatore'.\n**outcome** | INTERFACE | The outcome of the operation described by the event.
In NDP it is mapped with field 'esito'.
Values:
_SEND_: Correctly sent request to HTTP endpoint. In NDP it is mapped with value 'INVIATA'.
_SEND_FAILURE_: Failed to send request to HTTP endpoint. In NDP it is mapped with value 'INVIATA_KO'
_RECEIVED_: Received an OK response from HTTP endpoint. In NDP it is mapped with value 'RICEVUTA_KO'
_RECEIVED_FAILURE_: Received a failure response from endpoint. In NDP it is mapped with value 'RICEVUTA_KO'
_NEVER_RECEIVED_: Failed to receive response at all from endpoint. In NDP it is mapped with value 'NO_RICEVUTA'
_EXECUTED_INTERNAL_STEP_: Executed internal step on execution. In NDP it is mapped with value 'CAMBIO_STATO'\n**httpMethod** | INTERFACE | The HTTP method of the endpoint related to the event.
This field is set only if the events that describe an HTTP communication with an external service.\n**httpUri** | INTERFACE | The URI related to the called endpoint.
This field is set only if the events that describe an HTTP communication with an external service.\n**httpHeaders** | INTERFACE | The list of HTTP headers extracted from the request/response analyzed by the event.
This field is set only if the events that describe an HTTP communication with an external service.\n**httpCallRemoteAddress** | INTERFACE | The remote IP address extracted from the called endpoint.
This field is set only if the events that describe an HTTP communication with an external service.\n**httpStatusCode** | INTERFACE | The status code extracted from the called endpoint.
This field is set only if the events that describe an HTTP communication with an external service.\n**executionTimeMs** | INTERFACE | The duration time of the invocation of the endpoint related to the event.
This field is set only if the events that describe an HTTP communication with an external service.\n**compressedPayload** | INTERFACE | The payload of the request/response analyzed by the event.
This value is zipped using GZip compression algorithm.\n**compressedPayloadLength** | INTERFACE | The length (in number of characters) of the compressed payload.\n**businessProcess** | INTERFACE | The descriptive label associated to the endpoint called by user and related to the whole process.\n**operationStatus** | INTERFACE | The final status of the whole operation.
This is set only in the events that describe the response in output to user.\n**operationErrorTitle** | INTERFACE | The error title extracted from the computation that refers to the error occurred during computation.
This is set only in the events that describe the response in output to user if there is an error.\n**operationErrorDetail** | INTERFACE | The error detail message extracted from the computation that refers to the error occurred during computation.
This is set only in the events that describe the response in output to user if there is an error.\n**operationErrorCode** | INTERFACE | The error code extracted from the computation that refers to the error occurred during computation.
This is set only in the events that describe the response in output to user if there is an error.\n**primitive** | INTERNAL | The typology of primitive analyzed and tracked by the event.
In NDP it is mapped with field 'eventType'.\n**sessionId** | INTERNAL | The session identifier generated by WISP SOAP Converter and used in the request.\n**cartId** | INTERNAL | The cart identifier used in the request.\n**iuv** | INTERNAL | The 'identificativo univoco pagamento' used in the request.\n**noticeNumber** | INTERNAL | The notice number (aka NAV code) used in the request.\n**domainId** | INTERNAL | The creditor institution identifier used in the request.\n**ccp** | INTERNAL | The 'codice contesto pagamento' used in the request.\n**psp** | INTERNAL | The payment service provider used in the request.\n**station** | INTERNAL | The station used in the request.\n**channel** | INTERNAL | The channel used in the request.\n**status** | INTERNAL | The state of the internal step executed.
Values:
_FOUND_RPT_IN_STORAGE_
_EXTRACTED_DATA_FROM_RPT_
_CREATED_NEW_PAYMENT_POSITION_IN_GPD_
_GENERATED_NAV_FOR_NEW_PAYMENT_POSITION_
_UPDATED_EXISTING_PAYMENT_POSITION_IN_GPD_
_FOUND_INVALID_PAYMENT_POSITION_IN_GPD_
_GENERATED_CACHE_ABOUT_RPT_FOR_DECOUPLER_
_GENERATED_CACHE_ABOUT_RPT_FOR_RT_GENERATION_
_SAVED_RPT_IN_CART_RECEIVED_REDIRECT_URL_FROM_CHECKOUT_
_GENERATED_NEW_RT_
_NEGATIVE_RT_NOT_GENERABLE_
_NEGATIVE_RT_GENERATION_SKIPPED_
_NEGATIVE_RT_GENERATION_SUCCESS_
_RT_SEND_SUCCESS_
_RT_SEND_FAILURE_\n**info** | INTERNAL | The other information that can be inserted for the tracing.\n**paymentToken** | INTERNAL | The payment token.\n\n
\n\n\n## OPERATIONAL ERROR CODES\n\n
Details\nNAME | CODE | DESCRIPTION\n- | - | -\n**WIC-500** | *ERROR* | A not documented generic error occurred while execution. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-1000** | *GENERIC_ERROR* | A generic error occurred while executing conversion flow. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-1001** | *PARSING_GENERIC_ERROR* | A generic error occurred while parsing of the content associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-1002** | *PARSING_INVALID_HEADER* | An error occurred while parsing of the content header, associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT.\n**WIC-1003** | *PARSING_INVALID_BODY* | An error occurred while parsing of the content payload, associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT.\n**WIC-1004** | *PARSING_INVALID_XML_NODES* | An error occurred while parsing of the of the content associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT. The XML content extracted, either from payload or from header, is invalid because it is not possible to extract tag nodes from document. So, the document is probably empty.\n**WIC-1005** | *PARSING_INVALID_ZIPPED_PAYLOAD* | An error occurred while parsing of the content associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT. The SOAP request analyzed and stored in dedicated storage is not usable for convert the debt positions in GPD system. This is probably due to an invalid conversion of the SOAP request via GZip algorithm executed before the same is stored in its storage.\n**WIC-1006** | *PARSING_RPT_PRIMITIVE_NOT_VALID* | An error occurred while parsing of the content associated to the SOAP request related to nodoInviaRPT or nodoInviaCarrelloRPT. The primitive (the content related to header 'soapaction') cannot be handled by WISP Converter application in redirect process: only one of nodoInviaRPT and nodoInviaCarrelloRPT can be accepted.\n**WIC-1100** | *VALIDATION_INVALID_MULTIBENEFICIARY_CART* | An error occurred while analyzing the RPTs extracted from SOAP request. In particular, the request is arrived as nodoInviaCarrelloRPT as multi-beneficiary cart, but the number of RPTs in the request is lower than two, so it cannot be correctly handled as multi-beneficiary.\n**WIC-1101** | *VALIDATION_INVALID_IBANS* | An error occurred while analyzing the RPTs extracted from SOAP request. An IBAN must always be set in RPT transfers if they aren't related to digital stamps (which don't require an IBAN, because they will be reported to specific subject). In this case, in one or more RPT transfers not related to digital stamp, the IBAN is not correctly set.\n**WIC-1102** | *VALIDATION_INVALID_DEBTOR* | An error occurred while analyzing the RPTs extracted from SOAP request. In particular, in a cart there are different debtor subjects and this is not permitted for this flow. So, the whole cart is discarded.\n**WIC-1103** | *VALIDATION_INVALID_CREDITOR_INSTITUTION* | An error occurred while analyzing the RPTs extracted from SOAP request. In particular, in a cart there are different RPT that refers to different payees, but this is not permitted when the cart is not for multi-beneficiary. So, the whole cart is discarded.\n**WIC-1200** | *CONFIGURATION_INVALID_CACHE* | An error occurred while trying to access data from cached configuration. It is possible that the cache is not retrieved yet by this service or a corrupted configuration was returned from APIConfig Cache internal service. If this problem still occurs, please check the connectivity with APIConfig Cache.\n**WIC-1201** | *CONFIGURATION_INVALID_STATION* | An error occurred while retrieving data from local cached configuration. In particular, it is not possible to retrieve the configuration about the station because it does not exists in cache, and maybe also in general configuration. So, a change in whole configuration and/or a refresh on cache is required.\n**WIC-1202** | *CONFIGURATION_INVALID_CREDITOR_INSTITUTION_STATION* | An error occurred while checking the station that will be used for the payment process. In particular, analyzing the station that is related to the segregation code extracted from a payment option's notice number, it turns out that the required station does not exists in cached configuration. So, a change in whole configuration and/or a refresh on cache is required.\n**WIC-1203** | *CONFIGURATION_INVALID_STATION_REDIRECT_URL* | An error occurred while checking the station that will be used for the payment process. In particular, analyzing the station that is related to the segregation code extracted from a payment option's notice number, it turns out that the configuration about redirection in error cases is not correctly set to points towards some creditor institution's endpoint. So, a change in configuration is required.\n**WIC-1204** | *CONFIGURATION_INVALID_STATION_SERVICE_URL* | An error occurred while checking the station that will be used for the payment process. In particular, analyzing the station that is related to the segregation code extracted from a payment option's notice number, it turns out that the configuration is not correctly set to points towards GPD service endpoint for RT generator. So, a change in configuration is required.\n**WIC-1205** | *CONFIGURATION_INVALID_GPD_STATION* | An error occurred while checking the station that will be used for the payment process. In particular, analyzing the station that is related to the segregation code extracted from a payment option's notice number, it turns out that the configuration is correctly set to points towards GPD service endpoint but uses the 'v1' primitive version (and it must use the 'v2' version). So, a change in configuration is required.\n**WIC-1300** | *PAYMENT_POSITION_NOT_IN_PAYABLE_STATE* | An error occurred while checking an existing payment position. One or more RPTs extracted from the request refers to existing payment positions in GPD that have a state from which it is impossible to execute a payment flow. If the execution of this flow is related to a RPT cart, all the payments that can be retrieved or generated ex novo from those RPTs are declared as atomically invalid (if one RPT in cart is bad, all RPTs in cart are bad) and not payable with this flow.\n**WIC-1301** | *PAYMENT_POSITION_IN_INCONSISTENT_STATE* | An error occurred while checking an existing payment position in GPD system. The retrieved payment position, previously inserted in GPD by this same flow or by other procedures, is in an invalid state, not mappable to an existing value. This can be related to a wrong setting in GPD or a corruption of the retrieved data.\n**WIC-1302** | *PAYMENT_POSITION_NOT_VALID* | An error occurred while generating a payment position. In particular, something during the generation of a new payment position or the analysis of an existing payment position went wrong and the operation cannot be completed. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-1303** | *PAYMENT_OPTION_NOT_EXTRACTABLE* | An error occurred while extracting a payment option from a payment position. This can be caused by a malformed payment position that does not have a payment option. Remember that a payment position in this flow must have one and only one payment option.\n**WIC-1400** | *RECEIPT_KO_NOT_GENERATED* | An error occurred while generating a negative RT (aka a KO receipt). So, no receipt can be sent lately to creditor institution and probably the process must be executed manually. For better understanding the cause, please use the Technical Support's APIs.\n**WIC-2000** | *PERSISTENCE_SAVING_RE_ERROR* | An error occurred wile trying to store a new event in the Registro Eventi storage. The error is somewhat related to a persistence problem of the used storage and in the majority of the cases is temporary (maybe a 429 HTTP code). This error currently blocks the entire flow because that can lead to untraceable requests. For better understanding the cause, please execute a search in the log provider (Application Insights, Kibana, etc).\n**WIC-2001** | *PERSISTENCE_RPT_NOT_FOUND* | An error occurred while trying to retrieve the RPT content saved in storage by WISP SOAP Converter. This can be related either with the use of a wrong sessionId or a missed persistence from WISP SOAP Converter, so it is better to analyze the entire flow using Technical Support's APIs. This block totally the conversion of the RPTs in GPD's payment positions, so the whole process is discarded.\n**WIC-2002** | *PERSISTENCE_REQUESTID_CACHING_ERROR* | An error occurred while trying to retrieve data from internal cache. Specifically, the cached key, defined in format wisp_nav2iuv__
\n", + "termsOfService" : "https://www.pagopa.gov.it/", + "title" : "WISP Converter", + "version" : "0.0.22" }, - "servers": [ - { - "url": "http://localhost", - "description": "Generated server url" - } - ], - "tags": [ - { - "description": "Application info APIs", - "name": "Home" - }, - { - "description": "Convert sendPaymentResultV2, closePaymentV2 or paSendRTV2 into paaInviaRT to EC", - "name": "Receipt" - }, - { - "description": "Conversion and redirection APIs", - "name": "Redirect" - } - ], - "paths": { - "/info": { - "get": { - "operationId": "healthCheck", - "responses": { - "200": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AppInfoResponse" + "servers" : [ { + "url" : "http://localhost", + "description" : "Generated server url" + } ], + "tags" : [ { + "description" : "Application info APIs", + "name" : "Home" + }, { + "description" : "Convert sendPaymentResultV2, closePaymentV2 or paSendRTV2 into paaInviaRT to EC", + "name" : "Receipt" + }, { + "description" : "Conversion and redirection APIs", + "name" : "Redirect" + } ], + "paths" : { + "/info" : { + "get" : { + "operationId" : "healthCheck", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/AppInfoResponse" } } }, - "description": "OK.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "description" : "OK.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "summary": "Return OK if application is started", - "tags": [ - "Home" - ] + "security" : [ { + "ApiKey" : [ ] + } ], + "summary" : "Return OK if application is started", + "tags" : [ "Home" ] }, - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } + "parameters" : [ { + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "in" : "header", + "name" : "X-Request-Id", + "schema" : { + "type" : "string" } - ] + } ] }, - "/payments": { - "get": { - "operationId": "redirect", - "parameters": [ - { - "example": "identificativoIntermediarioPA_sessionId", - "in": "query", - "name": "sessionId", - "required": true, - "schema": { - "type": "string" - } + "/payments" : { + "get" : { + "operationId" : "redirect", + "parameters" : [ { + "example" : "identificativoIntermediarioPA_sessionId", + "in" : "query", + "name" : "sessionId", + "required" : true, + "schema" : { + "type" : "string" } - ], - "responses": { - "302": { - "description": "Redirect to Checkout service.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + } ], + "responses" : { + "302" : { + "description" : "Redirect to Checkout service.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "tags": [ - "Redirect" - ] + "security" : [ { + "ApiKey" : [ ] + } ], + "tags" : [ "Redirect" ] }, - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } + "parameters" : [ { + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "in" : "header", + "name" : "X-Request-Id", + "schema" : { + "type" : "string" } - ] + } ] }, - "/receipt/ko": { - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } + "/receipt/ko" : { + "parameters" : [ { + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "in" : "header", + "name" : "X-Request-Id", + "schema" : { + "type" : "string" } - ], - "post": { - "operationId": "receiptKo", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ReceiptRequest" + } ], + "post" : { + "operationId" : "receiptKo", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ReceiptRequest" } } }, - "required": true + "required" : true }, - "responses": { - "200": { - "description": "Successfully forwarded paaInviaRT- to EC", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "responses" : { + "200" : { + "description" : "Successfully forwarded paaInviaRT- to EC", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "tags": [ - "Receipt" - ] + "security" : [ { + "ApiKey" : [ ] + } ], + "tags" : [ "Receipt" ] } }, - "/receipt/ok": { - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } + "/receipt/ok" : { + "parameters" : [ { + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "in" : "header", + "name" : "X-Request-Id", + "schema" : { + "type" : "string" } - ], - "post": { - "operationId": "receiptOk", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ReceiptRequest" + } ], + "post" : { + "operationId" : "receiptOk", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ReceiptRequest" } } }, - "required": true + "required" : true }, - "responses": { - "200": { - "description": "Successfully forwarded paaInviaRT+ to EC", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "responses" : { + "200" : { + "description" : "Successfully forwarded paaInviaRT+ to EC", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "tags": [ - "Receipt" - ] + "security" : [ { + "ApiKey" : [ ] + } ], + "tags" : [ "Receipt" ] } } }, - "components": { - "schemas": { - "AppInfoResponse": { - "type": "object", - "properties": { - "environment": { - "type": "string" + "components" : { + "schemas" : { + "AppInfoResponse" : { + "type" : "object", + "properties" : { + "environment" : { + "type" : "string" }, - "name": { - "type": "string" + "name" : { + "type" : "string" }, - "version": { - "type": "string" + "version" : { + "type" : "string" } } }, - "ReceiptRequest": { - "type": "object", - "properties": { - "content": { - "type": "string" + "ReceiptRequest" : { + "type" : "object", + "properties" : { + "content" : { + "type" : "string" } } } }, - "securitySchemes": { - "ApiKey": { - "description": "The API key to access this function app.", - "in": "header", - "name": "Ocp-Apim-Subscription-Key", - "type": "apiKey" + "securitySchemes" : { + "ApiKey" : { + "description" : "The API key to access this function app.", + "in" : "header", + "name" : "Ocp-Apim-Subscription-Key", + "type" : "apiKey" } } } -} +} \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/wispconverter/service/DebtPositionService.java b/src/main/java/it/gov/pagopa/wispconverter/service/DebtPositionService.java index dd240c76..4375ea2a 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/service/DebtPositionService.java +++ b/src/main/java/it/gov/pagopa/wispconverter/service/DebtPositionService.java @@ -3,7 +3,12 @@ import it.gov.pagopa.gen.wispconverter.client.cache.model.ServiceDto; import it.gov.pagopa.gen.wispconverter.client.cache.model.StationDto; import it.gov.pagopa.gen.wispconverter.client.gpd.api.DebtPositionsApiApi; -import it.gov.pagopa.gen.wispconverter.client.gpd.model.*; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.MultiplePaymentPositionModelDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.PaymentOptionModelDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.PaymentPositionModelBaseResponseDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.PaymentPositionModelDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.TransferMetadataModelDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.TransferModelDto; import it.gov.pagopa.gen.wispconverter.client.iuvgenerator.api.GenerationApi; import it.gov.pagopa.gen.wispconverter.client.iuvgenerator.model.IUVGenerationResponseDto; import it.gov.pagopa.wispconverter.exception.AppErrorCodeMessageEnum; @@ -64,6 +69,8 @@ public class DebtPositionService { private final Pattern taxonomyPattern = Pattern.compile("([^/]++/[^/]++)/?"); + private static final String REST_CLIENT_LOG_STRING = "RestClientException ERROR [%s] - %s"; + @Value("${wisp-converter.poste-italiane.abi-code}") private String posteItalianeABICode; @@ -439,7 +446,7 @@ private void handleValidPaymentPosition(DebtPositionsApiApi gpdClientInstance, S generateREForUpdatedPaymentPosition(sessionData, iuv); } catch (RestClientException e) { - throw new AppException(AppErrorCodeMessageEnum.CLIENT_GPD, String.format("RestClientException ERROR [%s] - %s", e.getCause().getClass().getCanonicalName(), e.getMessage())); + throw new AppException(AppErrorCodeMessageEnum.CLIENT_GPD, String.format(REST_CLIENT_LOG_STRING, e.getCause().getClass().getCanonicalName(), e.getMessage())); } } @@ -534,7 +541,7 @@ private String generateNavCodeFromIuvGenerator(String creditorInstitutionId) { } catch (RestClientException e) { throw new AppException(AppErrorCodeMessageEnum.CLIENT_IUVGENERATOR, - String.format("RestClientException ERROR [%s] - %s", e.getCause().getClass().getCanonicalName(), e.getMessage())); + String.format(REST_CLIENT_LOG_STRING, e.getCause().getClass().getCanonicalName(), e.getMessage())); } return navCode; } @@ -559,7 +566,7 @@ private void handlePaymentPositionInsertion(DebtPositionsApiApi gpdClientInstanc generateREForBulkInsert(extractedPaymentPositions); } catch (RestClientException e) { - throw new AppException(AppErrorCodeMessageEnum.CLIENT_GPD, String.format("RestClientException ERROR [%s] - %s", e.getCause().getClass().getCanonicalName(), e.getMessage())); + throw new AppException(AppErrorCodeMessageEnum.CLIENT_GPD, String.format(REST_CLIENT_LOG_STRING, e.getCause().getClass().getCanonicalName(), e.getMessage())); } } } diff --git a/src/main/java/it/gov/pagopa/wispconverter/service/ReceiptService.java b/src/main/java/it/gov/pagopa/wispconverter/service/ReceiptService.java index 8d42b738..8da0c66e 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/service/ReceiptService.java +++ b/src/main/java/it/gov/pagopa/wispconverter/service/ReceiptService.java @@ -153,7 +153,6 @@ public void paaInviaRTOk(String payload) { gov.telematici.pagamenti.ws.papernodo.ObjectFactory objectFactory = new gov.telematici.pagamenti.ws.papernodo.ObjectFactory(); sessionData.getAllRPTs().forEach(rpt -> { - Instant now = Instant.now(); PaymentServiceProviderDto psp = psps.get(rpt.getRpt().getPayeeInstitution().getSubjectUniqueIdentifier().getCode()); IntestazionePPT intestazionePPT = generateIntestazionePPT( diff --git a/src/main/java/it/gov/pagopa/wispconverter/servicebus/RTConsumer.java b/src/main/java/it/gov/pagopa/wispconverter/servicebus/RTConsumer.java index 4528a1cb..04dedc2c 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/servicebus/RTConsumer.java +++ b/src/main/java/it/gov/pagopa/wispconverter/servicebus/RTConsumer.java @@ -59,8 +59,8 @@ public void post(){ .connectionString(connectionString) .processor() .queueName(queueName) - .processMessage(context -> processMessage(context)) - .processError(context -> processError(context)) + .processMessage(this::processMessage) + .processError(this::processError) .buildProcessorClient(); } @@ -99,7 +99,7 @@ public void processMessage(ServiceBusReceivedMessageContext context) { null ); - Boolean ok = false; + boolean ok = false; try{ log.debug("[{}]Sending receipt",receiptId); paaInviaRTService.send(url,receipt.getPayload()); @@ -157,4 +157,4 @@ public void processError(ServiceBusErrorContext context) { reason, context.getException().toString()); } } -} \ No newline at end of file +} diff --git a/src/main/java/it/gov/pagopa/wispconverter/util/client/AbstractAppClientLoggingInterceptor.java b/src/main/java/it/gov/pagopa/wispconverter/util/client/AbstractAppClientLoggingInterceptor.java index bd3c30de..5ab67591 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/util/client/AbstractAppClientLoggingInterceptor.java +++ b/src/main/java/it/gov/pagopa/wispconverter/util/client/AbstractAppClientLoggingInterceptor.java @@ -52,7 +52,7 @@ public abstract class AbstractAppClientLoggingInterceptor implements ClientHttpR private boolean responsePretty; private boolean mustPersistEventOnRE; - public AbstractAppClientLoggingInterceptor(RequestResponseLoggingProperties clientLoggingProperties, ReService reService, ClientServiceEnum clientServiceEnum) { + protected AbstractAppClientLoggingInterceptor(RequestResponseLoggingProperties clientLoggingProperties, ReService reService, ClientServiceEnum clientServiceEnum) { this.reService = reService; this.clientServiceEnum = clientServiceEnum; this.mustPersistEventOnRE = true; diff --git a/src/main/java/it/gov/pagopa/wispconverter/util/interceptor/AbstractAppServerLoggingInterceptor.java b/src/main/java/it/gov/pagopa/wispconverter/util/interceptor/AbstractAppServerLoggingInterceptor.java index eb1c01ce..affc648c 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/util/interceptor/AbstractAppServerLoggingInterceptor.java +++ b/src/main/java/it/gov/pagopa/wispconverter/util/interceptor/AbstractAppServerLoggingInterceptor.java @@ -367,10 +367,12 @@ private void handleMDCSessionContent(HttpServletRequest request, Trace trace) { String queryString = request.getQueryString(); - // include sessionID in MDC - Matcher sessionIdMatcher = this.sessionIdPattern.matcher(queryString); - if (sessionIdMatcher.find()) { - MDC.put(Constants.MDC_SESSION_ID, sessionIdMatcher.group(1)); + if(queryString != null) { + // include sessionID in MDC + Matcher sessionIdMatcher = this.sessionIdPattern.matcher(queryString); + if (sessionIdMatcher.find()) { + MDC.put(Constants.MDC_SESSION_ID, sessionIdMatcher.group(1)); + } } } } diff --git a/src/test/java/it/gov/pagopa/wispconverter/HomeTest.java b/src/test/java/it/gov/pagopa/wispconverter/HomeTest.java index 41a8db09..9798b749 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/HomeTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/HomeTest.java @@ -21,8 +21,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import static org.junit.jupiter.api.Assertions.*; - @ActiveProfiles(profiles = "test") @SpringBootTest(classes = Application.class) @AutoConfigureMockMvc @@ -61,7 +59,7 @@ void slash() throws Exception { void info() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/info").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); final String content = result.getResponse().getContentAsString(); diff --git a/src/test/java/it/gov/pagopa/wispconverter/OpenApiGenerationTest.java b/src/test/java/it/gov/pagopa/wispconverter/OpenApiGenerationTest.java index d66832f4..ba5e4b44 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/OpenApiGenerationTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/OpenApiGenerationTest.java @@ -59,7 +59,7 @@ void swaggerSpringPlugin() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); final String content = result.getResponse().getContentAsString(); diff --git a/src/test/java/it/gov/pagopa/wispconverter/ConsumerTest.java b/src/test/java/it/gov/pagopa/wispconverter/consumer/ConsumerTest.java similarity index 95% rename from src/test/java/it/gov/pagopa/wispconverter/ConsumerTest.java rename to src/test/java/it/gov/pagopa/wispconverter/consumer/ConsumerTest.java index ae8cd4bd..b97567ee 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/ConsumerTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/consumer/ConsumerTest.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.consumer; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -25,7 +25,7 @@ class ConsumerTest { @Test - void ok() throws Exception { + void ok() { ServiceBusReceivedMessageContext messageContext = mock(ServiceBusReceivedMessageContext.class); ServiceBusReceivedMessage message = mock(ServiceBusReceivedMessage.class); @@ -54,7 +54,7 @@ void ok() throws Exception { } @Test - void moreThanMax() throws Exception { + void moreThanMax() { ServiceBusReceivedMessageContext messageContext = mock(ServiceBusReceivedMessageContext.class); ServiceBusReceivedMessage message = mock(ServiceBusReceivedMessage.class); @@ -84,7 +84,7 @@ void moreThanMax() throws Exception { } @Test - void koSendToPa() throws Exception { + void koSendToPa() { ServiceBusSenderClient serviceBusSenderClient = mock(ServiceBusSenderClient.class); @@ -114,13 +114,13 @@ void koSendToPa() throws Exception { rtConsumer.processMessage(messageContext); - assertEquals(receipt.getRetry(),1); + assertEquals(1,receipt.getRetry()); verify(rtRequestRepository,times(1)).save(receipt); verify(serviceBusSenderClient,times(1)).sendMessage(any()); } @Test - public void testprocesserror(){ + void testprocesserror(){ ServiceBusErrorContext serviceBusErrorContext = mock(ServiceBusErrorContext.class); when(serviceBusErrorContext.getException()) .thenReturn(new ServiceBusException(new RuntimeException(),ServiceBusErrorSource.UNKNOWN)); @@ -129,7 +129,7 @@ public void testprocesserror(){ assertTrue(true); } @Test - public void testprocesserror2(){ + void testprocesserror2(){ ServiceBusErrorContext serviceBusErrorContext = mock(ServiceBusErrorContext.class); when(serviceBusErrorContext.getException()) .thenReturn(new ServiceBusException(new AmqpException(true, AmqpErrorCondition.MESSAGE_LOCK_LOST,"",null),ServiceBusErrorSource.UNKNOWN)); @@ -138,7 +138,7 @@ public void testprocesserror2(){ assertTrue(true); } @Test - public void testprocesserror3(){ + void testprocesserror3(){ ServiceBusErrorContext serviceBusErrorContext = mock(ServiceBusErrorContext.class); when(serviceBusErrorContext.getException()) .thenReturn(new ServiceBusException(new AmqpException(true, AmqpErrorCondition.UNAUTHORIZED_ACCESS,"",null),ServiceBusErrorSource.UNKNOWN)); @@ -147,7 +147,7 @@ public void testprocesserror3(){ assertTrue(true); } @Test - public void testprocesserror4(){ + void testprocesserror4(){ ServiceBusErrorContext serviceBusErrorContext = mock(ServiceBusErrorContext.class); when(serviceBusErrorContext.getException()) .thenReturn(new ServiceBusException(new AmqpException(true, AmqpErrorCondition.SERVER_BUSY_ERROR,"",null),ServiceBusErrorSource.UNKNOWN)); @@ -156,7 +156,7 @@ public void testprocesserror4(){ assertTrue(true); } @Test - public void testprocesserror5(){ + void testprocesserror5(){ ServiceBusErrorContext serviceBusErrorContext = mock(ServiceBusErrorContext.class); when(serviceBusErrorContext.getException()) .thenReturn( diff --git a/src/test/java/it/gov/pagopa/wispconverter/CarrelloTest.java b/src/test/java/it/gov/pagopa/wispconverter/endpoint/CarrelloTest.java similarity index 68% rename from src/test/java/it/gov/pagopa/wispconverter/CarrelloTest.java rename to src/test/java/it/gov/pagopa/wispconverter/endpoint/CarrelloTest.java index 4f122c49..686cf2b9 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/CarrelloTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/endpoint/CarrelloTest.java @@ -1,7 +1,7 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.endpoint; -import static it.gov.pagopa.wispconverter.ConstantsTestHelper.REDIRECT_PATH; -import static it.gov.pagopa.wispconverter.exception.AppErrorCodeMessageEnum.VALIDATION_INVALID_MULTIBENEFICIARY_CART; +import static it.gov.pagopa.wispconverter.utils.ConstantsTestHelper.REDIRECT_PATH; +import static it.gov.pagopa.wispconverter.utils.TestUtils.getPaymentPositionModelDto; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -10,13 +10,18 @@ import com.azure.messaging.servicebus.ServiceBusSenderClient; import com.fasterxml.jackson.databind.ObjectMapper; import it.gov.pagopa.gen.wispconverter.client.iuvgenerator.model.IUVGenerationResponseDto; +import it.gov.pagopa.wispconverter.Application; import it.gov.pagopa.wispconverter.repository.RPTRequestRepository; import it.gov.pagopa.wispconverter.repository.RTRequestRepository; import it.gov.pagopa.wispconverter.repository.ReEventRepository; import it.gov.pagopa.wispconverter.repository.model.RPTRequestEntity; import it.gov.pagopa.wispconverter.service.ConfigCacheService; import it.gov.pagopa.wispconverter.utils.TestUtils; + +import java.net.URI; import java.util.*; + +import org.junit.Assert; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -68,12 +73,14 @@ void success() throws Exception { org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); HttpHeaders headers = new HttpHeaders(); headers.add("location","locationheader"); - TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).build()); - + it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto cartResponseDto = new it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto(); + cartResponseDto.setCheckoutRedirectUrl(URI.create("http://www.google.com")); + TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).body(cartResponseDto)); it.gov.pagopa.gen.wispconverter.client.iuvgenerator.model.IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); + TestUtils.setMockGetExceptionNotFound(gpdClient); + TestUtils.setMockPost(gpdClient,ResponseEntity.ok().body(getPaymentPositionModelDto())); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( @@ -90,73 +97,34 @@ void success() throws Exception { mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) + .andExpect(MockMvcResultMatchers.status().is(HttpStatus.FOUND.value())) .andDo( - (result) -> { - assertNotNull(result); - assertNotNull(result.getResponse()); + result -> { + Assert.assertNotNull(result); + Assert.assertNotNull(result.getResponse()); }); verify(checkoutClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); verify(iuveneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(decouplerCachingClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - } - - @Test - void success_multibeneficiario() throws Exception { - String station = "mystation"; - org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); - HttpHeaders headers = new HttpHeaders(); - headers.add("location","locationheader"); - TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).build()); - - IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); - iuvGenerationModelResponseDto.setIuv("00000000"); - TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); - TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); - when(rptRequestRepository.findById(any())).thenReturn( - Optional.of( - RPTRequestEntity.builder().primitive("nodoInviaCarrelloRPT") - .payload( - TestUtils.zipAndEncode(TestUtils.getCarrelloPayload(2,station, - "100.00",true - )) - ).build() - ) - ); - when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); - - - - mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) - .andDo( - (result) -> { - assertNotNull(result); - assertNotNull(result.getResponse()); - }); - - verify(checkoutClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(iuveneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(2)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); verify(decouplerCachingClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); } @Test void fail_multibeneficiario_less_rpts() throws Exception { String station = "mystation"; - TestUtils.setMock(cacheClient,ResponseEntity.ok().body(TestUtils.configData(station))); - org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configCacheClient",cacheClient); + + org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); HttpHeaders headers = new HttpHeaders(); headers.add("location","locationheader"); - TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).build()); - - IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); + it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto cartResponseDto = new it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto(); + cartResponseDto.setCheckoutRedirectUrl(URI.create("http://www.google.com")); + TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).body(cartResponseDto)); + it.gov.pagopa.gen.wispconverter.client.iuvgenerator.model.IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); + TestUtils.setMockGetExceptionNotFound(gpdClient); + TestUtils.setMockPost(gpdClient,ResponseEntity.ok().body(getPaymentPositionModelDto())); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( @@ -176,7 +144,7 @@ void fail_multibeneficiario_less_rpts() throws Exception { mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); assertTrue(result.getResponse().getContentAsString().contains("Riprova, oppure contatta l'assistenza")); diff --git a/src/test/java/it/gov/pagopa/wispconverter/ReceiptTest.java b/src/test/java/it/gov/pagopa/wispconverter/endpoint/ReceiptTest.java similarity index 81% rename from src/test/java/it/gov/pagopa/wispconverter/ReceiptTest.java rename to src/test/java/it/gov/pagopa/wispconverter/endpoint/ReceiptTest.java index 77de6e55..30636ab1 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/ReceiptTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/endpoint/ReceiptTest.java @@ -1,14 +1,13 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.endpoint; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import com.azure.cosmos.CosmosClientBuilder; import com.azure.messaging.servicebus.ServiceBusSenderClient; import com.fasterxml.jackson.databind.ObjectMapper; -import gov.telematici.pagamenti.ws.papernodo.PaaInviaRTRisposta; +import it.gov.pagopa.wispconverter.Application; import it.gov.pagopa.wispconverter.controller.model.ReceiptRequest; import it.gov.pagopa.wispconverter.exception.PaaInviaRTException; import it.gov.pagopa.wispconverter.repository.CacheRepository; @@ -21,13 +20,9 @@ import it.gov.pagopa.wispconverter.service.PaaInviaRTServiceBusService; import it.gov.pagopa.wispconverter.service.model.ReceiptDto; import it.gov.pagopa.wispconverter.utils.TestUtils; -import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.util.Optional; import java.util.UUID; -import java.util.zip.GZIPOutputStream; import org.junit.jupiter.api.Test; -import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -84,29 +79,21 @@ private String getPaSendRTPayload(){ return pasendrtv2; } - private byte[] zip(byte[] uncompressed) throws IOException { - ByteArrayOutputStream bais = new ByteArrayOutputStream(); - GZIPOutputStream gzipOutputStream = new GZIPOutputStream(bais); - gzipOutputStream.write(uncompressed); - gzipOutputStream.close(); - bais.close(); - return bais.toByteArray(); - } - @Test void success_positive() throws Exception { String station = "mystation"; org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); - when(rptRequestRepository.findById(any())).thenReturn( + + when(rptRequestRepository.findById(anyString())).thenReturn( Optional.of( - RPTRequestEntity.builder().primitive("nodoInviaRPT") - .payload( - TestUtils.zipAndEncode(TestUtils.getRptPayload(false,station,"100.00","datispec")) - ).build() + RPTRequestEntity.builder() + .primitive("nodoInviaRPT") + .payload(TestUtils.zipAndEncode(TestUtils.getRptPayload(false,station,"100.00","datispec"))) + .build() ) ); - when(cacheRepository.read(any(),any())).thenReturn("asdsad"); + when(cacheRepository.read(anyString(),any())).thenReturn("wisp_nav2iuv_dominio"); mvc.perform(MockMvcRequestBuilders.post("/receipt/ok") .accept(MediaType.APPLICATION_JSON) @@ -114,13 +101,11 @@ void success_positive() throws Exception { .content(objectMapper.writeValueAsString(new ReceiptRequest(getPaSendRTPayload())))) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }); - - verify(reEventRepository,times(5)).save(any()); } @Test @@ -128,12 +113,13 @@ void success_negative() throws Exception { String station = "mystation"; org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); - when(rptRequestRepository.findById(any())).thenReturn(Optional.of(RPTRequestEntity - .builder() + when(rptRequestRepository.findById(any())) + .thenReturn(Optional.of(RPTRequestEntity.builder() .id(UUID.randomUUID().toString()) .primitive("nodoInviaRPT") .payload(TestUtils.zipAndEncode(TestUtils.getRptPayload(false,"mystation","10.00","dati"))) - .build())); + .build() + )); when(cacheRepository.read(any(),any())).thenReturn("wisp_nav2iuv_dominio"); ReceiptDto[] receiptDtos = { @@ -145,12 +131,10 @@ void success_negative() throws Exception { .content(objectMapper.writeValueAsString(new ReceiptRequest(objectMapper.writeValueAsString(receiptDtos))))) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }); - - verify(reEventRepository,times(5)).save(any()); } @Test @@ -166,8 +150,8 @@ void error_send_rt() throws Exception { ).build() ) ); - when(cacheRepository.read(any(),any())).thenReturn("asdsad"); - doThrow(new PaaInviaRTException("PAA_ERRORE_RESPONSE","PAA_ERRORE_RESPONSE","Errore PA")).doNothing().when(paaInviaRTService).send(anyString(), anyString()); + when(cacheRepository.read(any(),any())).thenReturn("wisp_nav2iuv_dominio"); + doThrow(new PaaInviaRTException("PAA_ERRORE_RESPONSE","PAA_ERRORE_RESPONSE","Errore PA")).when(paaInviaRTService).send(anyString(), anyString()); mvc.perform(MockMvcRequestBuilders.post("/receipt/ok") .accept(MediaType.APPLICATION_JSON) @@ -175,13 +159,12 @@ void error_send_rt() throws Exception { .content(objectMapper.writeValueAsString(new ReceiptRequest(getPaSendRTPayload())))) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }); verify(paaInviaRTService, times(1)).send(anyString(), anyString()); - verify(reEventRepository,times(6)).save(any()); } @Test @@ -197,23 +180,20 @@ void error_send_rt2() throws Exception { ).build() ) ); - when(cacheRepository.read(any(),any())).thenReturn("asdsad"); - doAnswer((i) -> { - return new ResponseEntity<>(HttpStatusCode.valueOf(200)); - }).when(paaInviaRTService).send(anyString(), anyString()); + when(cacheRepository.read(any(),any())).thenReturn("wisp_nav2iuv_dominio"); + doAnswer(i -> new ResponseEntity<>(HttpStatusCode.valueOf(200))).when(paaInviaRTService).send(anyString(), anyString()); mvc.perform(MockMvcRequestBuilders.post("/receipt/ok") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(new ReceiptRequest(getPaSendRTPayload())))) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }); verify(paaInviaRTService, times(1)).send(anyString(), anyString()); - verify(reEventRepository,times(5)).save(any()); } } diff --git a/src/test/java/it/gov/pagopa/wispconverter/RptTest.java b/src/test/java/it/gov/pagopa/wispconverter/endpoint/RptTest.java similarity index 57% rename from src/test/java/it/gov/pagopa/wispconverter/RptTest.java rename to src/test/java/it/gov/pagopa/wispconverter/endpoint/RptTest.java index c00324af..54b7b6cb 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/RptTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/endpoint/RptTest.java @@ -1,13 +1,18 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.endpoint; -import static it.gov.pagopa.wispconverter.ConstantsTestHelper.REDIRECT_PATH; +import static it.gov.pagopa.wispconverter.utils.ConstantsTestHelper.REDIRECT_PATH; +import static it.gov.pagopa.wispconverter.utils.TestUtils.*; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import com.azure.messaging.servicebus.ServiceBusSenderClient; import com.fasterxml.jackson.databind.ObjectMapper; +import it.gov.pagopa.gen.wispconverter.client.cache.model.StationCreditorInstitutionDto; import it.gov.pagopa.gen.wispconverter.client.iuvgenerator.model.IUVGenerationResponseDto; import it.gov.pagopa.gen.wispconverter.client.gpd.model.MultiplePaymentPositionModelDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.PaymentPositionModelDto; +import it.gov.pagopa.wispconverter.Application; +import it.gov.pagopa.wispconverter.repository.CacheRepository; import it.gov.pagopa.wispconverter.repository.RPTRequestRepository; import it.gov.pagopa.wispconverter.repository.RTRequestRepository; import it.gov.pagopa.wispconverter.repository.ReEventRepository; @@ -54,7 +59,7 @@ class RptTest { @MockBean private RTRequestRepository rtRequestRepository; - @MockBean private it.gov.pagopa.gen.wispconverter.client.iuvgenerator.invoker.ApiClient iuveneratorClient; + @MockBean private it.gov.pagopa.gen.wispconverter.client.iuvgenerator.invoker.ApiClient iuvGeneratorClient; @MockBean private it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient gpdClient; @MockBean private it.gov.pagopa.gen.wispconverter.client.checkout.invoker.ApiClient checkoutClient; @MockBean private it.gov.pagopa.gen.wispconverter.client.cache.invoker.ApiClient cacheClient; @@ -65,21 +70,24 @@ class RptTest { private ReEventRepository reEventRepository; @MockBean private ServiceBusSenderClient serviceBusSenderClient; + @MockBean + private CacheRepository cacheRepository; @Test - void success() throws Exception { + void success_debtPositionUpdateValid() throws Exception { String station = "mystation"; - org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); + StationCreditorInstitutionDto stationCreditorInstitutionDto = new StationCreditorInstitutionDto(); + stationCreditorInstitutionDto.setCreditorInstitutionCode("{pa}"); + stationCreditorInstitutionDto.setSegregationCode(12L); + stationCreditorInstitutionDto.setStationCode(station); + org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configDataCreditorInstitutionStations(stationCreditorInstitutionDto)); HttpHeaders headers = new HttpHeaders(); headers.add("location","locationheader"); it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto cartResponseDto = new it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto(); cartResponseDto.setCheckoutRedirectUrl(URI.create("http://www.google.com")); TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).body(cartResponseDto)); - - it.gov.pagopa.gen.wispconverter.client.iuvgenerator.model.IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); - iuvGenerationModelResponseDto.setIuv("00000000"); - TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); + TestUtils.setMockGet(gpdClient,ResponseEntity.ok().body(getValidPaymentPositionModelBaseResponseDto())); + TestUtils.setMockPut(gpdClient,ResponseEntity.ok().body(getPaymentPositionModelDto())); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( @@ -94,39 +102,84 @@ void success() throws Exception { mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.FOUND.value())) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }); verify(checkoutClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(iuveneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(2)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); verify(decouplerCachingClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); ArgumentCaptor argument = ArgumentCaptor.forClass(Object.class); - verify(gpdClient).invokeAPI(any(),any(),any(),any(),argument.capture(),any(),any(),any(),any(),any(),any(),any()); - MultiplePaymentPositionModelDto value = (MultiplePaymentPositionModelDto) argument.getValue(); + verify(gpdClient, times(2)).invokeAPI(any(),any(),any(),any(),argument.capture(),any(),any(),any(),any(),any(),any(),any()); + MultiplePaymentPositionModelDto value = new MultiplePaymentPositionModelDto(); + value.setPaymentPositions(List.of((PaymentPositionModelDto) argument.getValue())); assertEquals(1, value.getPaymentPositions().size()); assertEquals("TTTTTT11T11T123T", value.getPaymentPositions().get(0).getFiscalCode()); ArgumentCaptor reevents = ArgumentCaptor.forClass(ReEventDto.class); - verify(reEventRepository,times(8)).save(any()); reevents.getAllValues(); } @Test - void success_tassonomia() throws Exception { + void success_debtPositionUpdateInvalid() throws Exception { + String station = "mystation"; + StationCreditorInstitutionDto stationCreditorInstitutionDto = new StationCreditorInstitutionDto(); + stationCreditorInstitutionDto.setCreditorInstitutionCode("{pa}"); + stationCreditorInstitutionDto.setSegregationCode(12L); + stationCreditorInstitutionDto.setStationCode(station); + org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configDataCreditorInstitutionStations(stationCreditorInstitutionDto)); + HttpHeaders headers = new HttpHeaders(); + headers.add("location","locationheader"); + it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto cartResponseDto = new it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto(); + cartResponseDto.setCheckoutRedirectUrl(URI.create("http://www.google.com")); + TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).body(cartResponseDto)); + TestUtils.setMockGet(gpdClient,ResponseEntity.ok().body(getInvalidPaymentPositionModelBaseResponseDto())); + TestUtils.setMockPut(gpdClient,ResponseEntity.ok().body(getPaymentPositionModelDto())); + TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); + when(rptRequestRepository.findById(any())) + .thenReturn(Optional.of( + RPTRequestEntity.builder() + .primitive("nodoInviaRPT") + .payload(TestUtils.zipAndEncode(TestUtils.getRptPayload(false,station,"100.00",null))) + .build() + ) + ); + when(cacheRepository.read(any(),any())).thenReturn("wisp_nav2iuv_dominio"); + when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); + + mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) + .andDo( + result -> { + assertNotNull(result); + assertNotNull(result.getResponse()); + }); + + verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(decouplerCachingClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + + ArgumentCaptor reevents = ArgumentCaptor.forClass(ReEventDto.class); + reevents.getAllValues(); + } + + @Test + void success_debtPositionCreate() throws Exception { String station = "mystation"; org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); HttpHeaders headers = new HttpHeaders(); headers.add("location","locationheader"); - TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).build()); + it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto cartResponseDto = new it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto(); + cartResponseDto.setCheckoutRedirectUrl(URI.create("http://www.google.com")); + TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).body(cartResponseDto)); IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); - iuvGenerationModelResponseDto.setIuv("00000000"); - TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); + iuvGenerationModelResponseDto.setIuv("123456IUVMOCK2"); + TestUtils.setMock(iuvGeneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); + TestUtils.setMockGetExceptionNotFound(gpdClient); + TestUtils.setMockPost(gpdClient,ResponseEntity.ok().body(getPaymentPositionModelDto())); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( @@ -138,19 +191,17 @@ void success_tassonomia() throws Exception { ); when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); - - mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) + .andExpect(MockMvcResultMatchers.status().is(HttpStatus.FOUND.value())) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }); verify(checkoutClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(iuveneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(iuvGeneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(2)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); verify(decouplerCachingClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); } @@ -160,12 +211,15 @@ void success_bollo() throws Exception { org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); HttpHeaders headers = new HttpHeaders(); headers.add("location","locationheader"); - TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).build()); + it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto cartResponseDto = new it.gov.pagopa.gen.wispconverter.client.checkout.model.CartResponseDto(); + cartResponseDto.setCheckoutRedirectUrl(URI.create("http://www.google.com")); + TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).body(cartResponseDto)); IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); - TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); + TestUtils.setMock(iuvGeneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); + TestUtils.setMockGetExceptionNotFound(gpdClient); + TestUtils.setMockPost(gpdClient,ResponseEntity.ok().body(getPaymentPositionModelDto())); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( @@ -177,24 +231,37 @@ void success_bollo() throws Exception { ); when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); - - mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) + .andExpect(MockMvcResultMatchers.status().is(HttpStatus.FOUND.value())) .andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }); verify(checkoutClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(iuveneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(iuvGeneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(2)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); verify(decouplerCachingClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); } @Test - void fail_rpt_not_exists() throws Exception { + void fail_rptNotFound() throws Exception { + MvcResult resultActions = mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo( + result -> { + assertNotNull(result); + assertNotNull(result.getResponse()); + }).andReturn(); + assertEquals("text/html;charset=UTF-8",resultActions.getResponse().getContentType()); + String contentAsString = resultActions.getResponse().getContentAsString(); + assertTrue(contentAsString.contains("Riprova, oppure contatta l'assistenza")); + verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(decouplerCachingClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + } + @Test + void fail_iuvGeneratorError() throws Exception { String station = "mystation"; org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); HttpHeaders headers = new HttpHeaders(); @@ -204,24 +271,32 @@ void fail_rpt_not_exists() throws Exception { IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) - .when(iuveneratorClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); + .when(iuvGeneratorClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + TestUtils.setMockGetExceptionNotFound(gpdClient); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); - + when(rptRequestRepository.findById(any())).thenReturn( + Optional.of( + RPTRequestEntity.builder().primitive("nodoInviaRPT") + .payload( + TestUtils.zipAndEncode(TestUtils.getRptPayload(false,station,"100.00","datispec")) + ).build() + ) + ); MvcResult resultActions = mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }).andReturn(); assertEquals("text/html;charset=UTF-8",resultActions.getResponse().getContentType()); String contentAsString = resultActions.getResponse().getContentAsString(); assertTrue(contentAsString.contains("Riprova, oppure contatta l'assistenza")); - verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(iuvGeneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); verify(decouplerCachingClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); } @Test @@ -235,7 +310,7 @@ void fail_generic() throws Exception { IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) - .when(iuveneratorClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + .when(iuvGeneratorClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); @@ -243,7 +318,7 @@ void fail_generic() throws Exception { MvcResult resultActions = mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo( - (result) -> { + result -> { assertNotNull(result); assertNotNull(result.getResponse()); }).andReturn(); @@ -256,7 +331,7 @@ void fail_generic() throws Exception { } @Test - void fail_getNAVCodeFromIUVGenerator() throws Exception { + void fail_debtPositionCreate() throws Exception { String station = "mystation"; org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); HttpHeaders headers = new HttpHeaders(); @@ -265,9 +340,10 @@ void fail_getNAVCodeFromIUVGenerator() throws Exception { IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); + TestUtils.setMock(iuvGeneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); + TestUtils.setMockGetExceptionNotFound(gpdClient); doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) - .when(iuveneratorClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); + .when(gpdClient).parameterToMultiValueMap(any(),any(),any()); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( @@ -279,29 +355,27 @@ void fail_getNAVCodeFromIUVGenerator() throws Exception { ); when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); - mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()); - verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(iuvGeneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); verify(decouplerCachingClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); } @Test - void fail_createDebtPositions() throws Exception { + void fail_storeRequestMappingInCache() throws Exception { String station = "mystation"; org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); - HttpHeaders headers = new HttpHeaders(); - headers.add("location","locationheader"); - TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).build()); - IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); - iuvGenerationModelResponseDto.setIuv("00000000"); - TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); + iuvGenerationModelResponseDto.setIuv("123456IUVMOCK2"); + TestUtils.setMock(iuvGeneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); + TestUtils.setMockGetExceptionNotFound(gpdClient); + TestUtils.setMockPost(gpdClient,ResponseEntity.ok().body(getPaymentPositionModelDto())); doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) - .when(gpdClient).parameterToMultiValueMap(any(),any(),any()); - TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); + .when(decouplerCachingClient) + .invokeAPI(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( RPTRequestEntity.builder().primitive("nodoInviaRPT") @@ -310,35 +384,28 @@ void fail_createDebtPositions() throws Exception { ).build() ) ); - when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); - - mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()); - verify(iuveneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(decouplerCachingClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(iuvGeneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(2)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); } + @Test - void fail_storeRequestMappingInCache() throws Exception { + void fail_checkoutRequest() throws Exception { String station = "mystation"; org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); - HttpHeaders headers = new HttpHeaders(); - headers.add("location","locationheader"); - TestUtils.setMock(checkoutClient, ResponseEntity.status(HttpStatus.FOUND).headers(headers).build()); - + doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) + .when(checkoutClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); - TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); - doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) - .when(decouplerCachingClient) - .invokeAPI( - any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); + TestUtils.setMock(iuvGeneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); + TestUtils.setMockGetExceptionNotFound(gpdClient); + TestUtils.setMockPost(gpdClient,ResponseEntity.ok().body(getPaymentPositionModelDto())); + TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( RPTRequestEntity.builder().primitive("nodoInviaRPT") @@ -352,46 +419,102 @@ void fail_storeRequestMappingInCache() throws Exception { mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()); - verify(iuveneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - + verify(iuvGeneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(2)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(decouplerCachingClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(checkoutClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); } + @Test + void fail_ibanNullValue() throws Exception { + String station = "mystation"; + org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); + when(rptRequestRepository.findById(any())).thenReturn( + Optional.of( + RPTRequestEntity.builder().primitive("nodoInviaRPT") + .payload( + TestUtils.zipAndEncode(TestUtils.getRptNullIbanPayload(station,"100.00","datispec")) + ).build() + ) + ); + when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); + + MvcResult resultActions = mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo( + result -> { + assertNotNull(result); + assertNotNull(result.getResponse()); + }).andReturn(); + assertEquals("text/html;charset=UTF-8",resultActions.getResponse().getContentType()); + String contentAsString = resultActions.getResponse().getContentAsString(); + assertTrue(contentAsString.contains("Riprova, oppure contatta l'assistenza")); + + verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(iuvGeneratorClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(decouplerCachingClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + } @Test - void fail_checkout() throws Exception { + void fail_nullDebtPosition() throws Exception { String station = "mystation"; org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); - HttpHeaders headers = new HttpHeaders(); - headers.add("location","locationheader"); - doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) - .when(checkoutClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - IUVGenerationResponseDto iuvGenerationModelResponseDto = new IUVGenerationResponseDto(); - iuvGenerationModelResponseDto.setIuv("00000000"); - TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); - TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); + TestUtils.setMock(gpdClient, ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( RPTRequestEntity.builder().primitive("nodoInviaRPT") .payload( - TestUtils.zipAndEncode(TestUtils.getRptPayload(false,station,"100.00",null)) + TestUtils.zipAndEncode(TestUtils.getRptPayload(false,station,"100.00","datispec")) ).build() ) ); when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); + MvcResult resultActions = mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo( + result -> { + assertNotNull(result); + assertNotNull(result.getResponse()); + }).andReturn(); + assertEquals("text/html;charset=UTF-8",resultActions.getResponse().getContentType()); + String contentAsString = resultActions.getResponse().getContentAsString(); + assertTrue(contentAsString.contains("Riprova, oppure contatta l'assistenza")); + verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(iuvGeneratorClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(decouplerCachingClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + } - mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()); + @Test + void fail_debtPositionBadRequest() throws Exception { + String station = "mystation"; + org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); + TestUtils.setMockGetExceptionBadRequest(gpdClient); + when(rptRequestRepository.findById(any())).thenReturn( + Optional.of( + RPTRequestEntity.builder().primitive("nodoInviaRPT") + .payload( + TestUtils.zipAndEncode(TestUtils.getRptPayload(false,station,"100.00","datispec")) + ).build() + ) + ); + when(redisSimpleTemplate.opsForValue()).thenReturn(mock(ValueOperations.class)); - verify(iuveneratorClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); - verify(decouplerCachingClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + MvcResult resultActions = mvc.perform(MockMvcRequestBuilders.get(REDIRECT_PATH + "?sessionId=aaaaaaaaaaaa").accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo( + result -> { + assertNotNull(result); + assertNotNull(result.getResponse()); + }).andReturn(); + assertEquals("text/html;charset=UTF-8",resultActions.getResponse().getContentType()); + String contentAsString = resultActions.getResponse().getContentAsString(); + assertTrue(contentAsString.contains("Riprova, oppure contatta l'assistenza")); + verify(checkoutClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(iuvGeneratorClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(gpdClient,times(1)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + verify(decouplerCachingClient,times(0)).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); } - } diff --git a/src/test/java/it/gov/pagopa/wispconverter/PaaInviaRTServiceTest.java b/src/test/java/it/gov/pagopa/wispconverter/service/PaaInviaRTServiceTest.java similarity index 94% rename from src/test/java/it/gov/pagopa/wispconverter/PaaInviaRTServiceTest.java rename to src/test/java/it/gov/pagopa/wispconverter/service/PaaInviaRTServiceTest.java index 975acec7..fd8fd769 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/PaaInviaRTServiceTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/service/PaaInviaRTServiceTest.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.service; import gov.telematici.pagamenti.ws.papernodo.EsitoPaaInviaRT; import gov.telematici.pagamenti.ws.papernodo.FaultBean; @@ -17,10 +17,10 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class PaaInviaRTServiceTest { +class PaaInviaRTServiceTest { @Test - public void esitoOK(){ + void esitoOK(){ RestClient.Builder builder = mock(RestClient.Builder.class); RestClient client = mock(RestClient.class); when(builder.build()).thenReturn(client); @@ -28,6 +28,7 @@ public void esitoOK(){ when(client.post()).thenReturn(requestBodyUriSpec); RestClient.RequestBodySpec requestBodySpec = mock(RestClient.RequestBodySpec.class); when(requestBodyUriSpec.uri(any(URI.class))).thenReturn(requestBodySpec); + when(requestBodySpec.header(anyString(), anyString())).thenReturn(requestBodySpec); when(requestBodySpec.body(anyString())).thenReturn(requestBodySpec); RestClient.ResponseSpec responseSpec = mock(RestClient.ResponseSpec.class); @@ -46,7 +47,7 @@ public void esitoOK(){ } @Test - public void esitoKO(){ + void esitoKO(){ RestClient.Builder builder = mock(RestClient.Builder.class); RestClient client = mock(RestClient.class); when(builder.build()).thenReturn(client); diff --git a/src/test/java/it/gov/pagopa/wispconverter/BaseTest.java b/src/test/java/it/gov/pagopa/wispconverter/utility/BaseTest.java similarity index 99% rename from src/test/java/it/gov/pagopa/wispconverter/BaseTest.java rename to src/test/java/it/gov/pagopa/wispconverter/utility/BaseTest.java index 07149cb0..7a44d653 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/BaseTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/utility/BaseTest.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.utility; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/src/test/java/it/gov/pagopa/wispconverter/LoggingTest.java b/src/test/java/it/gov/pagopa/wispconverter/utility/LoggingTest.java similarity index 99% rename from src/test/java/it/gov/pagopa/wispconverter/LoggingTest.java rename to src/test/java/it/gov/pagopa/wispconverter/utility/LoggingTest.java index 00ad4c49..d228ffcd 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/LoggingTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/utility/LoggingTest.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.utility; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; diff --git a/src/test/java/it/gov/pagopa/wispconverter/XmlUtilTest.java b/src/test/java/it/gov/pagopa/wispconverter/utility/XmlUtilTest.java similarity index 93% rename from src/test/java/it/gov/pagopa/wispconverter/XmlUtilTest.java rename to src/test/java/it/gov/pagopa/wispconverter/utility/XmlUtilTest.java index b05a3866..63906524 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/XmlUtilTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/utility/XmlUtilTest.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.utility; import it.gov.pagopa.wispconverter.util.XmlUtil; import org.junit.Test; diff --git a/src/test/java/it/gov/pagopa/wispconverter/ZipUtilTest.java b/src/test/java/it/gov/pagopa/wispconverter/utility/ZipUtilTest.java similarity index 73% rename from src/test/java/it/gov/pagopa/wispconverter/ZipUtilTest.java rename to src/test/java/it/gov/pagopa/wispconverter/utility/ZipUtilTest.java index 9fcf2082..9b8289ab 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/ZipUtilTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/utility/ZipUtilTest.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.utility; import it.gov.pagopa.wispconverter.util.ZipUtil; import org.junit.jupiter.api.Test; @@ -8,20 +8,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class ZipUtilTest { +class ZipUtilTest { private static final String XML_STRING = ""; @Test - public void zip() throws IOException { + void zip() throws IOException { byte[] byteString = ZipUtil.zip(XML_STRING); byte[] unzip = ZipUtil.unzip(byteString); - String utf8String = ZipUtil.getUtf8String(byteString); String utf8Unzip = ZipUtil.getUtf8String(unzip); assertNotEquals(byteString, unzip); assertEquals(XML_STRING, utf8Unzip); - String s = new String(byteString); -// assertEquals(XML_STRING, s); } } diff --git a/src/test/java/it/gov/pagopa/wispconverter/ConstantsTestHelper.java b/src/test/java/it/gov/pagopa/wispconverter/utils/ConstantsTestHelper.java similarity index 69% rename from src/test/java/it/gov/pagopa/wispconverter/ConstantsTestHelper.java rename to src/test/java/it/gov/pagopa/wispconverter/utils/ConstantsTestHelper.java index 3fc4ef03..61f5204e 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/ConstantsTestHelper.java +++ b/src/test/java/it/gov/pagopa/wispconverter/utils/ConstantsTestHelper.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.wispconverter; +package it.gov.pagopa.wispconverter.utils; public class ConstantsTestHelper { diff --git a/src/test/java/it/gov/pagopa/wispconverter/utils/TestUtils.java b/src/test/java/it/gov/pagopa/wispconverter/utils/TestUtils.java index 4e9bc9c8..90900f73 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/utils/TestUtils.java +++ b/src/test/java/it/gov/pagopa/wispconverter/utils/TestUtils.java @@ -1,10 +1,19 @@ package it.gov.pagopa.wispconverter.utils; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - import io.micrometer.core.instrument.util.IOUtils; +import it.gov.pagopa.gen.wispconverter.client.cache.model.ConnectionDto; +import it.gov.pagopa.gen.wispconverter.client.cache.model.ServiceDto; +import it.gov.pagopa.gen.wispconverter.client.cache.model.StationCreditorInstitutionDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.PaymentOptionModelDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.PaymentOptionModelResponseDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.PaymentPositionModelBaseResponseDto; +import it.gov.pagopa.gen.wispconverter.client.gpd.model.PaymentPositionModelDto; +import it.gov.pagopa.wispconverter.exception.AppErrorCodeMessageEnum; +import it.gov.pagopa.wispconverter.exception.AppException; +import org.springframework.http.*; +import org.springframework.web.client.HttpClientErrorException; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -12,13 +21,12 @@ import java.util.Arrays; import java.util.Base64; import java.util.HashMap; +import java.util.List; import java.util.zip.GZIPOutputStream; -import it.gov.pagopa.gen.wispconverter.client.cache.model.ConnectionDto; -import it.gov.pagopa.gen.wispconverter.client.cache.model.ServiceDto; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; public class TestUtils { @@ -33,21 +41,21 @@ public static String loadFileContent(String fileName) { return content; } - public static it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto configData(String stationCode){ + public static it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto configData(String stationCode) { it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto configDataV1 = new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto(); configDataV1.setStations(new HashMap<>()); it.gov.pagopa.gen.wispconverter.client.cache.model.StationDto station = new it.gov.pagopa.gen.wispconverter.client.cache.model.StationDto(); station.setStationCode(stationCode); - station.setConnection(new ConnectionDto()); - station.getConnection().setIp("127.0.0.1"); - station.getConnection().setPort(8888l); - station.getConnection().setProtocol(ConnectionDto.ProtocolEnum.HTTP); - station.setService(new ServiceDto()); - station.getService().setPath("/path"); + station.setConnection(new ConnectionDto()); + station.getConnection().setIp("127.0.0.1"); + station.getConnection().setPort(8888L); + station.getConnection().setProtocol(ConnectionDto.ProtocolEnum.HTTP); + station.setService(new ServiceDto()); + station.getService().setPath("/path"); station.setRedirect(new it.gov.pagopa.gen.wispconverter.client.cache.model.RedirectDto()); station.getRedirect().setIp("127.0.0.1"); station.getRedirect().setPath("/redirect"); - station.getRedirect().setPort(8888l); + station.getRedirect().setPort(8888L); station.getRedirect().setProtocol(it.gov.pagopa.gen.wispconverter.client.cache.model.RedirectDto.ProtocolEnum.HTTPS); station.getRedirect().setQueryString("param=1"); configDataV1.getStations().put(station.getStationCode(), station); @@ -67,86 +75,177 @@ public static it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto return configDataV1; } - public static void setMock(it.gov.pagopa.gen.wispconverter.client.decouplercaching.invoker.ApiClient client, ResponseEntity response){ - when(client.invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any())).thenReturn(response); - when(client.parameterToMultiValueMap(any(),any(),any())).thenReturn(new HttpHeaders()); + public static it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto configDataCreditorInstitutionStations + (StationCreditorInstitutionDto stationCreditorInstitutionDto) { + it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto configDataV1 = new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto(); + configDataV1.setCreditorInstitutionStations(new HashMap<>()); + configDataV1.getCreditorInstitutionStations().put(stationCreditorInstitutionDto.getCreditorInstitutionCode(), stationCreditorInstitutionDto); + configDataV1.setStations(new HashMap<>()); + it.gov.pagopa.gen.wispconverter.client.cache.model.StationDto station = new it.gov.pagopa.gen.wispconverter.client.cache.model.StationDto(); + station.setStationCode(stationCreditorInstitutionDto.getStationCode()); + station.setConnection(new ConnectionDto()); + station.getConnection().setIp("127.0.0.1"); + station.getConnection().setPort(8888L); + station.getConnection().setProtocol(ConnectionDto.ProtocolEnum.HTTP); + station.setService(new ServiceDto()); + station.getService().setPath("/path"); + station.setRedirect(new it.gov.pagopa.gen.wispconverter.client.cache.model.RedirectDto()); + station.getRedirect().setIp("127.0.0.1"); + station.getRedirect().setPath("/redirect"); + station.getRedirect().setPort(8888L); + station.getRedirect().setProtocol(it.gov.pagopa.gen.wispconverter.client.cache.model.RedirectDto.ProtocolEnum.HTTPS); + station.getRedirect().setQueryString("param=1"); + configDataV1.getStations().put(station.getStationCode(), station); + + configDataV1.setConfigurations(new HashMap<>()); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.identificativoUnivocoAttestante.tipoIdentificativoUnivoco", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("G")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.identificativoUnivocoAttestante.codiceIdentificativoUnivoco", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("codiceIdentificativoUnivoco")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.denominazioneAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("denominazioneAttestante")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.codiceUnitOperAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("codiceUnitOperAttestante")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.denomUnitOperAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("denomUnitOperAttestante")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.indirizzoAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("indirizzoAttestante")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.civicoAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("civicoAttestante")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.capAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("capAttestante")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.localitaAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("localitaAttestante")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.provinciaAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("provinciaAttestante")); + configDataV1.getConfigurations().put("GLOBAL-istitutoAttestante.nazioneAttestante", new it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigurationKeyDto().value("nazioneAttestante")); + return configDataV1; + } + + public static void setMock(it.gov.pagopa.gen.wispconverter.client.decouplercaching.invoker.ApiClient client, ResponseEntity response) { + when(client.invokeAPI(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(response); + when(client.parameterToMultiValueMap(any(), any(), any())).thenReturn(new HttpHeaders()); + when(client.parameterToString(any())).thenReturn(""); + when(client.selectHeaderAccept(any())).thenReturn(List.of()); + when(client.selectHeaderContentType(any())).thenReturn(MediaType.APPLICATION_JSON); + } + + public static void setMock(it.gov.pagopa.gen.wispconverter.client.cache.invoker.ApiClient client, ResponseEntity response) { + when(client.invokeAPI(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(response); + when(client.parameterToMultiValueMap(any(), any(), any())).thenReturn(new HttpHeaders()); when(client.parameterToString(any())).thenReturn(""); - when(client.selectHeaderAccept(any())).thenReturn(Arrays.asList()); + when(client.selectHeaderAccept(any())).thenReturn(List.of()); when(client.selectHeaderContentType(any())).thenReturn(MediaType.APPLICATION_JSON); } - public static void setMock(it.gov.pagopa.gen.wispconverter.client.cache.invoker.ApiClient client,ResponseEntity response){ - when(client.invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any())).thenReturn(response); - when(client.parameterToMultiValueMap(any(),any(),any())).thenReturn(new HttpHeaders()); + + public static void setMock(it.gov.pagopa.gen.wispconverter.client.iuvgenerator.invoker.ApiClient client, ResponseEntity response) { + when(client.invokeAPI(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(response); + when(client.parameterToMultiValueMap(any(), any(), any())).thenReturn(new HttpHeaders()); when(client.parameterToString(any())).thenReturn(""); - when(client.selectHeaderAccept(any())).thenReturn(Arrays.asList()); + when(client.selectHeaderAccept(any())).thenReturn(List.of()); when(client.selectHeaderContentType(any())).thenReturn(MediaType.APPLICATION_JSON); } - public static void setMock(it.gov.pagopa.gen.wispconverter.client.iuvgenerator.invoker.ApiClient client,ResponseEntity response){ - when(client.invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any())).thenReturn(response); - when(client.parameterToMultiValueMap(any(),any(),any())).thenReturn(new HttpHeaders()); + + public static void setMock(it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient client, ResponseEntity response) { + when(client.invokeAPI(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(response); + when(client.parameterToMultiValueMap(any(), any(), any())).thenReturn(new HttpHeaders()); when(client.parameterToString(any())).thenReturn(""); - when(client.selectHeaderAccept(any())).thenReturn(Arrays.asList()); + when(client.selectHeaderAccept(any())).thenReturn(List.of()); when(client.selectHeaderContentType(any())).thenReturn(MediaType.APPLICATION_JSON); } - public static void setMock(it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient client,ResponseEntity response){ - when(client.invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any())).thenReturn(response); - when(client.parameterToMultiValueMap(any(),any(),any())).thenReturn(new HttpHeaders()); + + public static void setMockGet(it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient client, ResponseEntity response) { + when(client.invokeAPI(any(), eq(HttpMethod.GET), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(response); + when(client.parameterToMultiValueMap(any(), any(), any())).thenReturn(new HttpHeaders()); when(client.parameterToString(any())).thenReturn(""); - when(client.selectHeaderAccept(any())).thenReturn(Arrays.asList()); + when(client.selectHeaderAccept(any())).thenReturn(List.of()); when(client.selectHeaderContentType(any())).thenReturn(MediaType.APPLICATION_JSON); } - public static void setMock(it.gov.pagopa.gen.wispconverter.client.checkout.invoker.ApiClient client,ResponseEntity response){ - when(client.invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any())).thenReturn(response); - when(client.parameterToMultiValueMap(any(),any(),any())).thenReturn(new HttpHeaders()); + + public static void setMockGetExceptionNotFound(it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient client) { + when(client.invokeAPI(any(), eq(HttpMethod.GET), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())) + .thenThrow(new AppException(new HttpClientErrorException(HttpStatus.NOT_FOUND), AppErrorCodeMessageEnum.CLIENT_GPD)); + } + + public static void setMockGetExceptionBadRequest(it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient client) { + when(client.invokeAPI(any(), eq(HttpMethod.GET), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())) + .thenThrow(new AppException(new HttpClientErrorException(HttpStatus.BAD_REQUEST), AppErrorCodeMessageEnum.CLIENT_GPD)); + } + + public static void setMockPut(it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient client, ResponseEntity response) { + when(client.invokeAPI(any(), eq(HttpMethod.PUT), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(response); + when(client.parameterToMultiValueMap(any(), any(), any())).thenReturn(new HttpHeaders()); when(client.parameterToString(any())).thenReturn(""); - when(client.selectHeaderAccept(any())).thenReturn(Arrays.asList()); + when(client.selectHeaderAccept(any())).thenReturn(List.of()); when(client.selectHeaderContentType(any())).thenReturn(MediaType.APPLICATION_JSON); } - public static String getInnerRptPayload(boolean bollo,String amount,String datiSpecificiRiscossione){ - if(datiSpecificiRiscossione==null){ + public static void setMockPost(it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient client, ResponseEntity response) { + when(client.invokeAPI(any(), eq(HttpMethod.POST), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(response); + when(client.parameterToMultiValueMap(any(), any(), any())).thenReturn(new HttpHeaders()); + when(client.parameterToString(any())).thenReturn(""); + when(client.selectHeaderAccept(any())).thenReturn(List.of()); + when(client.selectHeaderContentType(any())).thenReturn(MediaType.APPLICATION_JSON); + } + + public static void setMock(it.gov.pagopa.gen.wispconverter.client.checkout.invoker.ApiClient client, ResponseEntity response) { + when(client.invokeAPI(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(response); + when(client.parameterToMultiValueMap(any(), any(), any())).thenReturn(new HttpHeaders()); + when(client.parameterToString(any())).thenReturn(""); + when(client.selectHeaderAccept(any())).thenReturn(List.of()); + when(client.selectHeaderContentType(any())).thenReturn(MediaType.APPLICATION_JSON); + } + + public static String getInnerRptPayload(boolean bollo, String amount, String datiSpecificiRiscossione) { + if (datiSpecificiRiscossione == null) { datiSpecificiRiscossione = "9/tipodovuto_7/datospecifico"; } - String rpt = TestUtils.loadFileContent(bollo?"/requests/rptBollo.xml":"/requests/rpt.xml"); + String rpt = TestUtils.loadFileContent(bollo ? "/requests/rptBollo.xml" : "/requests/rpt.xml"); return rpt - .replace("{datiSpecificiRiscossione}",datiSpecificiRiscossione) - .replaceAll("\\{amount\\}", amount); + .replace("{datiSpecificiRiscossione}", datiSpecificiRiscossione) + .replaceAll("\\{amount}", amount); } - public static String getRptPayload(boolean bollo,String station,String amount,String datiSpecificiRiscossione){ - if(datiSpecificiRiscossione==null){ + public static String getRptPayload(boolean bollo, String station, String amount, String datiSpecificiRiscossione) { + if (datiSpecificiRiscossione == null) { datiSpecificiRiscossione = "9/tipodovuto_7/datospecifico"; } - String rpt = TestUtils.loadFileContent(bollo?"/requests/rptBollo.xml":"/requests/rpt.xml"); + String rpt = TestUtils.loadFileContent(bollo ? "/requests/rptBollo.xml" : "/requests/rpt.xml"); String rptreplace = rpt - .replace("{datiSpecificiRiscossione}",datiSpecificiRiscossione) - .replaceAll("\\{amount\\}", amount); + .replace("{datiSpecificiRiscossione}", datiSpecificiRiscossione) + .replaceAll("\\{amount}", amount); String nodoInviaRPT = TestUtils.loadFileContent("/requests/nodoInviaRPT.xml"); return nodoInviaRPT - .replace("{station}",station) + .replace("{station}", station) .replace("{rpt}", Base64.getEncoder().encodeToString(rptreplace.getBytes(StandardCharsets.UTF_8))); } - public static String getCarrelloPayload(int numofrpt,String station,String amount,boolean multibeneficiario){ - String rpt = TestUtils.loadFileContent("/requests/rpt.xml"); - String rptreplace = rpt.replaceAll("\\{amount\\}", amount); - StringBuilder listaRpt = new StringBuilder(""); - for(int i=0;i"+ - ""+ - ""+ - ""+ - ""+ + ("" + + "" + + "" + + "" + + "" + "{rpt}" + - "").replace("{rpt}",Base64.getEncoder().encodeToString(rptreplace.getBytes(StandardCharsets.UTF_8))) + "").replace("{rpt}", Base64.getEncoder().encodeToString(rptReplaceIuv.getBytes(StandardCharsets.UTF_8))) ); } String carrello = TestUtils.loadFileContent("/requests/nodoInviaCarrelloRPT.xml"); return carrello - .replace("{station}",station) - .replace("{multi}",multibeneficiario?"true":"") + .replace("{station}", station) + .replace("{multi}", multibeneficiario ? "true" : "") .replace("{elementiRpt}", listaRpt.toString()); } @@ -158,7 +257,8 @@ public static byte[] zip(byte[] uncompressed) throws IOException { bais.close(); return bais.toByteArray(); } - public static String zipAndEncode(String p){ + + public static String zipAndEncode(String p) { try { return new String(Base64.getEncoder().encode(zip(p.getBytes(StandardCharsets.UTF_8)))); } catch (IOException e) { @@ -166,4 +266,45 @@ public static String zipAndEncode(String p){ } } + public static PaymentPositionModelBaseResponseDto getValidPaymentPositionModelBaseResponseDto() { + PaymentPositionModelBaseResponseDto paymentPositionModelBaseResponseDto = new PaymentPositionModelBaseResponseDto(); + paymentPositionModelBaseResponseDto.setOrganizationFiscalCode("org12345678"); + paymentPositionModelBaseResponseDto.setIupd("abcd-efgh-ilmn-opqr"); + paymentPositionModelBaseResponseDto.setStatus(PaymentPositionModelBaseResponseDto.StatusEnum.VALID); + paymentPositionModelBaseResponseDto.setPaymentOption(List.of(getPaymentOptionModelResponseDto())); + return paymentPositionModelBaseResponseDto; + } + + public static PaymentPositionModelBaseResponseDto getInvalidPaymentPositionModelBaseResponseDto() { + PaymentPositionModelBaseResponseDto paymentPositionModelBaseResponseDto = new PaymentPositionModelBaseResponseDto(); + paymentPositionModelBaseResponseDto.setOrganizationFiscalCode("org12345678"); + paymentPositionModelBaseResponseDto.setIupd("abcd-efgh-ilmn-opqr"); + paymentPositionModelBaseResponseDto.setStatus(PaymentPositionModelBaseResponseDto.StatusEnum.INVALID); + paymentPositionModelBaseResponseDto.setPaymentOption(List.of(getPaymentOptionModelResponseDto())); + return paymentPositionModelBaseResponseDto; + } + + public static PaymentOptionModelResponseDto getPaymentOptionModelResponseDto() { + PaymentOptionModelResponseDto paymentOptionModelResponseDto = new PaymentOptionModelResponseDto(); + paymentOptionModelResponseDto.setIuv("123456IUVMOCK1"); + paymentOptionModelResponseDto.setAmount(200L); + paymentOptionModelResponseDto.setNav("3123456IUVMOCK1"); + return paymentOptionModelResponseDto; + } + + public static PaymentPositionModelDto getPaymentPositionModelDto() { + PaymentPositionModelDto paymentPositionModelDto = new PaymentPositionModelDto(); + paymentPositionModelDto.setIupd("abcd-efgh-ilmn-opqr"); + paymentPositionModelDto.setPaymentOption(List.of(getPaymentOptionModelDto())); + return paymentPositionModelDto; + } + + public static PaymentOptionModelDto getPaymentOptionModelDto() { + PaymentOptionModelDto paymentOptionModelDto = new PaymentOptionModelDto(); + paymentOptionModelDto.setIuv("123456IUVMOCK1"); + paymentOptionModelDto.setAmount(200L); + paymentOptionModelDto.setNav("3123456IUVMOCK1"); + return paymentOptionModelDto; + } + } diff --git a/src/test/resources/requests/rpt.xml b/src/test/resources/requests/rpt.xml index 24b7a9f0..22857c6d 100644 --- a/src/test/resources/requests/rpt.xml +++ b/src/test/resources/requests/rpt.xml @@ -24,7 +24,7 @@ {dataEsecuzionePagamento} {amount} {tipoVersamento} - {iuv} + 123456IUVMOCK1 {ccp} 0 @@ -34,4 +34,4 @@ {datiSpecificiRiscossione} - \ No newline at end of file + diff --git a/src/test/resources/requests/rptBollo.xml b/src/test/resources/requests/rptBollo.xml index 2d6194c1..29c217fe 100644 --- a/src/test/resources/requests/rptBollo.xml +++ b/src/test/resources/requests/rptBollo.xml @@ -24,7 +24,7 @@ {dataEsecuzionePagamento} {amount} {tipoVersamento} - {iuv} + 123456IUVMOCK1 {ccp} 0 @@ -44,4 +44,4 @@ - \ No newline at end of file + diff --git a/src/test/resources/requests/rptCart.xml b/src/test/resources/requests/rptCart.xml new file mode 100644 index 00000000..a9688c1c --- /dev/null +++ b/src/test/resources/requests/rptCart.xml @@ -0,0 +1,37 @@ + + 0 + + {pa} + + 3179612d79fa3367 + {dataOraMessaggioRichiesta}T17:13:31 + USR + + + F + TTTTTT11T11T123T + + Utente Test + + + + G + 00053070918 + + Comune di Nuoro + + + {dataEsecuzionePagamento} + {amount} + {tipoVersamento} + {iuv} + {ccp} + 0 + + {amount} + IT96R0760154321000000012345 + Pagamento di prova + {datiSpecificiRiscossione} + + + diff --git a/src/test/resources/requests/rptNullIban.xml b/src/test/resources/requests/rptNullIban.xml new file mode 100644 index 00000000..a4400baf --- /dev/null +++ b/src/test/resources/requests/rptNullIban.xml @@ -0,0 +1,36 @@ + + 0 + + {pa} + + 3179612d79fa3366 + {dataOraMessaggioRichiesta}T17:13:30 + USR + + + F + TTTTTT11T11T123T + + Utente Test + + + + G + 00053070918 + + Comune di Nuoro + + + {dataEsecuzionePagamento} + {amount} + {tipoVersamento} + 123456IUVMOCK1 + {ccp} + 0 + + {amount} + Pagamento di prova + {datiSpecificiRiscossione} + + +