@Test public void testValidationOfIntegerFailure() { Integer integerEntity = 0; assertFalse("Expected ListSchema integer validation failure did not succeed", schema.validate(integerEntity)); }
@Override protected boolean validate(String fieldName, Object entity, List<ValidationError> errors, Repository<Entity> repo) { boolean isValid = true; Object convertedEntity = convert(entity); if (convertedEntity instanceof Set) { convertedEntity = new ArrayList<Object>((Set) convertedEntity); } if (convertedEntity instanceof List) { List<?> entityList = (List<?>) convertedEntity; for (Object fieldEntity : entityList) { boolean isFieldValid = false; for (NeutralSchema itemSchema : getList()) { if (itemSchema.validate(fieldName, fieldEntity, errors, repo)) { isFieldValid = true; break; } } if (!isFieldValid) { isValid = false; if (errors == null) { return false; } } } if (getProperties() != null) { for (Entry<String, Object> entry : getProperties().entrySet()) { if (Restriction.isRestriction(entry.getKey())) { long restrictionValue = Long.parseLong(entry.getValue().toString()); switch (Restriction.fromValue(entry.getKey())) { case LENGTH: if (!addError(entityList.size() == restrictionValue, fieldName, convertedEntity, "length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MIN_LENGTH: if (!addError(entityList.size() >= restrictionValue, fieldName, convertedEntity, "min-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MAX_LENGTH: if (!addError(entityList.size() <= restrictionValue, fieldName, convertedEntity, "max-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; } } } } } else { return addError(false, fieldName, convertedEntity, "List", ErrorType.INVALID_DATATYPE, errors); } return isValid; }
ListSchema extends NeutralSchema { @Override protected boolean validate(String fieldName, Object entity, List<ValidationError> errors, Repository<Entity> repo) { boolean isValid = true; Object convertedEntity = convert(entity); if (convertedEntity instanceof Set) { convertedEntity = new ArrayList<Object>((Set) convertedEntity); } if (convertedEntity instanceof List) { List<?> entityList = (List<?>) convertedEntity; for (Object fieldEntity : entityList) { boolean isFieldValid = false; for (NeutralSchema itemSchema : getList()) { if (itemSchema.validate(fieldName, fieldEntity, errors, repo)) { isFieldValid = true; break; } } if (!isFieldValid) { isValid = false; if (errors == null) { return false; } } } if (getProperties() != null) { for (Entry<String, Object> entry : getProperties().entrySet()) { if (Restriction.isRestriction(entry.getKey())) { long restrictionValue = Long.parseLong(entry.getValue().toString()); switch (Restriction.fromValue(entry.getKey())) { case LENGTH: if (!addError(entityList.size() == restrictionValue, fieldName, convertedEntity, "length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MIN_LENGTH: if (!addError(entityList.size() >= restrictionValue, fieldName, convertedEntity, "min-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MAX_LENGTH: if (!addError(entityList.size() <= restrictionValue, fieldName, convertedEntity, "max-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; } } } } } else { return addError(false, fieldName, convertedEntity, "List", ErrorType.INVALID_DATATYPE, errors); } return isValid; } }
ListSchema extends NeutralSchema { @Override protected boolean validate(String fieldName, Object entity, List<ValidationError> errors, Repository<Entity> repo) { boolean isValid = true; Object convertedEntity = convert(entity); if (convertedEntity instanceof Set) { convertedEntity = new ArrayList<Object>((Set) convertedEntity); } if (convertedEntity instanceof List) { List<?> entityList = (List<?>) convertedEntity; for (Object fieldEntity : entityList) { boolean isFieldValid = false; for (NeutralSchema itemSchema : getList()) { if (itemSchema.validate(fieldName, fieldEntity, errors, repo)) { isFieldValid = true; break; } } if (!isFieldValid) { isValid = false; if (errors == null) { return false; } } } if (getProperties() != null) { for (Entry<String, Object> entry : getProperties().entrySet()) { if (Restriction.isRestriction(entry.getKey())) { long restrictionValue = Long.parseLong(entry.getValue().toString()); switch (Restriction.fromValue(entry.getKey())) { case LENGTH: if (!addError(entityList.size() == restrictionValue, fieldName, convertedEntity, "length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MIN_LENGTH: if (!addError(entityList.size() >= restrictionValue, fieldName, convertedEntity, "min-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MAX_LENGTH: if (!addError(entityList.size() <= restrictionValue, fieldName, convertedEntity, "max-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; } } } } } else { return addError(false, fieldName, convertedEntity, "List", ErrorType.INVALID_DATATYPE, errors); } return isValid; } ListSchema();  ListSchema(String xsdType); }
ListSchema extends NeutralSchema { @Override protected boolean validate(String fieldName, Object entity, List<ValidationError> errors, Repository<Entity> repo) { boolean isValid = true; Object convertedEntity = convert(entity); if (convertedEntity instanceof Set) { convertedEntity = new ArrayList<Object>((Set) convertedEntity); } if (convertedEntity instanceof List) { List<?> entityList = (List<?>) convertedEntity; for (Object fieldEntity : entityList) { boolean isFieldValid = false; for (NeutralSchema itemSchema : getList()) { if (itemSchema.validate(fieldName, fieldEntity, errors, repo)) { isFieldValid = true; break; } } if (!isFieldValid) { isValid = false; if (errors == null) { return false; } } } if (getProperties() != null) { for (Entry<String, Object> entry : getProperties().entrySet()) { if (Restriction.isRestriction(entry.getKey())) { long restrictionValue = Long.parseLong(entry.getValue().toString()); switch (Restriction.fromValue(entry.getKey())) { case LENGTH: if (!addError(entityList.size() == restrictionValue, fieldName, convertedEntity, "length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MIN_LENGTH: if (!addError(entityList.size() >= restrictionValue, fieldName, convertedEntity, "min-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MAX_LENGTH: if (!addError(entityList.size() <= restrictionValue, fieldName, convertedEntity, "max-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; } } } } } else { return addError(false, fieldName, convertedEntity, "List", ErrorType.INVALID_DATATYPE, errors); } return isValid; } ListSchema();  ListSchema(String xsdType); @Override NeutralSchemaType getSchemaType(); @Override boolean isPrimitive(); void setList(List<NeutralSchema> list); List<NeutralSchema> getList(); @Override boolean isSimple(); void updateAnnotations(); @Override Object convert(Object value); Map<String, NeutralSchema> getFields(); }
ListSchema extends NeutralSchema { @Override protected boolean validate(String fieldName, Object entity, List<ValidationError> errors, Repository<Entity> repo) { boolean isValid = true; Object convertedEntity = convert(entity); if (convertedEntity instanceof Set) { convertedEntity = new ArrayList<Object>((Set) convertedEntity); } if (convertedEntity instanceof List) { List<?> entityList = (List<?>) convertedEntity; for (Object fieldEntity : entityList) { boolean isFieldValid = false; for (NeutralSchema itemSchema : getList()) { if (itemSchema.validate(fieldName, fieldEntity, errors, repo)) { isFieldValid = true; break; } } if (!isFieldValid) { isValid = false; if (errors == null) { return false; } } } if (getProperties() != null) { for (Entry<String, Object> entry : getProperties().entrySet()) { if (Restriction.isRestriction(entry.getKey())) { long restrictionValue = Long.parseLong(entry.getValue().toString()); switch (Restriction.fromValue(entry.getKey())) { case LENGTH: if (!addError(entityList.size() == restrictionValue, fieldName, convertedEntity, "length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MIN_LENGTH: if (!addError(entityList.size() >= restrictionValue, fieldName, convertedEntity, "min-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; case MAX_LENGTH: if (!addError(entityList.size() <= restrictionValue, fieldName, convertedEntity, "max-length=" + restrictionValue, ErrorType.INVALID_VALUE, errors)) { return false; } break; } } } } } else { return addError(false, fieldName, convertedEntity, "List", ErrorType.INVALID_DATATYPE, errors); } return isValid; } ListSchema();  ListSchema(String xsdType); @Override NeutralSchemaType getSchemaType(); @Override boolean isPrimitive(); void setList(List<NeutralSchema> list); List<NeutralSchema> getList(); @Override boolean isSimple(); void updateAnnotations(); @Override Object convert(Object value); Map<String, NeutralSchema> getFields();  }