diff --git a/src/org/kar/archidata/annotation/AnnotationTools.java b/src/org/kar/archidata/annotation/AnnotationTools.java index eb5ff5b..2534fef 100644 --- a/src/org/kar/archidata/annotation/AnnotationTools.java +++ b/src/org/kar/archidata/annotation/AnnotationTools.java @@ -24,6 +24,8 @@ import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.validation.constraints.DecimalMax; +import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; @@ -197,6 +199,22 @@ public class AnnotationTools { return (Checker[]) annotation; } + public static DecimalMin getConstraintsDecimalMin(final Field element) { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(DecimalMin.class); + if (annotation.length == 0) { + return null; + } + return ((DecimalMin) annotation[0]); + } + + public static DecimalMax getConstraintsDecimalMax(final Field element) { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(DecimalMax.class); + if (annotation.length == 0) { + return null; + } + return ((DecimalMax) annotation[0]); + } + public static Long getConstraintsMax(final Field element) { final Annotation[] annotation = element.getDeclaredAnnotationsByType(Max.class); if (annotation.length == 0) { diff --git a/src/org/kar/archidata/dataAccess/options/CheckJPA.java b/src/org/kar/archidata/dataAccess/options/CheckJPA.java index f615f9d..a3351db 100644 --- a/src/org/kar/archidata/dataAccess/options/CheckJPA.java +++ b/src/org/kar/archidata/dataAccess/options/CheckJPA.java @@ -30,6 +30,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jakarta.persistence.ManyToOne; +import jakarta.validation.constraints.DecimalMax; +import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.Size; public class CheckJPA implements CheckFunctionInterface { @@ -124,6 +126,60 @@ public class CheckJPA implements CheckFunctionInterface { final Class type = field.getType(); if (type == Long.class || type == long.class) { + final DecimalMax maxValueDecimal = AnnotationTools.getConstraintsDecimalMax(field); + if (maxValueDecimal != null) { + final long maxValue = Long.parseLong(maxValueDecimal.value()); + final boolean inclusive = maxValueDecimal.inclusive(); + add(fieldName, + ( + final DBAccess ioDb, + final String baseName, + final T data, + final List modifiedValue, + final QueryOptions options) -> { + final Object elem = field.get(data); + if (elem == null) { + return; + } + final Long elemTyped = (Long) elem; + if (inclusive) { + if (elemTyped > maxValue) { + throw new InputException(baseName + fieldName, + "Value too height max: " + maxValue); + } + } else if (elemTyped >= maxValue) { + throw new InputException(baseName + fieldName, + "Value too height max: " + maxValue); + } + }); + } + final DecimalMin minValueDecimal = AnnotationTools.getConstraintsDecimalMin(field); + if (minValueDecimal != null) { + final long minValue = Long.parseLong(minValueDecimal.value()); + final boolean inclusive = minValueDecimal.inclusive(); + add(fieldName, + ( + final DBAccess ioDb, + final String baseName, + final T data, + final List modifiedValue, + final QueryOptions options) -> { + final Object elem = field.get(data); + if (elem == null) { + return; + } + final Long elemTyped = (Long) elem; + if (inclusive) { + if (elemTyped < minValue) { + throw new InputException(baseName + fieldName, + "Value too Low min: " + minValue); + } + } else if (elemTyped <= minValue) { + throw new InputException(baseName + fieldName, + "Value too Low min: " + minValue); + } + }); + } final Long maxValue = AnnotationTools.getConstraintsMax(field); if (maxValue != null) { add(fieldName, @@ -190,6 +246,61 @@ public class CheckJPA implements CheckFunctionInterface { } } else if (type == Integer.class || type == int.class) { + final DecimalMax maxValueDecimal = AnnotationTools.getConstraintsDecimalMax(field); + if (maxValueDecimal != null) { + final int maxValue = Integer.parseInt(maxValueDecimal.value()); + final boolean inclusive = maxValueDecimal.inclusive(); + add(fieldName, + ( + final DBAccess ioDb, + final String baseName, + final T data, + final List modifiedValue, + final QueryOptions options) -> { + final Object elem = field.get(data); + if (elem == null) { + return; + } + final Integer elemTyped = (Integer) elem; + if (inclusive) { + if (elemTyped > maxValue) { + throw new InputException(baseName + fieldName, + "Value too height max: " + maxValue); + } + } else if (elemTyped >= maxValue) { + + throw new InputException(baseName + fieldName, + "Value too height max: " + maxValue); + } + }); + } + final DecimalMin minValueDecimal = AnnotationTools.getConstraintsDecimalMin(field); + if (minValueDecimal != null) { + final int minValue = Integer.parseInt(minValueDecimal.value()); + final boolean inclusive = minValueDecimal.inclusive(); + add(fieldName, + ( + final DBAccess ioDb, + final String baseName, + final T data, + final List modifiedValue, + final QueryOptions options) -> { + final Object elem = field.get(data); + if (elem == null) { + return; + } + final Integer elemTyped = (Integer) elem; + if (inclusive) { + if (elemTyped < minValue) { + throw new InputException(baseName + fieldName, + "Value too Low min: " + minValue); + } + } else if (elemTyped <= minValue) { + throw new InputException(baseName + fieldName, + "Value too Low min: " + minValue); + } + }); + } final Long maxValueRoot = AnnotationTools.getConstraintsMax(field); if (maxValueRoot != null) { final int maxValue = maxValueRoot.intValue(); @@ -276,6 +387,60 @@ public class CheckJPA implements CheckFunctionInterface { } else if (type == Boolean.class || type == boolean.class) { } else if (type == Float.class || type == float.class) { + final DecimalMax maxValueDecimal = AnnotationTools.getConstraintsDecimalMax(field); + if (maxValueDecimal != null) { + final float maxValue = Float.parseFloat(maxValueDecimal.value()); + final boolean inclusive = maxValueDecimal.inclusive(); + add(fieldName, + ( + final DBAccess ioDb, + final String baseName, + final T data, + final List modifiedValue, + final QueryOptions options) -> { + final Object elem = field.get(data); + if (elem == null) { + return; + } + final Float elemTyped = (Float) elem; + if (inclusive) { + if (elemTyped > maxValue) { + throw new InputException(baseName + fieldName, + "Value too height max: " + maxValue); + } + } else if (elemTyped >= maxValue) { + throw new InputException(baseName + fieldName, + "Value too height max: " + maxValue); + } + }); + } + final DecimalMin minValueDecimal = AnnotationTools.getConstraintsDecimalMin(field); + if (minValueDecimal != null) { + final float minValue = Float.parseFloat(minValueDecimal.value()); + final boolean inclusive = minValueDecimal.inclusive(); + add(fieldName, + ( + final DBAccess ioDb, + final String baseName, + final T data, + final List modifiedValue, + final QueryOptions options) -> { + final Object elem = field.get(data); + if (elem == null) { + return; + } + final Float elemTyped = (Float) elem; + if (inclusive) { + if (elemTyped < minValue) { + throw new InputException(baseName + fieldName, + "Value too Low min: " + minValue); + } + } else if (elemTyped <= minValue) { + throw new InputException(baseName + fieldName, + "Value too Low min: " + minValue); + } + }); + } final Long maxValueRoot = AnnotationTools.getConstraintsMax(field); if (maxValueRoot != null) { final float maxValue = maxValueRoot.floatValue(); @@ -291,6 +456,7 @@ public class CheckJPA implements CheckFunctionInterface { return; } final Float elemTyped = (Float) elem; + if (elemTyped > maxValue) { throw new InputException(baseName + fieldName, "Value too height max: " + maxValue); @@ -319,6 +485,60 @@ public class CheckJPA implements CheckFunctionInterface { }); } } else if (type == Double.class || type == double.class) { + final DecimalMax maxValueDecimal = AnnotationTools.getConstraintsDecimalMax(field); + if (maxValueDecimal != null) { + final double maxValue = Float.parseFloat(maxValueDecimal.value()); + final boolean inclusive = maxValueDecimal.inclusive(); + add(fieldName, + ( + final DBAccess ioDb, + final String baseName, + final T data, + final List modifiedValue, + final QueryOptions options) -> { + final Object elem = field.get(data); + if (elem == null) { + return; + } + final Double elemTyped = (Double) elem; + if (inclusive) { + if (elemTyped > maxValue) { + throw new InputException(baseName + fieldName, + "Value too height max: " + maxValue); + } + } else if (elemTyped >= maxValue) { + throw new InputException(baseName + fieldName, + "Value too height max: " + maxValue); + } + }); + } + final DecimalMin minValueDecimal = AnnotationTools.getConstraintsDecimalMin(field); + if (minValueDecimal != null) { + final double minValue = Float.parseFloat(minValueDecimal.value()); + final boolean inclusive = minValueDecimal.inclusive(); + add(fieldName, + ( + final DBAccess ioDb, + final String baseName, + final T data, + final List modifiedValue, + final QueryOptions options) -> { + final Object elem = field.get(data); + if (elem == null) { + return; + } + final Double elemTyped = (Double) elem; + if (inclusive) { + if (elemTyped < minValue) { + throw new InputException(baseName + fieldName, + "Value too Low min: " + minValue); + } + } else if (elemTyped <= minValue) { + throw new InputException(baseName + fieldName, + "Value too Low min: " + minValue); + } + }); + } final Long maxValueRoot = AnnotationTools.getConstraintsMax(field); if (maxValueRoot != null) { final double maxValue = maxValueRoot.doubleValue(); diff --git a/test/src/test/kar/archidata/checker/TestJPACheckerDecimalMax.java b/test/src/test/kar/archidata/checker/TestJPACheckerDecimalMax.java new file mode 100644 index 0000000..f77cd00 --- /dev/null +++ b/test/src/test/kar/archidata/checker/TestJPACheckerDecimalMax.java @@ -0,0 +1,240 @@ +package test.kar.archidata.checker; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.kar.archidata.exception.InputException; + +import test.kar.archidata.checker.model.JpaBaseModel; +import test.kar.archidata.checker.model.JpaBaseModel.JpaBaseModelChecker; + +public class TestJPACheckerDecimalMax { + + @Test + public void testDecimalMaxIncludeInteger() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxIncludeInteger = 75; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeInteger = 74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeInteger = 76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxIncludeInteger = 100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxIncludeIntegerObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxIncludeIntegerObject = 75; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeIntegerObject = 74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeIntegerObject = 76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxIncludeIntegerObject = 100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxIncludeLong() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxIncludeLong = 75; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeLong = 74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeLong = 76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxIncludeLong = 100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxIncludeLongObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxIncludeLongObject = 75L; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeLongObject = 74L; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeLongObject = 76L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxIncludeLongObject = 100L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxIncludeFloat() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + // can not be tested + //data.testDecimalMaxIncludeFloat = 75.56f; + //Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeFloat = 75.5599f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeFloat = 75.5601f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxIncludeFloat = 100f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxIncludeFloatObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxIncludeFloatObject = 75.56f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeFloatObject = 75.5599f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeFloatObject = 75.5601f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxIncludeFloatObject = 100f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxIncludeDouble() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + // can not be tested + //data.testDecimalMaxIncludeDouble = 75.56d; + //Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeDouble = 75.5599d; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeDouble = 75.5601d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxIncludeDouble = 100d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxIncludeDoubleObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + //data.testDecimalMaxIncludeDoubleObject = 75.56d; + //Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeDoubleObject = 75.5599d; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxIncludeDoubleObject = 75.5601d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxIncludeDoubleObject = 100d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + // exclude + + @Test + public void testDecimalMaxExcludeInteger() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxExcludeInteger = 75; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeInteger = 74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxExcludeInteger = 76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeInteger = 100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxExcludeIntegerObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxExcludeIntegerObject = 75; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeIntegerObject = 74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxExcludeIntegerObject = 76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeIntegerObject = 100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxExcludeLong() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxExcludeLong = 75; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeLong = 74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxExcludeLong = 76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeLong = 100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxExcludeLongObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxExcludeLongObject = 75L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeLongObject = 74L; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxExcludeLongObject = 76L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeLongObject = 100L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxExcludeFloat() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxExcludeFloat = 75.56f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeFloat = 75.5599f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxExcludeFloat = 75.5601f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeFloat = 100f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxExcludeFloatObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxExcludeFloatObject = 75.56f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeFloatObject = 75.5599f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxExcludeFloatObject = 75.5601f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeFloatObject = 100f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxExcludeDouble() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxExcludeDouble = 75.56d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeDouble = 75.5599d; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxExcludeDouble = 75.5601d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeDouble = 100d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMaxExcludeDoubleObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMaxExcludeDoubleObject = 75.56d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeDoubleObject = 75.5599d; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMaxExcludeDoubleObject = 75.5601d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMaxExcludeDoubleObject = 100d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + +} diff --git a/test/src/test/kar/archidata/checker/TestJPACheckerDecimalMin.java b/test/src/test/kar/archidata/checker/TestJPACheckerDecimalMin.java new file mode 100644 index 0000000..cc2d78b --- /dev/null +++ b/test/src/test/kar/archidata/checker/TestJPACheckerDecimalMin.java @@ -0,0 +1,240 @@ +package test.kar.archidata.checker; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.kar.archidata.exception.InputException; + +import test.kar.archidata.checker.model.JpaBaseModel; +import test.kar.archidata.checker.model.JpaBaseModel.JpaBaseModelChecker; + +public class TestJPACheckerDecimalMin { + + @Test + public void testDecimalMinIncludeInteger() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinIncludeInteger = -75; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeInteger = -74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeInteger = -76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinIncludeInteger = -100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinIncludeIntegerObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinIncludeIntegerObject = -75; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeIntegerObject = -74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeIntegerObject = -76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinIncludeIntegerObject = -100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinIncludeLong() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinIncludeLong = -75; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeLong = -74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeLong = -76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinIncludeLong = -100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinIncludeLongObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinIncludeLongObject = -75L; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeLongObject = -74L; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeLongObject = -76L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinIncludeLongObject = -100L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinIncludeFloat() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinIncludeFloat = -75.56f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeFloat = -75.5599f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeFloat = -75.5601f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinIncludeFloat = -100f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinIncludeFloatObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinIncludeFloatObject = -75.56f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeFloatObject = -75.5599f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeFloatObject = -75.5601f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinIncludeFloatObject = -100f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinIncludeDouble() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + // can not be tested + //data.testDecimalMinIncludeDouble = -75.56d; + //Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeDouble = -75.5599d; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeDouble = -75.5601d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinIncludeDouble = -100d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinIncludeDoubleObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + // can not be tested + //data.testDecimalMinIncludeDoubleObject = -75.56d; + //Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeDoubleObject = -75.5599d; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinIncludeDoubleObject = -75.5601d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinIncludeDoubleObject = -100d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + // exclude + + @Test + public void testDecimalMinExcludeInteger() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinExcludeInteger = -75; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeInteger = -74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinExcludeInteger = -76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeInteger = -100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinExcludeIntegerObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinExcludeIntegerObject = -75; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeIntegerObject = -74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinExcludeIntegerObject = -76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeIntegerObject = -100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinExcludeLong() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinExcludeLong = -75; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeLong = -74; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinExcludeLong = -76; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeLong = -100; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinExcludeLongObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinExcludeLongObject = -75L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeLongObject = -74L; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinExcludeLongObject = -76L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeLongObject = -100L; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinExcludeFloat() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinExcludeFloat = -75.56f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeFloat = -75.5599f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinExcludeFloat = -75.5601f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeFloat = -100f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinExcludeFloatObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinExcludeFloatObject = -75.56f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeFloatObject = -75.5599f; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinExcludeFloatObject = -75.5601f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeFloatObject = -100f; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinExcludeDouble() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinExcludeDouble = -75.56d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeDouble = -75.5599d; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinExcludeDouble = -75.5601d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeDouble = -100d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + + @Test + public void testDecimalMinExcludeDoubleObject() throws Exception { + final JpaBaseModelChecker checker = new JpaBaseModelChecker(); + final JpaBaseModel data = new JpaBaseModel(); + data.testDecimalMinExcludeDoubleObject = -75.56d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeDoubleObject = -75.5599d; + Assertions.assertDoesNotThrow(() -> checker.check(data)); + data.testDecimalMinExcludeDoubleObject = -75.5601d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + data.testDecimalMinExcludeDoubleObject = -100d; + Assertions.assertThrows(InputException.class, () -> checker.check(data)); + } + +}