feat: CurrencyExchangeRequest with validator and validator's tests outline
This commit is contained in:
parent
5555e57f34
commit
ca2a6c1795
4 changed files with 111 additions and 0 deletions
|
@ -0,0 +1,24 @@
|
|||
package eu.ztsh.wymiana.validation;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({ TYPE_USE })
|
||||
@Documented
|
||||
@Constraint(validatedBy = {ValidExchangeRequestValidator.class })
|
||||
public @interface ValidExchangeRequest {
|
||||
|
||||
String message() default "Exchange request is not valid";
|
||||
Class<?>[] groups() default { };
|
||||
Class<? extends Payload>[] payload() default { };
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package eu.ztsh.wymiana.validation;
|
||||
|
||||
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
public class ValidExchangeRequestValidator implements ConstraintValidator<ValidExchangeRequest, CurrencyExchangeRequest> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(CurrencyExchangeRequest currencyExchangeRequest,
|
||||
ConstraintValidatorContext constraintValidatorContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package eu.ztsh.wymiana.web.model;
|
||||
|
||||
import eu.ztsh.wymiana.validation.ValidExchangeRequest;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Builder;
|
||||
import org.hibernate.validator.constraints.pl.PESEL;
|
||||
|
||||
@Builder
|
||||
@ValidExchangeRequest
|
||||
public record CurrencyExchangeRequest(
|
||||
@PESEL String pesel,
|
||||
@NotNull String from,
|
||||
@NotNull String to,
|
||||
Double toBuy,
|
||||
Double toSell
|
||||
) {
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package eu.ztsh.wymiana.validation;
|
||||
|
||||
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ValidExchangeRequestValidatorTest extends ValidatorTest<ValidExchangeRequestValidator, CurrencyExchangeRequest> {
|
||||
|
||||
protected ValidExchangeRequestValidatorTest() {
|
||||
super(new ValidExchangeRequestValidator());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Valid request with buy value specified")
|
||||
void validRequestWithBuyTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Valid request with sell value specified")
|
||||
void validRequestWithSellTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Invalid PESEL value")
|
||||
void invalidPeselTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("From and To have same value")
|
||||
void sameFromToTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Empty amounts")
|
||||
void emptyBuySellTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Both Buy and Sell params filled in")
|
||||
void bothFilledBuySellTest() {
|
||||
|
||||
}
|
||||
@Test
|
||||
@DisplayName("Negative amount value")
|
||||
void negativeAmountTest() {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue