use of jakarta.validation.constraints.DecimalMax in project eclipselink by eclipse-ee4j.
the class BeanValidationBindingsTestCase method testAllFacetsAndAnnotations.
/**
* Tests that the XJC detects all facets and generates their respective
* annotations correctly.
*/
public void testAllFacetsAndAnnotations() throws Throwable {
pkg = "rs";
Class<?>[] c = roundTrip(RICH_SCHEMA_PATH, pkg);
Class<?> Main = c[0];
Class<?> Numbers = c[1];
Class<?> NumberWithHiddenValueAttribute = c[2];
Class<?> Strings = c[4];
XmlElement xmlElement;
Size size;
DecimalMax decimalMax;
DecimalMin decimalMin;
Pattern.List patternList;
Pattern pattern;
/* Main.class */
Field numbers = Main.getDeclaredField("numbers");
assertNotNull(numbers.getAnnotation(Valid.class));
assertNotNull(numbers.getAnnotation(NotNull.class));
xmlElement = numbers.getAnnotation(XmlElement.class);
assertFalse(xmlElement.nillable());
Field strings = Main.getDeclaredField("strings");
size = strings.getAnnotation(Size.class);
assertTrue(size.min() == 1 && size.max() == 2);
assertNotNull(strings.getAnnotation(Valid.class));
assertNotNull(strings.getAnnotation(NotNull.class));
xmlElement = strings.getAnnotation(XmlElement.class);
assertFalse(xmlElement.nillable());
Field unsignedByte = Main.getDeclaredField("unsignedByte");
decimalMax = unsignedByte.getAnnotation(DecimalMax.class);
assertEquals(decimalMax.value(), "255");
assertTrue(decimalMax.inclusive());
decimalMin = unsignedByte.getAnnotation(DecimalMin.class);
assertEquals(decimalMin.value(), "0");
assertTrue(decimalMin.inclusive());
Field byteArray = Main.getDeclaredField("byteArray");
size = byteArray.getAnnotation(Size.class);
assertTrue(size.max() == 18);
Field someCollection = Main.getDeclaredField("someCollection");
size = someCollection.getAnnotation(Size.class);
assertTrue(size.min() == 1);
assertNotNull(someCollection.getAnnotation(Valid.class));
assertNotNull(someCollection.getAnnotation(NotNull.class));
Field optionalElement = Main.getDeclaredField("optionalElement");
size = optionalElement.getAnnotation(Size.class);
assertTrue(size.min() == 0);
assertNotNull(optionalElement.getAnnotation(Valid.class));
assertNull(optionalElement.getAnnotation(NotNull.class));
Field optionalElementWithSimpleType = Main.getDeclaredField("optionalElementWithSimpleType");
assertNull(optionalElementWithSimpleType.getAnnotation(NotNull.class));
decimalMin = optionalElementWithSimpleType.getAnnotation(DecimalMin.class);
assertEquals(decimalMin.value(), "1");
decimalMax = optionalElementWithSimpleType.getAnnotation(DecimalMax.class);
assertEquals(decimalMax.value(), "31");
/* Numbers.class */
Field minInclusive = Numbers.getDeclaredField("minInclusive");
decimalMin = minInclusive.getAnnotation(DecimalMin.class);
assertEquals(decimalMin.value(), "1000");
assertTrue(decimalMin.inclusive());
Field maxInclusive = Numbers.getDeclaredField("maxInclusive");
decimalMax = maxInclusive.getAnnotation(DecimalMax.class);
assertEquals(decimalMax.value(), "1000");
assertTrue(decimalMax.inclusive());
Field minExclusive = Numbers.getDeclaredField("minExclusive");
decimalMin = minExclusive.getAnnotation(DecimalMin.class);
assertEquals(decimalMin.value(), "0");
assertFalse(decimalMin.inclusive());
Field maxExclusive = Numbers.getDeclaredField("maxExclusive");
decimalMax = maxExclusive.getAnnotation(DecimalMax.class);
assertEquals(decimalMax.value(), "1000");
assertFalse(decimalMax.inclusive());
Field minMaxExclusive = Numbers.getDeclaredField("minMaxExclusive");
decimalMax = minMaxExclusive.getAnnotation(DecimalMax.class);
assertEquals(decimalMax.value(), "9223372");
assertFalse(decimalMax.inclusive());
decimalMin = minMaxExclusive.getAnnotation(DecimalMin.class);
assertEquals(decimalMin.value(), "0");
assertFalse(decimalMin.inclusive());
/* NumberWithHiddenValueAttribute.class */
Field value = NumberWithHiddenValueAttribute.getDeclaredField("value");
assertNotNull(value.getAnnotation(XmlValue.class));
size = value.getAnnotation(Size.class);
assertTrue(size.min() == 1 && size.max() == 5);
Field code = NumberWithHiddenValueAttribute.getDeclaredField("code");
assertNotNull(code.getAnnotation(NotNull.class));
Field whatNumber = NumberWithHiddenValueAttribute.getDeclaredField("whatNumber");
XmlAttribute xmlAttribute = whatNumber.getAnnotation(XmlAttribute.class);
assertTrue(xmlAttribute.required());
/* Strings.class */
Field regexShorthands = Strings.getDeclaredField("regexShorthands");
patternList = regexShorthands.getAnnotation(Pattern.List.class);
Pattern[] patterns = patternList.value();
assertEquals("[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]", patterns[0].regexp());
assertEquals("[^:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]", patterns[1].regexp());
assertEquals("[-.0-9:A-Z_a-z\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]", patterns[2].regexp());
assertEquals("[^-.0-9:A-Z_a-z\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]", patterns[3].regexp());
assertEquals("\\p{Nd}", patterns[4].regexp());
assertEquals("\\P{Nd}", patterns[5].regexp());
assertEquals("[\\u0009-\\u000D\\u0020\\u0085\\u00A0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]", patterns[6].regexp());
assertEquals("[^\\u0009-\\u000D\\u0020\\u0085\\u00A0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]", patterns[7].regexp());
assertEquals("[\\u0009\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]", patterns[8].regexp());
assertEquals("[^\\u0009\\u0020\\u00A0\\u1680\\u180E\\u2000\\u2001-\\u200A\\u202F\\u205F\\u3000]", patterns[9].regexp());
assertEquals("[^\\u000A-\\u000D\\u0085\\u2028\\u2029]", patterns[10].regexp());
assertEquals("(?:(?>\\u000D\\u000A)|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029])", patterns[11].regexp());
Field idType = Strings.getDeclaredField("idType");
pattern = idType.getAnnotation(Pattern.class);
assertEquals(pattern.regexp(), "[[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]-[:]][[-.0-9:A-Z_a-z\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]-[:]]*");
assertTrue(idType.getAnnotation(Size.class).max() == 100);
Field genericString = Strings.getDeclaredField("genericString");
assertTrue(genericString.getAnnotation(Size.class).min() == 0);
assertTrue(genericString.getAnnotation(Size.class).max() == 1024);
Field maxLength = Strings.getDeclaredField("maxLength");
assertTrue(maxLength.getAnnotation(Size.class).max() == 1024);
Field minLength = Strings.getDeclaredField("minLength");
assertTrue(minLength.getAnnotation(Size.class).min() == 0);
}
use of jakarta.validation.constraints.DecimalMax in project hibernate-validator by hibernate.
the class MaxValidatorForNumberTest method testIsValidDecimalMaxExclusive.
@Test
@TestForIssue(jiraKey = "HV-256")
public void testIsValidDecimalMaxExclusive() {
boolean inclusive = false;
ConstraintAnnotationDescriptor.Builder<DecimalMax> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(DecimalMax.class);
descriptorBuilder.setAttribute("value", "15.0E0");
descriptorBuilder.setAttribute("inclusive", inclusive);
descriptorBuilder.setMessage("{validator.max}");
DecimalMax m = descriptorBuilder.build().getAnnotation();
testDecimalMax(m, false);
}
use of jakarta.validation.constraints.DecimalMax in project hibernate-validator by hibernate.
the class MaxValidatorForNumberTest method testIsValidDecimalMax.
@Test
public void testIsValidDecimalMax() {
ConstraintAnnotationDescriptor.Builder<DecimalMax> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(DecimalMax.class);
descriptorBuilder.setAttribute("value", "15.0E0");
descriptorBuilder.setMessage("{validator.max}");
DecimalMax m = descriptorBuilder.build().getAnnotation();
testDecimalMax(m, true);
}
use of jakarta.validation.constraints.DecimalMax in project hibernate-validator by hibernate.
the class MaxValidatorForStringTest method testIsValidDecimalMax.
@Test
public void testIsValidDecimalMax() {
ConstraintAnnotationDescriptor.Builder<DecimalMax> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(DecimalMax.class);
descriptorBuilder.setAttribute("value", "15.0E0");
descriptorBuilder.setMessage("{validator.max}");
DecimalMax m = descriptorBuilder.build().getAnnotation();
DecimalMaxValidatorForCharSequence constraint = new DecimalMaxValidatorForCharSequence();
constraint.initialize(m);
testMaxValidator(constraint, true);
}
use of jakarta.validation.constraints.DecimalMax in project hibernate-validator by hibernate.
the class MaxValidatorForNumberTest method testIsValidDecimalMax1.
@Test
public void testIsValidDecimalMax1() {
ConstraintAnnotationDescriptor.Builder<DecimalMax> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(DecimalMax.class);
descriptorBuilder.setAttribute("value", Integer.toString(Integer.MAX_VALUE - 1));
DecimalMax m = descriptorBuilder.build().getAnnotation();
DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber();
constraint.initialize(m);
assertFalse(constraint.isValid(Double.POSITIVE_INFINITY, null));
}
Aggregations