Class VoucherifyMockUtil
java.lang.Object
org.bhn.promotion.voucherify.utils.VoucherifyMockUtil
This class contains Voucherify Util methods
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidconvertStringToEnum(String exportType, String sortingParameterName, io.voucherify.client.model.ExportsCreateRequestBody createRequestBody, List<String> voucherFields, List<String> vouhcerifyOrderFields) Converts the export type and sorting parameter name to the corresponding enums and sets them in the providedExportsCreateRequestBody.static FilegenerateCSVFromDownloadExport(String filePath, String downloadExportResponseData, String promoReportNewFields, String promoOrderFields, String exportType) Generates a CSV file from the downloaded export data.static StringgenerateFilePath(String exportType) Generates a file path for the export file based on the export type.static Consumer<org.springframework.http.HttpHeaders>getHttpHeadersConsumer(String appId, String token) Returns a consumer that sets HTTP headers for API requests.static StringgetTokenFromResultUrl(String resultUrl) Extracts the token from the result URL.static InputStreamreadFromJson(String filePath) Reads a JSON file from the resources directory and returns its input stream.rollbackRollbackResponse(String filePath) This class creates Rollback response object from jsonstatic voidsetParametersBasedOnExportType(String exportType, io.voucherify.client.model.ExportsCreateRequestBodyParameters parameters, List<String> voucherFields, List<String> vouhcerifyOrderFields) Sets parameters in the givenExportsCreateRequestBodyParametersbased on the export type.voucherifyQualificationResponse(String filePath) This class creates Eligibility response object from jsonstatic RedeemPromotionResponseDtovoucherifyRedemptionResponse(String filePath) This class creates Redemption response object from jsonstatic ValidationResponseDtovoucherifyValidationResponse(String filePath) This class creates Validation response object from json
-
Method Details
-
voucherifyValidationResponse
This class creates Validation response object from json- Parameters:
filePath- Json Response file- Returns:
ValidationResponseDtoValidations Response object
-
voucherifyQualificationResponse
This class creates Eligibility response object from json- Parameters:
filePath- Json Response file- Returns:
CheckPromotionEligibilityResponseDtoEligibility Response object
-
voucherifyRedemptionResponse
This class creates Redemption response object from json- Parameters:
filePath- Json Response file- Returns:
RedeemPromotionResponseDtoRedemption Response object
-
rollbackRollbackResponse
This class creates Rollback response object from json- Parameters:
filePath- Json Response file- Returns:
RedemptionRollbackResponseDtoRollback Response object
-
getTokenFromResultUrl
Extracts the token from the result URL.- Parameters:
resultUrl- the URL from which to extract the token.- Returns:
- the extracted token, or null if the token cannot be found.
-
setParametersBasedOnExportType
public static void setParametersBasedOnExportType(String exportType, io.voucherify.client.model.ExportsCreateRequestBodyParameters parameters, List<String> voucherFields, List<String> vouhcerifyOrderFields) Sets parameters in the givenExportsCreateRequestBodyParametersbased on the export type.- Parameters:
exportType- the type of export (e.g., VOUCHER or ORDER).parameters- the parameters object to set fields in.voucherFields- the list of fields for voucher exports.vouhcerifyOrderFields- the list of fields for order exports.
-
generateFilePath
Generates a file path for the export file based on the export type.- Parameters:
exportType- the type of export (e.g., VOUCHER or ORDER).- Returns:
- the generated file path as a String.
-
convertStringToEnum
public static void convertStringToEnum(String exportType, String sortingParameterName, io.voucherify.client.model.ExportsCreateRequestBody createRequestBody, List<String> voucherFields, List<String> vouhcerifyOrderFields) Converts the export type and sorting parameter name to the corresponding enums and sets them in the providedExportsCreateRequestBody.- Parameters:
exportType- the type of export (e.g., VOUCHER or ORDER).sortingParameterName- the name of the sorting parameter.createRequestBody- the request body to set parameters in.voucherFields- the list of fields for voucher exports.vouhcerifyOrderFields- the list of fields for order exports.
-
generateCSVFromDownloadExport
public static File generateCSVFromDownloadExport(String filePath, String downloadExportResponseData, String promoReportNewFields, String promoOrderFields, String exportType) Generates a CSV file from the downloaded export data.- Parameters:
filePath- the path where the CSV file will be generated.downloadExportResponseData- the data returned from the download export response.promoReportNewFields- the new fields for the promo report.promoOrderFields- the fields for the order report.exportType- the type of export (e.g., VOUCHER or ORDER).- Returns:
- the generated CSV file.
-
getHttpHeadersConsumer
public static Consumer<org.springframework.http.HttpHeaders> getHttpHeadersConsumer(String appId, String token) Returns a consumer that sets HTTP headers for API requests.- Parameters:
appId- the application ID.token- the application token.- Returns:
- a consumer that adds the necessary headers to the HTTP request.
-
readFromJson
Reads a JSON file from the resources directory and returns its input stream.- Parameters:
filePath- the name of the JSON file to read, located in the `/mockJson/` directory within the resources.- Returns:
- an InputStream for the specified JSON file, or null if the file cannot be found.
- Throws:
NullPointerException- if the provided filePath is null.
-