public void testPrimitiveArray() { final Validator validator = new Validator(); final Account account = new Account(); // test min size List<ConstraintViolation> violations = validator.validate(account); assertEquals(1, violations.size()); assertEquals("MIN_SIZE", violations.get(0).getMessage()); // test valid account.items = new int[] {1}; violations = validator.validate(account); assertEquals(0, violations.size()); // test max size account.items = new int[] {1, 2, 3, 4, 5}; violations = validator.validate(account); assertEquals(1, violations.size()); assertEquals("MAX_SIZE", violations.get(0).getMessage()); // test attribute not null account.items = null; violations = validator.validate(account); assertEquals(1, violations.size()); assertEquals("NOT_NULL", violations.get(0).getMessage()); // test elements max account.items = new int[] {1, 100}; violations = validator.validate(account); assertEquals(1, violations.size()); assertEquals("MAX", violations.get(0).getMessage()); }
private void assertValidated(final Object command) { // TODO: proper logging. final List<ConstraintViolation> violations = validator.validate(command); if (violations != null && violations.size() > 0) { System.out.println("[ERROR] Constraints Violation for : " + JSONValue.toJSONString(command)); for (final ConstraintViolation violation : violations) { System.out.println(violation.toString()); } throw new ConstraintsViolatedException(violations); } }