diff --git a/pom.xml b/pom.xml index a1b9723..e6e624a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ fr.ouestfrance.querydsl querydsl - 1.2.1-SNAPSHOT + 1.3.0-SNAPSHOT querydsl Unified queryDSL based on annotations https://github.com/ouest-france/querydsl diff --git a/src/main/java/fr/ouestfrance/querydsl/FilterOperation.java b/src/main/java/fr/ouestfrance/querydsl/FilterOperation.java index 57b4b38..d6c7c43 100644 --- a/src/main/java/fr/ouestfrance/querydsl/FilterOperation.java +++ b/src/main/java/fr/ouestfrance/querydsl/FilterOperation.java @@ -1,6 +1,7 @@ package fr.ouestfrance.querydsl; import fr.ouestfrance.querydsl.service.validators.ValidatedBy; +import fr.ouestfrance.querydsl.service.validators.impl.BooleanValidator; import fr.ouestfrance.querydsl.service.validators.impl.CollectionValidator; import fr.ouestfrance.querydsl.service.validators.impl.ComparableValidator; import fr.ouestfrance.querydsl.service.validators.impl.StringValidator; @@ -72,4 +73,11 @@ class IN implements FilterOperation { @ValidatedBy(CollectionValidator.class) class NOTIN implements FilterOperation { } + + /** + * Is null Operation + */ + @ValidatedBy(BooleanValidator.class) + class ISNULL implements FilterOperation { + } } diff --git a/src/main/java/fr/ouestfrance/querydsl/service/validators/impl/BooleanValidator.java b/src/main/java/fr/ouestfrance/querydsl/service/validators/impl/BooleanValidator.java new file mode 100644 index 0000000..49cca13 --- /dev/null +++ b/src/main/java/fr/ouestfrance/querydsl/service/validators/impl/BooleanValidator.java @@ -0,0 +1,20 @@ +package fr.ouestfrance.querydsl.service.validators.impl; + +import fr.ouestfrance.querydsl.service.validators.FilterFieldValidator; +import lombok.NoArgsConstructor; + +/** + * Validator that handle filter on Boolean + */ +@NoArgsConstructor +public class BooleanValidator implements FilterFieldValidator { + @Override + public boolean validate(Class clazz) { + return Boolean.class.isAssignableFrom(clazz); + } + + @Override + public String message() { + return "should be applied to Boolean"; + } +} diff --git a/src/test/java/fr/ouestfrance/querydsl/service/validators/impl/BooleanValidatorTest.java b/src/test/java/fr/ouestfrance/querydsl/service/validators/impl/BooleanValidatorTest.java new file mode 100644 index 0000000..66ff93e --- /dev/null +++ b/src/test/java/fr/ouestfrance/querydsl/service/validators/impl/BooleanValidatorTest.java @@ -0,0 +1,37 @@ +package fr.ouestfrance.querydsl.service.validators.impl; + +import fr.ouestfrance.querydsl.service.validators.FilterFieldValidator; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class BooleanValidatorTest { + + private final FilterFieldValidator validator = new BooleanValidator(); + @Test + void shouldValidate(){ + assertTrue(validator.validate(Boolean.class)); + } + + @Test + void shouldUnValidate(){ + assertFalse(validator.validate(String.class)); + assertFalse(validator.validate(Double.class)); + assertFalse(validator.validate(LocalDate.class)); + assertFalse(validator.validate(LocalDateTime.class)); + assertFalse(validator.validate(Date.class)); + assertFalse(validator.validate(UUID.class)); + assertFalse(validator.validate(Integer.class)); + assertFalse(validator.validate(BigDecimal.class)); + assertFalse(validator.validate(Set.class)); + assertFalse(validator.validate(ArrayList.class)); + assertFalse(validator.validate(LinkedList.class)); + assertFalse(validator.validate(HashSet.class)); + } +} diff --git a/src/test/java/fr/ouestfrance/querydsl/service/validators/impl/ComprableValidatorTest.java b/src/test/java/fr/ouestfrance/querydsl/service/validators/impl/ComparableValidatorTest.java similarity index 97% rename from src/test/java/fr/ouestfrance/querydsl/service/validators/impl/ComprableValidatorTest.java rename to src/test/java/fr/ouestfrance/querydsl/service/validators/impl/ComparableValidatorTest.java index 11e4d8a..bec4faf 100644 --- a/src/test/java/fr/ouestfrance/querydsl/service/validators/impl/ComprableValidatorTest.java +++ b/src/test/java/fr/ouestfrance/querydsl/service/validators/impl/ComparableValidatorTest.java @@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -class ComprableValidatorTest { +class ComparableValidatorTest { private final FilterFieldValidator validator = new ComparableValidator(); @Test