Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PPANTT-191] feat: Create mdb gps service #1

Merged
merged 29 commits into from
Dec 4, 2024

Conversation

gioelemella
Copy link
Collaborator

@gioelemella gioelemella commented Nov 29, 2024

List of Changes

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

google-java-format

[google-java-format] reported by reviewdog 🐶

https://github.com/pagopa/pagopa-gps-mbd-service/blob/5b8f7d29564c98e5f8f6e1c2e17caa9d7a17c8f4/src/main/java/it/gov/pagopa/mbd/gps/service/config/WebMvcConfiguration.java#L27-L28


[google-java-format] reported by reviewdog 🐶

@Value("${server.servlet.context-path}")
String basePath;
@Value("${info.application.name}")
private String name;
@Value("${info.application.version}")
private String version;
@Value("${info.properties.environment}")
private String environment;
/**
* @return redirect to Swagger page documentation
*/
@Hidden
@GetMapping("")
public RedirectView home() {
if (!basePath.endsWith("/")) {
basePath += "/";
}
return new RedirectView(basePath + "swagger-ui.html");
}
/**
* Return app name, version and environment
*
* @return the app info
*/
@Operation(
summary = "health check",
description = "Return OK if application is started",
security = {@SecurityRequirement(name = "ApiKey")},
tags = {"Home"})
@GetMapping(value = "/info")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<AppInfo> healthCheck() {
AppInfo info = AppInfo.builder().name(name).version(version).environment(environment).build();
return ResponseEntity.status(HttpStatus.OK).body(info);


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@RequestMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Autowired
public MbdGpsController(ModelMapper modelMapper) {
this.modelMapper = modelMapper;
}


[google-java-format] reported by reviewdog 🐶

/**
* Map MBD service specific data into payment option model
*
* @param mbdPaymentOptionRequest MBD data
* @return the mapped model
*/
@PostMapping("/mbd/paymentOption")
@ResponseStatus(HttpStatus.CREATED)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = MbdPaymentOptionResponse.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@Operation(summary = "Create MBD payment option", security = {@SecurityRequirement(name = "ApiKey")})
public @Valid MbdPaymentOptionResponse createMdbPaymentOption(
@RequestBody @NotNull @Valid MbdPaymentOptionRequest mbdPaymentOptionRequest
) {
return this.modelMapper.map(mbdPaymentOptionRequest, MbdPaymentOptionResponse.class);
}
}


[google-java-format] reported by reviewdog 🐶

INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error", "Something was wrong"),
BAD_REQUEST(HttpStatus.INTERNAL_SERVER_ERROR, "Bad Request", "%s"),
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "Unauthorized", "Error during authentication"),
FORBIDDEN(HttpStatus.FORBIDDEN, "Forbidden", "This method is forbidden"),
RESPONSE_NOT_READABLE(HttpStatus.BAD_GATEWAY, "Response Not Readable", "The response body is not readable"),


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

public final HttpStatus httpStatus;
public final String title;
public final String details;


[google-java-format] reported by reviewdog 🐶

AppError(HttpStatus httpStatus, String title, String details) {
this.httpStatus = httpStatus;
this.title = title;
this.details = details;
}


[google-java-format] reported by reviewdog 🐶

https://github.com/pagopa/pagopa-gps-mbd-service/blob/5b8f7d29564c98e5f8f6e1c2e17caa9d7a17c8f4/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java#L26-L27


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* title returned to the response when this exception occurred
*/
String title;
/**
* http status returned to the response when this exception occurred
*/
HttpStatus httpStatus;


[google-java-format] reported by reviewdog 🐶

/**
* @param httpStatus HTTP status returned to the response
* @param title title returned to the response when this exception occurred
* @param message the detail message returend to the response
* @param cause The cause of this {@link AppException}
*/
public AppException(
@NotNull HttpStatus httpStatus, @NotNull String title,
@NotNull String message, Throwable cause
) {
super(message, cause);
this.title = title;
this.httpStatus = httpStatus;
}


[google-java-format] reported by reviewdog 🐶

/**
* @param httpStatus HTTP status returned to the response
* @param title title returned to the response when this exception occurred
* @param message the detail message returend to the response
*/
public AppException(@NotNull HttpStatus httpStatus, @NotNull String title, @NotNull String message) {
super(message);
this.title = title;
this.httpStatus = httpStatus;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* @param appError Response template returned to the response
* @param args {@link Formatter} replaces the placeholders in "details" string of
* {@link AppError} with the arguments. If there are more arguments than format
* specifiers, the extra arguments are ignored.
*/
public AppException(@NotNull AppError appError, Object... args) {
super(formatDetails(appError, args));
this.httpStatus = appError.httpStatus;
this.title = appError.title;
}


[google-java-format] reported by reviewdog 🐶

/**
* @param appError Response template returned to the response
* @param cause The cause of this {@link AppException}
* @param args Arguments for the details of {@link AppError} replaced by the
* {@link Formatter}. If there are more arguments than format specifiers, the
* extra arguments are ignored.
*/
public AppException(@NotNull AppError appError, Throwable cause, Object... args) {
super(formatDetails(appError, args), cause);
this.httpStatus = appError.httpStatus;
this.title = appError.title;
}


[google-java-format] reported by reviewdog 🐶

private static String formatDetails(AppError appError, Object[] args) {
return String.format(appError.details, args);
}


[google-java-format] reported by reviewdog 🐶

@Override
public String toString() {
return "AppException(" + httpStatus + ", " + title + ")" + super.toString();
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.util.ArrayList;
import java.util.List;
/**
* All Exceptions are handled by this class
*/


[google-java-format] reported by reviewdog 🐶

/**
* Handle if the input request is not a valid JSON
*
* @param ex {@link HttpMessageNotReadableException} exception raised
* @param headers of the response
* @param status of the response
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status
*/
@Override
public ResponseEntity<Object> handleHttpMessageNotReadable(
HttpMessageNotReadableException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
log.warn("Input not readable: ", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail("Invalid input format")
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}


[google-java-format] reported by reviewdog 🐶

/**
* Handle if missing some request parameters in the request
*
* @param ex {@link MissingServletRequestParameterException} exception raised
* @param headers of the response
* @param status of the response
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status
*/
@Override
public ResponseEntity<Object> handleMissingServletRequestParameter(
MissingServletRequestParameterException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
log.warn("Missing request parameter: ", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* Customize the response for TypeMismatchException.
*
* @param ex the exception
* @param headers the headers to be written to the response
* @param status the selected response status
* @param request the current request
* @return a {@code ResponseEntity} instance
*/
@Override
protected ResponseEntity<Object> handleTypeMismatch(
TypeMismatchException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
log.warn("Type mismatch: ", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(String.format("Invalid value %s for property %s", ex.getValue(),
((MethodArgumentTypeMismatchException) ex).getName()))
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* Handle if validation constraints are unsatisfied
*
* @param ex {@link MethodArgumentNotValidException} exception raised
* @param headers of the response
* @param status of the response
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
List<String> details = new ArrayList<>();
for (FieldError error : ex.getBindingResult().getFieldErrors()) {
details.add(error.getField() + ": " + error.getDefaultMessage());
}
var detailsMessage = String.join(", ", details);
log.warn("Input not valid: " + detailsMessage);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(detailsMessage)
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}


[google-java-format] reported by reviewdog 🐶

@ExceptionHandler({ConstraintViolationException.class})
public ResponseEntity<ProblemJson> handleConstraintViolationException(
final ConstraintViolationException ex,
final WebRequest request
) {
log.warn("Validation Error raised:", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* Handle if a {@link AppException} is raised
*
* @param ex {@link AppException} exception raised
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with an appropriated HTTP status
*/
@ExceptionHandler({AppException.class})
public ResponseEntity<ProblemJson> handleAppException(
final AppException ex,
final WebRequest request
) {
if (ex.getCause() != null) {
log.warn("App Exception raised: {}\nCause of the App Exception: ", ex.getMessage(), ex.getCause());
} else {
log.warn("App Exception raised: ", ex);
}
var errorResponse = ProblemJson.builder()
.status(ex.getHttpStatus().value())
.title(ex.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, ex.getHttpStatus());
}
/**
* Handle if a {@link Exception} is raised
*
* @param ex {@link Exception} exception raised
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with 500 as HTTP status
*/
@ExceptionHandler({Exception.class})
public ResponseEntity<ProblemJson> handleGenericException(
final Exception ex,
final WebRequest request
) {
log.error("Generic Exception raised:", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
.title(AppError.INTERNAL_SERVER_ERROR.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties;
import it.gov.pagopa.mbd.gps.service.model.PaymentOption;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;


[google-java-format] reported by reviewdog 🐶

* Converter class that specify how to convert a {@link MbdPaymentOptionRequest} instance to a {@link MbdPaymentOptionResponse} instance


[google-java-format] reported by reviewdog 🐶

public class ConvertMbdPaymentOptionRequestToMbdPaymentOptionResponse implements Converter<MbdPaymentOptionRequest, MbdPaymentOptionResponse> {


[google-java-format] reported by reviewdog 🐶

private static final boolean IS_PARTIAL_PAYMENT = false;
private static final String ID_TRANSFER = "1";
private static final String STAMP_TYPE = "st";


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.transfer.remittance-information}")
private String remittanceInformation;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.due-date-delta-time-unit}")
private ChronoUnit dueDateDeltaTimeUnit;


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.retention-date-delta}")
private int retentionDateDelta;


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.retention-date-delta-time-unit}")
private ChronoUnit retentionDateDeltaTimeUnit;


[google-java-format] reported by reviewdog 🐶

@Override
public MbdPaymentOptionResponse convert(MappingContext<MbdPaymentOptionRequest, MbdPaymentOptionResponse> context) {
MbdPaymentOptionRequestProperties model = context.getSource().getProperties();


[google-java-format] reported by reviewdog 🐶

Transfer transfer = Transfer.builder()
.amount(model.getAmount())
.idTransfer(ID_TRANSFER)
.organizationFiscalCode(model.getFiscalCode())
.remittanceInformation(remittanceInformation)
.stamp(Stamp.builder()
.hashDocument(model.getDocumentHash())
.provincialResidence(model.getProvincialResidence())
.stampType(STAMP_TYPE)
.build())
.build();


[google-java-format] reported by reviewdog 🐶

PaymentOption paymentOption = PaymentOption.builder()
.firstName(model.getFirstName())
.lastName(model.getLastName())
.amount(model.getAmount())
.description(description)
.dueDate(LocalDateTime.now().plus(dueDateDelta, dueDateDeltaTimeUnit))
.retentionDate(LocalDateTime.now().plus(retentionDateDelta, retentionDateDeltaTimeUnit))
.isPartialPayment(IS_PARTIAL_PAYMENT)
.transfer(Collections.singletonList(transfer))
.build();


[google-java-format] reported by reviewdog 🐶

return MbdPaymentOptionResponse.builder()
.paymentOption(Collections.singletonList(paymentOption))
.build();
}
}


[google-java-format] reported by reviewdog 🐶

private String[] origins;
private String[] methods;


[google-java-format] reported by reviewdog 🐶

private String name;
private String version;
private String environment;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "MBD payment option's properties", requiredMode = Schema.RequiredMode.REQUIRED)
private MbdPaymentOptionRequestProperties properties;
}


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD service specific data
*/


[google-java-format] reported by reviewdog 🐶

@NotNull(message = "amount is required")
@Schema(description = "MBD amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED)
private String firstName;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED)
private String lastName;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's fiscal code", requiredMode = Schema.RequiredMode.REQUIRED)
private String fiscalCode;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's residence province", requiredMode = Schema.RequiredMode.REQUIRED)
private String provincialResidence;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(min = 44, max = 44)
@Schema(description = "MBD document's hash", requiredMode = Schema.RequiredMode.REQUIRED)
private String documentHash;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.util.List;
/**
* Model class that holds MBD GPS response
*/


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "MBD payment option", requiredMode = Schema.RequiredMode.REQUIRED)
private List<@Valid PaymentOption> paymentOption;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.time.LocalDateTime;
import java.util.List;
/**
* Model class that holds MBD payment option data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED)
private String firstName;
@NotBlank
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED)
private String lastName;
@NotNull(message = "amount is required")
@Schema(description = "Payment option's amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;
@NotBlank(message = "payment option description is required")
@Size(max = 140) // compliant to paForNode.xsd
@Schema(description = "Payment option's description", requiredMode = Schema.RequiredMode.REQUIRED)
private String description;
@NotNull(message = "is partial payment is required")
@Schema(description = "Payment option's is partial payment flag", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean isPartialPayment;
@NotNull(message = "due date is required")
@Schema(description = "Payment option's due date", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime dueDate;
@Schema(description = "Payment option's retention date", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime retentionDate;
@Valid
@Schema(description = "Payment option's transfer list", requiredMode = Schema.RequiredMode.REQUIRED)
private List<@Valid Transfer> transfer;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@JsonProperty("title")
@Schema(description = "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable")
private String title;


[google-java-format] reported by reviewdog 🐶

@JsonProperty("status")
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.")
@Min(100)
@Max(600)
private Integer status;


[google-java-format] reported by reviewdog 🐶

@JsonProperty("detail")
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.")
private String detail;


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD stamp data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(max = 72)
@Schema(description = "Document hash type is stBase64Binary72 as described in https://github.com/pagopa/pagopa-api.", requiredMode = Schema.RequiredMode.REQUIRED)
// Stamp generally get as input a base64sha256, that is the SHA256 hash of a given string encoded with Base64.
// It is not equivalent to base64encode(sha256(“test”)), if sha256() returns a hexadecimal representation.
// The result should normally be 44 characters, to be compliant with as-is it was extended to 72
private String hashDocument;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(min = 2, max = 2)
@Schema(description = "The type of the stamp", minLength = 2, maxLength = 2, requiredMode = Schema.RequiredMode.REQUIRED)
private String stampType;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Pattern(regexp = "[A-Z]{2}")
@Schema(description = "The province of residence", example = "RM", pattern = "[A-Z]{2,2}", requiredMode = Schema.RequiredMode.REQUIRED)
private String provincialResidence;
}


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD transfer data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank(message = "id transfer is required")
@Schema(description = "Transfer's id", allowableValues = {"1", "2", "3", "4", "5"}, requiredMode = Schema.RequiredMode.REQUIRED)
private String idTransfer;


[google-java-format] reported by reviewdog 🐶

@NotNull(message = "amount is required")
@Schema(description = "Transfer's amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;


[google-java-format] reported by reviewdog 🐶

@Schema(description = "Fiscal code related to the organization targeted by this transfer.", example = "00000000000")
private String organizationFiscalCode;


[google-java-format] reported by reviewdog 🐶

@NotBlank(message = "remittance information is required")
@Size(max = 140, message = "remittance information must be compliant to EACT FORMATTING RULES, up to 140 chars")
@Schema(description = "Transfer's remittance information", requiredMode = Schema.RequiredMode.REQUIRED)
// https://docs.pagopa.it/saci/specifiche-attuative-dei-codici-identificativi-di-versamento-riversamento-e-rendicontazione/operazione-di-trasferimento-fondi
private String remittanceInformation; // causale


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "Transfer's stamp", requiredMode = Schema.RequiredMode.REQUIRED)
private Stamp stamp;
}


[google-java-format] reported by reviewdog 🐶

public static final String HEADER_REQUEST_ID = "X-Request-Id";


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertTrue;


[google-java-format] reported by reviewdog 🐶

@Test
void contextLoads() {
// check only if the context is loaded
assertTrue(true);
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void swaggerSpringPlugin() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())
.andDo(
result -> {
assertNotNull(result);
assertNotNull(result.getResponse());
final String content = result.getResponse().getContentAsString();
assertFalse(content.isBlank());
assertFalse(content.contains("${"), "Generated swagger contains placeholders");
Object swagger =
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class);
String formatted =
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger);
Path basePath = Paths.get("openapi/");
Files.createDirectories(basePath);
Files.write(basePath.resolve("openapi.json"), formatted.getBytes());
});
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void healthCheckTestSuccess() throws Exception {
mvc.perform(get("/info")).andExpect(status().isOk());
}
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties;
import it.gov.pagopa.mbd.gps.service.model.PaymentOption;


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶

@Autowired
private MockMvc mvc;
@Autowired
private ObjectMapper objectMapper;
@Test
void createMdbPaymentOptionTestSuccess() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
MvcResult result = mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andReturn();
String json = result.getResponse().getContentAsString();
assertNotNull(json);
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class);
assertNotNull(response);
assertNotNull(response.getPaymentOption());
assertEquals(1, response.getPaymentOption().size());
PaymentOption paymentOption = response.getPaymentOption().get(0);
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName());
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName());
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount());
assertNotNull(paymentOption.getDescription());
assertNotNull(paymentOption.getDueDate());
assertNotNull(paymentOption.getRetentionDate());
assertFalse(paymentOption.getIsPartialPayment());
assertNotNull(paymentOption.getTransfer());
assertEquals(1, paymentOption.getTransfer().size());
Transfer transfer = paymentOption.getTransfer().get(0);
assertEquals(request.getProperties().getAmount(), transfer.getAmount());
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode());
assertEquals("1", transfer.getIdTransfer());
assertNotNull(transfer.getRemittanceInformation());
assertNotNull(transfer.getStamp());
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence());
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument());
assertEquals("st", transfer.getStamp().getStampType());
}
@Test
void createMdbPaymentOptionTestFailAmountMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setAmount(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFirstName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setLastName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFiscalCode(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setProvincialResidence(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash("asdfsdf");
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() {
return MbdPaymentOptionRequest.builder()
.properties(MbdPaymentOptionRequestProperties.builder()
.amount(16L)
.firstName("Mario")
.lastName("Rossi")
.fiscalCode("0000000000000000")
.provincialResidence("AS")
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB")
.build())
.build();
}
}

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

google-java-format

[google-java-format] reported by reviewdog 🐶

https://github.com/pagopa/pagopa-gps-mbd-service/blob/5b8f7d29564c98e5f8f6e1c2e17caa9d7a17c8f4/src/main/java/it/gov/pagopa/mbd/gps/service/config/WebMvcConfiguration.java#L27-L28


[google-java-format] reported by reviewdog 🐶

@Value("${server.servlet.context-path}")
String basePath;
@Value("${info.application.name}")
private String name;
@Value("${info.application.version}")
private String version;
@Value("${info.properties.environment}")
private String environment;
/**
* @return redirect to Swagger page documentation
*/
@Hidden
@GetMapping("")
public RedirectView home() {
if (!basePath.endsWith("/")) {
basePath += "/";
}
return new RedirectView(basePath + "swagger-ui.html");
}
/**
* Return app name, version and environment
*
* @return the app info
*/
@Operation(
summary = "health check",
description = "Return OK if application is started",
security = {@SecurityRequirement(name = "ApiKey")},
tags = {"Home"})
@GetMapping(value = "/info")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<AppInfo> healthCheck() {
AppInfo info = AppInfo.builder().name(name).version(version).environment(environment).build();
return ResponseEntity.status(HttpStatus.OK).body(info);


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@RequestMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Autowired
public MbdGpsController(ModelMapper modelMapper) {
this.modelMapper = modelMapper;
}


[google-java-format] reported by reviewdog 🐶

/**
* Map MBD service specific data into payment option model
*
* @param mbdPaymentOptionRequest MBD data
* @return the mapped model
*/
@PostMapping("/mbd/paymentOption")
@ResponseStatus(HttpStatus.CREATED)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = MbdPaymentOptionResponse.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@Operation(summary = "Create MBD payment option", security = {@SecurityRequirement(name = "ApiKey")})
public @Valid MbdPaymentOptionResponse createMdbPaymentOption(
@RequestBody @NotNull @Valid MbdPaymentOptionRequest mbdPaymentOptionRequest
) {
return this.modelMapper.map(mbdPaymentOptionRequest, MbdPaymentOptionResponse.class);
}
}


[google-java-format] reported by reviewdog 🐶

INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error", "Something was wrong"),
BAD_REQUEST(HttpStatus.INTERNAL_SERVER_ERROR, "Bad Request", "%s"),
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "Unauthorized", "Error during authentication"),
FORBIDDEN(HttpStatus.FORBIDDEN, "Forbidden", "This method is forbidden"),
RESPONSE_NOT_READABLE(HttpStatus.BAD_GATEWAY, "Response Not Readable", "The response body is not readable"),


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

public final HttpStatus httpStatus;
public final String title;
public final String details;


[google-java-format] reported by reviewdog 🐶

AppError(HttpStatus httpStatus, String title, String details) {
this.httpStatus = httpStatus;
this.title = title;
this.details = details;
}


[google-java-format] reported by reviewdog 🐶

https://github.com/pagopa/pagopa-gps-mbd-service/blob/5b8f7d29564c98e5f8f6e1c2e17caa9d7a17c8f4/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java#L26-L27


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* title returned to the response when this exception occurred
*/
String title;
/**
* http status returned to the response when this exception occurred
*/
HttpStatus httpStatus;


[google-java-format] reported by reviewdog 🐶

/**
* @param httpStatus HTTP status returned to the response
* @param title title returned to the response when this exception occurred
* @param message the detail message returend to the response
* @param cause The cause of this {@link AppException}
*/
public AppException(
@NotNull HttpStatus httpStatus, @NotNull String title,
@NotNull String message, Throwable cause
) {
super(message, cause);
this.title = title;
this.httpStatus = httpStatus;
}


[google-java-format] reported by reviewdog 🐶

/**
* @param httpStatus HTTP status returned to the response
* @param title title returned to the response when this exception occurred
* @param message the detail message returend to the response
*/
public AppException(@NotNull HttpStatus httpStatus, @NotNull String title, @NotNull String message) {
super(message);
this.title = title;
this.httpStatus = httpStatus;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* @param appError Response template returned to the response
* @param args {@link Formatter} replaces the placeholders in "details" string of
* {@link AppError} with the arguments. If there are more arguments than format
* specifiers, the extra arguments are ignored.
*/
public AppException(@NotNull AppError appError, Object... args) {
super(formatDetails(appError, args));
this.httpStatus = appError.httpStatus;
this.title = appError.title;
}


[google-java-format] reported by reviewdog 🐶

/**
* @param appError Response template returned to the response
* @param cause The cause of this {@link AppException}
* @param args Arguments for the details of {@link AppError} replaced by the
* {@link Formatter}. If there are more arguments than format specifiers, the
* extra arguments are ignored.
*/
public AppException(@NotNull AppError appError, Throwable cause, Object... args) {
super(formatDetails(appError, args), cause);
this.httpStatus = appError.httpStatus;
this.title = appError.title;
}


[google-java-format] reported by reviewdog 🐶

private static String formatDetails(AppError appError, Object[] args) {
return String.format(appError.details, args);
}


[google-java-format] reported by reviewdog 🐶

@Override
public String toString() {
return "AppException(" + httpStatus + ", " + title + ")" + super.toString();
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.util.ArrayList;
import java.util.List;
/**
* All Exceptions are handled by this class
*/


[google-java-format] reported by reviewdog 🐶

/**
* Handle if the input request is not a valid JSON
*
* @param ex {@link HttpMessageNotReadableException} exception raised
* @param headers of the response
* @param status of the response
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status
*/
@Override
public ResponseEntity<Object> handleHttpMessageNotReadable(
HttpMessageNotReadableException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
log.warn("Input not readable: ", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail("Invalid input format")
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}


[google-java-format] reported by reviewdog 🐶

/**
* Handle if missing some request parameters in the request
*
* @param ex {@link MissingServletRequestParameterException} exception raised
* @param headers of the response
* @param status of the response
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status
*/
@Override
public ResponseEntity<Object> handleMissingServletRequestParameter(
MissingServletRequestParameterException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
log.warn("Missing request parameter: ", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* Customize the response for TypeMismatchException.
*
* @param ex the exception
* @param headers the headers to be written to the response
* @param status the selected response status
* @param request the current request
* @return a {@code ResponseEntity} instance
*/
@Override
protected ResponseEntity<Object> handleTypeMismatch(
TypeMismatchException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
log.warn("Type mismatch: ", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(String.format("Invalid value %s for property %s", ex.getValue(),
((MethodArgumentTypeMismatchException) ex).getName()))
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* Handle if validation constraints are unsatisfied
*
* @param ex {@link MethodArgumentNotValidException} exception raised
* @param headers of the response
* @param status of the response
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
List<String> details = new ArrayList<>();
for (FieldError error : ex.getBindingResult().getFieldErrors()) {
details.add(error.getField() + ": " + error.getDefaultMessage());
}
var detailsMessage = String.join(", ", details);
log.warn("Input not valid: " + detailsMessage);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(detailsMessage)
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}


[google-java-format] reported by reviewdog 🐶

@ExceptionHandler({ConstraintViolationException.class})
public ResponseEntity<ProblemJson> handleConstraintViolationException(
final ConstraintViolationException ex,
final WebRequest request
) {
log.warn("Validation Error raised:", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* Handle if a {@link AppException} is raised
*
* @param ex {@link AppException} exception raised
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with an appropriated HTTP status
*/
@ExceptionHandler({AppException.class})
public ResponseEntity<ProblemJson> handleAppException(
final AppException ex,
final WebRequest request
) {
if (ex.getCause() != null) {
log.warn("App Exception raised: {}\nCause of the App Exception: ", ex.getMessage(), ex.getCause());
} else {
log.warn("App Exception raised: ", ex);
}
var errorResponse = ProblemJson.builder()
.status(ex.getHttpStatus().value())
.title(ex.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, ex.getHttpStatus());
}
/**
* Handle if a {@link Exception} is raised
*
* @param ex {@link Exception} exception raised
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with 500 as HTTP status
*/
@ExceptionHandler({Exception.class})
public ResponseEntity<ProblemJson> handleGenericException(
final Exception ex,
final WebRequest request
) {
log.error("Generic Exception raised:", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
.title(AppError.INTERNAL_SERVER_ERROR.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties;
import it.gov.pagopa.mbd.gps.service.model.PaymentOption;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;


[google-java-format] reported by reviewdog 🐶

* Converter class that specify how to convert a {@link MbdPaymentOptionRequest} instance to a {@link MbdPaymentOptionResponse} instance


[google-java-format] reported by reviewdog 🐶

public class ConvertMbdPaymentOptionRequestToMbdPaymentOptionResponse implements Converter<MbdPaymentOptionRequest, MbdPaymentOptionResponse> {


[google-java-format] reported by reviewdog 🐶

private static final boolean IS_PARTIAL_PAYMENT = false;
private static final String ID_TRANSFER = "1";
private static final String STAMP_TYPE = "st";


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.transfer.remittance-information}")
private String remittanceInformation;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.due-date-delta-time-unit}")
private ChronoUnit dueDateDeltaTimeUnit;


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.retention-date-delta}")
private int retentionDateDelta;


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.retention-date-delta-time-unit}")
private ChronoUnit retentionDateDeltaTimeUnit;


[google-java-format] reported by reviewdog 🐶

@Override
public MbdPaymentOptionResponse convert(MappingContext<MbdPaymentOptionRequest, MbdPaymentOptionResponse> context) {
MbdPaymentOptionRequestProperties model = context.getSource().getProperties();


[google-java-format] reported by reviewdog 🐶

Transfer transfer = Transfer.builder()
.amount(model.getAmount())
.idTransfer(ID_TRANSFER)
.organizationFiscalCode(model.getFiscalCode())
.remittanceInformation(remittanceInformation)
.stamp(Stamp.builder()
.hashDocument(model.getDocumentHash())
.provincialResidence(model.getProvincialResidence())
.stampType(STAMP_TYPE)
.build())
.build();


[google-java-format] reported by reviewdog 🐶

PaymentOption paymentOption = PaymentOption.builder()
.firstName(model.getFirstName())
.lastName(model.getLastName())
.amount(model.getAmount())
.description(description)
.dueDate(LocalDateTime.now().plus(dueDateDelta, dueDateDeltaTimeUnit))
.retentionDate(LocalDateTime.now().plus(retentionDateDelta, retentionDateDeltaTimeUnit))
.isPartialPayment(IS_PARTIAL_PAYMENT)
.transfer(Collections.singletonList(transfer))
.build();


[google-java-format] reported by reviewdog 🐶

return MbdPaymentOptionResponse.builder()
.paymentOption(Collections.singletonList(paymentOption))
.build();
}
}


[google-java-format] reported by reviewdog 🐶

private String[] origins;
private String[] methods;


[google-java-format] reported by reviewdog 🐶

private String name;
private String version;
private String environment;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "MBD payment option's properties", requiredMode = Schema.RequiredMode.REQUIRED)
private MbdPaymentOptionRequestProperties properties;
}


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD service specific data
*/


[google-java-format] reported by reviewdog 🐶

@NotNull(message = "amount is required")
@Schema(description = "MBD amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED)
private String firstName;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED)
private String lastName;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's fiscal code", requiredMode = Schema.RequiredMode.REQUIRED)
private String fiscalCode;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's residence province", requiredMode = Schema.RequiredMode.REQUIRED)
private String provincialResidence;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(min = 44, max = 44)
@Schema(description = "MBD document's hash", requiredMode = Schema.RequiredMode.REQUIRED)
private String documentHash;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.util.List;
/**
* Model class that holds MBD GPS response
*/


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "MBD payment option", requiredMode = Schema.RequiredMode.REQUIRED)
private List<@Valid PaymentOption> paymentOption;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.time.LocalDateTime;
import java.util.List;
/**
* Model class that holds MBD payment option data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED)
private String firstName;
@NotBlank
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED)
private String lastName;
@NotNull(message = "amount is required")
@Schema(description = "Payment option's amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;
@NotBlank(message = "payment option description is required")
@Size(max = 140) // compliant to paForNode.xsd
@Schema(description = "Payment option's description", requiredMode = Schema.RequiredMode.REQUIRED)
private String description;
@NotNull(message = "is partial payment is required")
@Schema(description = "Payment option's is partial payment flag", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean isPartialPayment;
@NotNull(message = "due date is required")
@Schema(description = "Payment option's due date", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime dueDate;
@Schema(description = "Payment option's retention date", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime retentionDate;
@Valid
@Schema(description = "Payment option's transfer list", requiredMode = Schema.RequiredMode.REQUIRED)
private List<@Valid Transfer> transfer;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@JsonProperty("title")
@Schema(description = "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable")
private String title;


[google-java-format] reported by reviewdog 🐶

@JsonProperty("status")
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.")
@Min(100)
@Max(600)
private Integer status;


[google-java-format] reported by reviewdog 🐶

@JsonProperty("detail")
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.")
private String detail;


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD stamp data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(max = 72)
@Schema(description = "Document hash type is stBase64Binary72 as described in https://github.com/pagopa/pagopa-api.", requiredMode = Schema.RequiredMode.REQUIRED)
// Stamp generally get as input a base64sha256, that is the SHA256 hash of a given string encoded with Base64.
// It is not equivalent to base64encode(sha256(“test”)), if sha256() returns a hexadecimal representation.
// The result should normally be 44 characters, to be compliant with as-is it was extended to 72
private String hashDocument;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(min = 2, max = 2)
@Schema(description = "The type of the stamp", minLength = 2, maxLength = 2, requiredMode = Schema.RequiredMode.REQUIRED)
private String stampType;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Pattern(regexp = "[A-Z]{2}")
@Schema(description = "The province of residence", example = "RM", pattern = "[A-Z]{2,2}", requiredMode = Schema.RequiredMode.REQUIRED)
private String provincialResidence;
}


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD transfer data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank(message = "id transfer is required")
@Schema(description = "Transfer's id", allowableValues = {"1", "2", "3", "4", "5"}, requiredMode = Schema.RequiredMode.REQUIRED)
private String idTransfer;


[google-java-format] reported by reviewdog 🐶

@NotNull(message = "amount is required")
@Schema(description = "Transfer's amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;


[google-java-format] reported by reviewdog 🐶

@Schema(description = "Fiscal code related to the organization targeted by this transfer.", example = "00000000000")
private String organizationFiscalCode;


[google-java-format] reported by reviewdog 🐶

@NotBlank(message = "remittance information is required")
@Size(max = 140, message = "remittance information must be compliant to EACT FORMATTING RULES, up to 140 chars")
@Schema(description = "Transfer's remittance information", requiredMode = Schema.RequiredMode.REQUIRED)
// https://docs.pagopa.it/saci/specifiche-attuative-dei-codici-identificativi-di-versamento-riversamento-e-rendicontazione/operazione-di-trasferimento-fondi
private String remittanceInformation; // causale


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "Transfer's stamp", requiredMode = Schema.RequiredMode.REQUIRED)
private Stamp stamp;
}


[google-java-format] reported by reviewdog 🐶

public static final String HEADER_REQUEST_ID = "X-Request-Id";


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertTrue;


[google-java-format] reported by reviewdog 🐶

@Test
void contextLoads() {
// check only if the context is loaded
assertTrue(true);
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void swaggerSpringPlugin() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())
.andDo(
result -> {
assertNotNull(result);
assertNotNull(result.getResponse());
final String content = result.getResponse().getContentAsString();
assertFalse(content.isBlank());
assertFalse(content.contains("${"), "Generated swagger contains placeholders");
Object swagger =
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class);
String formatted =
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger);
Path basePath = Paths.get("openapi/");
Files.createDirectories(basePath);
Files.write(basePath.resolve("openapi.json"), formatted.getBytes());
});
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void healthCheckTestSuccess() throws Exception {
mvc.perform(get("/info")).andExpect(status().isOk());
}
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties;
import it.gov.pagopa.mbd.gps.service.model.PaymentOption;


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶

@Autowired
private MockMvc mvc;
@Autowired
private ObjectMapper objectMapper;
@Test
void createMdbPaymentOptionTestSuccess() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
MvcResult result = mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andReturn();
String json = result.getResponse().getContentAsString();
assertNotNull(json);
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class);
assertNotNull(response);
assertNotNull(response.getPaymentOption());
assertEquals(1, response.getPaymentOption().size());
PaymentOption paymentOption = response.getPaymentOption().get(0);
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName());
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName());
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount());
assertNotNull(paymentOption.getDescription());
assertNotNull(paymentOption.getDueDate());
assertNotNull(paymentOption.getRetentionDate());
assertFalse(paymentOption.getIsPartialPayment());
assertNotNull(paymentOption.getTransfer());
assertEquals(1, paymentOption.getTransfer().size());
Transfer transfer = paymentOption.getTransfer().get(0);
assertEquals(request.getProperties().getAmount(), transfer.getAmount());
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode());
assertEquals("1", transfer.getIdTransfer());
assertNotNull(transfer.getRemittanceInformation());
assertNotNull(transfer.getStamp());
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence());
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument());
assertEquals("st", transfer.getStamp().getStampType());
}
@Test
void createMdbPaymentOptionTestFailAmountMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setAmount(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFirstName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setLastName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFiscalCode(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setProvincialResidence(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash("asdfsdf");
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() {
return MbdPaymentOptionRequest.builder()
.properties(MbdPaymentOptionRequestProperties.builder()
.amount(16L)
.firstName("Mario")
.lastName("Rossi")
.fiscalCode("0000000000000000")
.provincialResidence("AS")
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB")
.build())
.build();
}
}

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

google-java-format

[google-java-format] reported by reviewdog 🐶

/**
* Handle if validation constraints are unsatisfied
*
* @param ex {@link MethodArgumentNotValidException} exception raised
* @param headers of the response
* @param status of the response
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
List<String> details = new ArrayList<>();
for (FieldError error : ex.getBindingResult().getFieldErrors()) {
details.add(error.getField() + ": " + error.getDefaultMessage());
}
var detailsMessage = String.join(", ", details);
log.warn("Input not valid: " + detailsMessage);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(detailsMessage)
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}


[google-java-format] reported by reviewdog 🐶

@ExceptionHandler({ConstraintViolationException.class})
public ResponseEntity<ProblemJson> handleConstraintViolationException(
final ConstraintViolationException ex,
final WebRequest request
) {
log.warn("Validation Error raised:", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.BAD_REQUEST.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

/**
* Handle if a {@link AppException} is raised
*
* @param ex {@link AppException} exception raised
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with an appropriated HTTP status
*/
@ExceptionHandler({AppException.class})
public ResponseEntity<ProblemJson> handleAppException(
final AppException ex,
final WebRequest request
) {
if (ex.getCause() != null) {
log.warn("App Exception raised: {}\nCause of the App Exception: ", ex.getMessage(), ex.getCause());
} else {
log.warn("App Exception raised: ", ex);
}
var errorResponse = ProblemJson.builder()
.status(ex.getHttpStatus().value())
.title(ex.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, ex.getHttpStatus());
}
/**
* Handle if a {@link Exception} is raised
*
* @param ex {@link Exception} exception raised
* @param request from frontend
* @return a {@link ProblemJson} as response with the cause and with 500 as HTTP status
*/
@ExceptionHandler({Exception.class})
public ResponseEntity<ProblemJson> handleGenericException(
final Exception ex,
final WebRequest request
) {
log.error("Generic Exception raised:", ex);
var errorResponse = ProblemJson.builder()
.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
.title(AppError.INTERNAL_SERVER_ERROR.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties;
import it.gov.pagopa.mbd.gps.service.model.PaymentOption;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;


[google-java-format] reported by reviewdog 🐶

* Converter class that specify how to convert a {@link MbdPaymentOptionRequest} instance to a {@link MbdPaymentOptionResponse} instance


[google-java-format] reported by reviewdog 🐶

public class ConvertMbdPaymentOptionRequestToMbdPaymentOptionResponse implements Converter<MbdPaymentOptionRequest, MbdPaymentOptionResponse> {


[google-java-format] reported by reviewdog 🐶

private static final boolean IS_PARTIAL_PAYMENT = false;
private static final String ID_TRANSFER = "1";
private static final String STAMP_TYPE = "st";


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.transfer.remittance-information}")
private String remittanceInformation;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.due-date-delta-time-unit}")
private ChronoUnit dueDateDeltaTimeUnit;


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.retention-date-delta}")
private int retentionDateDelta;


[google-java-format] reported by reviewdog 🐶

@Value("${mbd.payment-option.retention-date-delta-time-unit}")
private ChronoUnit retentionDateDeltaTimeUnit;


[google-java-format] reported by reviewdog 🐶

@Override
public MbdPaymentOptionResponse convert(MappingContext<MbdPaymentOptionRequest, MbdPaymentOptionResponse> context) {
MbdPaymentOptionRequestProperties model = context.getSource().getProperties();


[google-java-format] reported by reviewdog 🐶

Transfer transfer = Transfer.builder()
.amount(model.getAmount())
.idTransfer(ID_TRANSFER)
.organizationFiscalCode(model.getFiscalCode())
.remittanceInformation(remittanceInformation)
.stamp(Stamp.builder()
.hashDocument(model.getDocumentHash())
.provincialResidence(model.getProvincialResidence())
.stampType(STAMP_TYPE)
.build())
.build();


[google-java-format] reported by reviewdog 🐶

PaymentOption paymentOption = PaymentOption.builder()
.firstName(model.getFirstName())
.lastName(model.getLastName())
.amount(model.getAmount())
.description(description)
.dueDate(LocalDateTime.now().plus(dueDateDelta, dueDateDeltaTimeUnit))
.retentionDate(LocalDateTime.now().plus(retentionDateDelta, retentionDateDeltaTimeUnit))
.isPartialPayment(IS_PARTIAL_PAYMENT)
.transfer(Collections.singletonList(transfer))
.build();


[google-java-format] reported by reviewdog 🐶

return MbdPaymentOptionResponse.builder()
.paymentOption(Collections.singletonList(paymentOption))
.build();
}
}


[google-java-format] reported by reviewdog 🐶

private String[] origins;
private String[] methods;


[google-java-format] reported by reviewdog 🐶

private String name;
private String version;
private String environment;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "MBD payment option's properties", requiredMode = Schema.RequiredMode.REQUIRED)
private MbdPaymentOptionRequestProperties properties;
}


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD service specific data
*/


[google-java-format] reported by reviewdog 🐶

@NotNull(message = "amount is required")
@Schema(description = "MBD amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED)
private String firstName;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED)
private String lastName;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's fiscal code", requiredMode = Schema.RequiredMode.REQUIRED)
private String fiscalCode;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's residence province", requiredMode = Schema.RequiredMode.REQUIRED)
private String provincialResidence;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(min = 44, max = 44)
@Schema(description = "MBD document's hash", requiredMode = Schema.RequiredMode.REQUIRED)
private String documentHash;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.util.List;
/**
* Model class that holds MBD GPS response
*/


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "MBD payment option", requiredMode = Schema.RequiredMode.REQUIRED)
private List<@Valid PaymentOption> paymentOption;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.time.LocalDateTime;
import java.util.List;
/**
* Model class that holds MBD payment option data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED)
private String firstName;
@NotBlank
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED)
private String lastName;
@NotNull(message = "amount is required")
@Schema(description = "Payment option's amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;
@NotBlank(message = "payment option description is required")
@Size(max = 140) // compliant to paForNode.xsd
@Schema(description = "Payment option's description", requiredMode = Schema.RequiredMode.REQUIRED)
private String description;
@NotNull(message = "is partial payment is required")
@Schema(description = "Payment option's is partial payment flag", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean isPartialPayment;
@NotNull(message = "due date is required")
@Schema(description = "Payment option's due date", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime dueDate;
@Schema(description = "Payment option's retention date", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime retentionDate;
@Valid
@Schema(description = "Payment option's transfer list", requiredMode = Schema.RequiredMode.REQUIRED)
private List<@Valid Transfer> transfer;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@JsonProperty("title")
@Schema(description = "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable")
private String title;


[google-java-format] reported by reviewdog 🐶

@JsonProperty("status")
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.")
@Min(100)
@Max(600)
private Integer status;


[google-java-format] reported by reviewdog 🐶

@JsonProperty("detail")
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.")
private String detail;


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD stamp data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(max = 72)
@Schema(description = "Document hash type is stBase64Binary72 as described in https://github.com/pagopa/pagopa-api.", requiredMode = Schema.RequiredMode.REQUIRED)
// Stamp generally get as input a base64sha256, that is the SHA256 hash of a given string encoded with Base64.
// It is not equivalent to base64encode(sha256(“test”)), if sha256() returns a hexadecimal representation.
// The result should normally be 44 characters, to be compliant with as-is it was extended to 72
private String hashDocument;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(min = 2, max = 2)
@Schema(description = "The type of the stamp", minLength = 2, maxLength = 2, requiredMode = Schema.RequiredMode.REQUIRED)
private String stampType;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Pattern(regexp = "[A-Z]{2}")
@Schema(description = "The province of residence", example = "RM", pattern = "[A-Z]{2,2}", requiredMode = Schema.RequiredMode.REQUIRED)
private String provincialResidence;
}


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD transfer data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank(message = "id transfer is required")
@Schema(description = "Transfer's id", allowableValues = {"1", "2", "3", "4", "5"}, requiredMode = Schema.RequiredMode.REQUIRED)
private String idTransfer;


[google-java-format] reported by reviewdog 🐶

@NotNull(message = "amount is required")
@Schema(description = "Transfer's amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;


[google-java-format] reported by reviewdog 🐶

@Schema(description = "Fiscal code related to the organization targeted by this transfer.", example = "00000000000")
private String organizationFiscalCode;


[google-java-format] reported by reviewdog 🐶

@NotBlank(message = "remittance information is required")
@Size(max = 140, message = "remittance information must be compliant to EACT FORMATTING RULES, up to 140 chars")
@Schema(description = "Transfer's remittance information", requiredMode = Schema.RequiredMode.REQUIRED)
// https://docs.pagopa.it/saci/specifiche-attuative-dei-codici-identificativi-di-versamento-riversamento-e-rendicontazione/operazione-di-trasferimento-fondi
private String remittanceInformation; // causale


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "Transfer's stamp", requiredMode = Schema.RequiredMode.REQUIRED)
private Stamp stamp;
}


[google-java-format] reported by reviewdog 🐶

public static final String HEADER_REQUEST_ID = "X-Request-Id";


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertTrue;


[google-java-format] reported by reviewdog 🐶

@Test
void contextLoads() {
// check only if the context is loaded
assertTrue(true);
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void swaggerSpringPlugin() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())
.andDo(
result -> {
assertNotNull(result);
assertNotNull(result.getResponse());
final String content = result.getResponse().getContentAsString();
assertFalse(content.isBlank());
assertFalse(content.contains("${"), "Generated swagger contains placeholders");
Object swagger =
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class);
String formatted =
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger);
Path basePath = Paths.get("openapi/");
Files.createDirectories(basePath);
Files.write(basePath.resolve("openapi.json"), formatted.getBytes());
});
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void healthCheckTestSuccess() throws Exception {
mvc.perform(get("/info")).andExpect(status().isOk());
}
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties;
import it.gov.pagopa.mbd.gps.service.model.PaymentOption;


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶

@Autowired
private MockMvc mvc;
@Autowired
private ObjectMapper objectMapper;
@Test
void createMdbPaymentOptionTestSuccess() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
MvcResult result = mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andReturn();
String json = result.getResponse().getContentAsString();
assertNotNull(json);
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class);
assertNotNull(response);
assertNotNull(response.getPaymentOption());
assertEquals(1, response.getPaymentOption().size());
PaymentOption paymentOption = response.getPaymentOption().get(0);
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName());
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName());
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount());
assertNotNull(paymentOption.getDescription());
assertNotNull(paymentOption.getDueDate());
assertNotNull(paymentOption.getRetentionDate());
assertFalse(paymentOption.getIsPartialPayment());
assertNotNull(paymentOption.getTransfer());
assertEquals(1, paymentOption.getTransfer().size());
Transfer transfer = paymentOption.getTransfer().get(0);
assertEquals(request.getProperties().getAmount(), transfer.getAmount());
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode());
assertEquals("1", transfer.getIdTransfer());
assertNotNull(transfer.getRemittanceInformation());
assertNotNull(transfer.getStamp());
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence());
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument());
assertEquals("st", transfer.getStamp().getStampType());
}
@Test
void createMdbPaymentOptionTestFailAmountMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setAmount(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFirstName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setLastName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFiscalCode(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setProvincialResidence(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash("asdfsdf");
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() {
return MbdPaymentOptionRequest.builder()
.properties(MbdPaymentOptionRequestProperties.builder()
.amount(16L)
.firstName("Mario")
.lastName("Rossi")
.fiscalCode("0000000000000000")
.provincialResidence("AS")
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB")
.build())
.build();
}
}

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

google-java-format

[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED)
private String lastName;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's fiscal code", requiredMode = Schema.RequiredMode.REQUIRED)
private String fiscalCode;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's residence province", requiredMode = Schema.RequiredMode.REQUIRED)
private String provincialResidence;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(min = 44, max = 44)
@Schema(description = "MBD document's hash", requiredMode = Schema.RequiredMode.REQUIRED)
private String documentHash;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.util.List;
/**
* Model class that holds MBD GPS response
*/


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "MBD payment option", requiredMode = Schema.RequiredMode.REQUIRED)
private List<@Valid PaymentOption> paymentOption;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.time.LocalDateTime;
import java.util.List;
/**
* Model class that holds MBD payment option data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED)
private String firstName;
@NotBlank
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED)
private String lastName;
@NotNull(message = "amount is required")
@Schema(description = "Payment option's amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;
@NotBlank(message = "payment option description is required")
@Size(max = 140) // compliant to paForNode.xsd
@Schema(description = "Payment option's description", requiredMode = Schema.RequiredMode.REQUIRED)
private String description;
@NotNull(message = "is partial payment is required")
@Schema(description = "Payment option's is partial payment flag", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean isPartialPayment;
@NotNull(message = "due date is required")
@Schema(description = "Payment option's due date", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime dueDate;
@Schema(description = "Payment option's retention date", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime retentionDate;
@Valid
@Schema(description = "Payment option's transfer list", requiredMode = Schema.RequiredMode.REQUIRED)
private List<@Valid Transfer> transfer;
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@JsonProperty("title")
@Schema(description = "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable")
private String title;


[google-java-format] reported by reviewdog 🐶

@JsonProperty("status")
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.")
@Min(100)
@Max(600)
private Integer status;


[google-java-format] reported by reviewdog 🐶

@JsonProperty("detail")
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.")
private String detail;


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD stamp data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(max = 72)
@Schema(description = "Document hash type is stBase64Binary72 as described in https://github.com/pagopa/pagopa-api.", requiredMode = Schema.RequiredMode.REQUIRED)
// Stamp generally get as input a base64sha256, that is the SHA256 hash of a given string encoded with Base64.
// It is not equivalent to base64encode(sha256(“test”)), if sha256() returns a hexadecimal representation.
// The result should normally be 44 characters, to be compliant with as-is it was extended to 72
private String hashDocument;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Size(min = 2, max = 2)
@Schema(description = "The type of the stamp", minLength = 2, maxLength = 2, requiredMode = Schema.RequiredMode.REQUIRED)
private String stampType;


[google-java-format] reported by reviewdog 🐶

@NotBlank
@Pattern(regexp = "[A-Z]{2}")
@Schema(description = "The province of residence", example = "RM", pattern = "[A-Z]{2,2}", requiredMode = Schema.RequiredMode.REQUIRED)
private String provincialResidence;
}


[google-java-format] reported by reviewdog 🐶

/**
* Model class that holds MBD transfer data
*/


[google-java-format] reported by reviewdog 🐶

@NotBlank(message = "id transfer is required")
@Schema(description = "Transfer's id", allowableValues = {"1", "2", "3", "4", "5"}, requiredMode = Schema.RequiredMode.REQUIRED)
private String idTransfer;


[google-java-format] reported by reviewdog 🐶

@NotNull(message = "amount is required")
@Schema(description = "Transfer's amount", requiredMode = Schema.RequiredMode.REQUIRED)
private Long amount;


[google-java-format] reported by reviewdog 🐶

@Schema(description = "Fiscal code related to the organization targeted by this transfer.", example = "00000000000")
private String organizationFiscalCode;


[google-java-format] reported by reviewdog 🐶

@NotBlank(message = "remittance information is required")
@Size(max = 140, message = "remittance information must be compliant to EACT FORMATTING RULES, up to 140 chars")
@Schema(description = "Transfer's remittance information", requiredMode = Schema.RequiredMode.REQUIRED)
// https://docs.pagopa.it/saci/specifiche-attuative-dei-codici-identificativi-di-versamento-riversamento-e-rendicontazione/operazione-di-trasferimento-fondi
private String remittanceInformation; // causale


[google-java-format] reported by reviewdog 🐶

@Valid
@Schema(description = "Transfer's stamp", requiredMode = Schema.RequiredMode.REQUIRED)
private Stamp stamp;
}


[google-java-format] reported by reviewdog 🐶

public static final String HEADER_REQUEST_ID = "X-Request-Id";


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertTrue;


[google-java-format] reported by reviewdog 🐶

@Test
void contextLoads() {
// check only if the context is loaded
assertTrue(true);
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void swaggerSpringPlugin() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())
.andDo(
result -> {
assertNotNull(result);
assertNotNull(result.getResponse());
final String content = result.getResponse().getContentAsString();
assertFalse(content.isBlank());
assertFalse(content.contains("${"), "Generated swagger contains placeholders");
Object swagger =
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class);
String formatted =
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger);
Path basePath = Paths.get("openapi/");
Files.createDirectories(basePath);
Files.write(basePath.resolve("openapi.json"), formatted.getBytes());
});
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void healthCheckTestSuccess() throws Exception {
mvc.perform(get("/info")).andExpect(status().isOk());
}
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties;
import it.gov.pagopa.mbd.gps.service.model.PaymentOption;


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶

@Autowired
private MockMvc mvc;
@Autowired
private ObjectMapper objectMapper;
@Test
void createMdbPaymentOptionTestSuccess() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
MvcResult result = mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andReturn();
String json = result.getResponse().getContentAsString();
assertNotNull(json);
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class);
assertNotNull(response);
assertNotNull(response.getPaymentOption());
assertEquals(1, response.getPaymentOption().size());
PaymentOption paymentOption = response.getPaymentOption().get(0);
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName());
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName());
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount());
assertNotNull(paymentOption.getDescription());
assertNotNull(paymentOption.getDueDate());
assertNotNull(paymentOption.getRetentionDate());
assertFalse(paymentOption.getIsPartialPayment());
assertNotNull(paymentOption.getTransfer());
assertEquals(1, paymentOption.getTransfer().size());
Transfer transfer = paymentOption.getTransfer().get(0);
assertEquals(request.getProperties().getAmount(), transfer.getAmount());
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode());
assertEquals("1", transfer.getIdTransfer());
assertNotNull(transfer.getRemittanceInformation());
assertNotNull(transfer.getStamp());
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence());
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument());
assertEquals("st", transfer.getStamp().getStampType());
}
@Test
void createMdbPaymentOptionTestFailAmountMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setAmount(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFirstName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setLastName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFiscalCode(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setProvincialResidence(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash("asdfsdf");
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() {
return MbdPaymentOptionRequest.builder()
.properties(MbdPaymentOptionRequestProperties.builder()
.amount(16L)
.firstName("Mario")
.lastName("Rossi")
.fiscalCode("0000000000000000")
.provincialResidence("AS")
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB")
.build())
.build();
}
}

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

google-java-format

[google-java-format] reported by reviewdog 🐶

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void swaggerSpringPlugin() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())
.andDo(
result -> {
assertNotNull(result);
assertNotNull(result.getResponse());
final String content = result.getResponse().getContentAsString();
assertFalse(content.isBlank());
assertFalse(content.contains("${"), "Generated swagger contains placeholders");
Object swagger =
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class);
String formatted =
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger);
Path basePath = Paths.get("openapi/");
Files.createDirectories(basePath);
Files.write(basePath.resolve("openapi.json"), formatted.getBytes());
});
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

@Test
void healthCheckTestSuccess() throws Exception {
mvc.perform(get("/info")).andExpect(status().isOk());
}
}


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties;
import it.gov.pagopa.mbd.gps.service.model.PaymentOption;


[google-java-format] reported by reviewdog 🐶

import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse;


[google-java-format] reported by reviewdog 🐶


[google-java-format] reported by reviewdog 🐶

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


[google-java-format] reported by reviewdog 🐶

@Autowired
private MockMvc mvc;
@Autowired
private ObjectMapper objectMapper;
@Test
void createMdbPaymentOptionTestSuccess() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
MvcResult result = mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andReturn();
String json = result.getResponse().getContentAsString();
assertNotNull(json);
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class);
assertNotNull(response);
assertNotNull(response.getPaymentOption());
assertEquals(1, response.getPaymentOption().size());
PaymentOption paymentOption = response.getPaymentOption().get(0);
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName());
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName());
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount());
assertNotNull(paymentOption.getDescription());
assertNotNull(paymentOption.getDueDate());
assertNotNull(paymentOption.getRetentionDate());
assertFalse(paymentOption.getIsPartialPayment());
assertNotNull(paymentOption.getTransfer());
assertEquals(1, paymentOption.getTransfer().size());
Transfer transfer = paymentOption.getTransfer().get(0);
assertEquals(request.getProperties().getAmount(), transfer.getAmount());
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode());
assertEquals("1", transfer.getIdTransfer());
assertNotNull(transfer.getRemittanceInformation());
assertNotNull(transfer.getStamp());
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence());
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument());
assertEquals("st", transfer.getStamp().getStampType());
}
@Test
void createMdbPaymentOptionTestFailAmountMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setAmount(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFirstName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setLastName(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setFiscalCode(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setProvincialResidence(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash(null);
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
@Test
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception {
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest();
request.getProperties().setDocumentHash("asdfsdf");
mvc.perform(post("/mbd/paymentOption")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() {
return MbdPaymentOptionRequest.builder()
.properties(MbdPaymentOptionRequestProperties.builder()
.amount(16L)
.firstName("Mario")
.lastName("Rossi")
.fiscalCode("0000000000000000")
.provincialResidence("AS")
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB")
.build())
.build();
}
}

Copy link
Contributor

github-actions bot commented Dec 4, 2024

This PR exceeds the recommended size of 400 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@pasqualespica pasqualespica self-requested a review December 4, 2024 15:41
Copy link
Contributor

@pasqualespica pasqualespica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work @gioelemella

@pasqualespica pasqualespica merged commit f89a64d into main Dec 4, 2024
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants