@Test public void testCheckConstraint_MAXLENGTH_TooLong() { ConstraintValidator validator = mock(ConstraintValidator.class); StringLengthConstraint constraint = new StringLengthConstraint("fake type", 5); JsonNode fieldValue = mock(JsonNode.class); when(fieldValue.asText()).thenReturn("123456"); new StringLengthChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, times(1)).addDocError(any(Error.class)); }
@Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((StringLengthConstraint) constraint).getValue(); String type = ((StringLengthConstraint) constraint).getType(); if (!(fieldValue instanceof NullNode)) { int len = fieldValue.asText().length(); if (StringLengthConstraint.MINLENGTH.equals(type)) { if (len < value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_SHORT, fieldValue.asText())); } } else if (len > value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_LONG, fieldValue.asText())); } } }
StringLengthChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((StringLengthConstraint) constraint).getValue(); String type = ((StringLengthConstraint) constraint).getType(); if (!(fieldValue instanceof NullNode)) { int len = fieldValue.asText().length(); if (StringLengthConstraint.MINLENGTH.equals(type)) { if (len < value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_SHORT, fieldValue.asText())); } } else if (len > value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_LONG, fieldValue.asText())); } } } }
StringLengthChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((StringLengthConstraint) constraint).getValue(); String type = ((StringLengthConstraint) constraint).getType(); if (!(fieldValue instanceof NullNode)) { int len = fieldValue.asText().length(); if (StringLengthConstraint.MINLENGTH.equals(type)) { if (len < value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_SHORT, fieldValue.asText())); } } else if (len > value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_LONG, fieldValue.asText())); } } }  }
StringLengthChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((StringLengthConstraint) constraint).getValue(); String type = ((StringLengthConstraint) constraint).getType(); if (!(fieldValue instanceof NullNode)) { int len = fieldValue.asText().length(); if (StringLengthConstraint.MINLENGTH.equals(type)) { if (len < value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_SHORT, fieldValue.asText())); } } else if (len > value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_LONG, fieldValue.asText())); } } }  @Override void checkConstraint(ConstraintValidator validator,
                                FieldTreeNode fieldMetadata,
                                Path fieldMetadataPath,
                                FieldConstraint constraint,
                                Path valuePath,
                                JsonDoc doc,
                                JsonNode fieldValue); }
StringLengthChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((StringLengthConstraint) constraint).getValue(); String type = ((StringLengthConstraint) constraint).getType(); if (!(fieldValue instanceof NullNode)) { int len = fieldValue.asText().length(); if (StringLengthConstraint.MINLENGTH.equals(type)) { if (len < value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_SHORT, fieldValue.asText())); } } else if (len > value) { validator.addDocError(Error.get(CrudConstants.ERR_TOO_LONG, fieldValue.asText())); } } }  @Override void checkConstraint(ConstraintValidator validator,
                                FieldTreeNode fieldMetadata,
                                Path fieldMetadataPath,
                                FieldConstraint constraint,
                                Path valuePath,
                                JsonDoc doc,
                                JsonNode fieldValue);  }