@Test void testGetDataValuesForTypeInt() { String attributeName = "attr"; int value = 123; Entity entity = mock(Entity.class); when(entity.getInt(attributeName)).thenReturn(value); Attribute attribute = when(mock(Attribute.class).getName()).thenReturn(attributeName).getMock(); when(attribute.getDataType()).thenReturn(AttributeType.INT); assertEquals(value, entityAttributesValidator.getDataValuesForType(entity, attribute)); }
Object getDataValuesForType(Entity entity, Attribute attribute) { String attributeName = attribute.getName(); switch (attribute.getDataType()) { case DATE: return entity.getLocalDate(attributeName); case DATE_TIME: return entity.getInstant(attributeName); case BOOL: return entity.getBoolean(attributeName); case DECIMAL: return entity.getDouble(attributeName); case LONG: return entity.getLong(attributeName); case INT: return entity.getInt(attributeName); case HYPERLINK: case ENUM: case HTML: case TEXT: case SCRIPT: case EMAIL: case STRING: return entity.getString(attributeName); case CATEGORICAL: case XREF: case FILE: Entity refEntity = entity.getEntity(attributeName); if (refEntity != null) return refEntity.getIdValue(); else return ""; case CATEGORICAL_MREF: case MREF: List<String> mrefValues = newArrayList(); for (Entity mrefEntity : entity.getEntities(attributeName)) { if (mrefEntity != null) { mrefValues.add(mrefEntity.getIdValue().toString()); } } return mrefValues; case COMPOUND: return ""; default: return ""; } }
EntityAttributesValidator { Object getDataValuesForType(Entity entity, Attribute attribute) { String attributeName = attribute.getName(); switch (attribute.getDataType()) { case DATE: return entity.getLocalDate(attributeName); case DATE_TIME: return entity.getInstant(attributeName); case BOOL: return entity.getBoolean(attributeName); case DECIMAL: return entity.getDouble(attributeName); case LONG: return entity.getLong(attributeName); case INT: return entity.getInt(attributeName); case HYPERLINK: case ENUM: case HTML: case TEXT: case SCRIPT: case EMAIL: case STRING: return entity.getString(attributeName); case CATEGORICAL: case XREF: case FILE: Entity refEntity = entity.getEntity(attributeName); if (refEntity != null) return refEntity.getIdValue(); else return ""; case CATEGORICAL_MREF: case MREF: List<String> mrefValues = newArrayList(); for (Entity mrefEntity : entity.getEntities(attributeName)) { if (mrefEntity != null) { mrefValues.add(mrefEntity.getIdValue().toString()); } } return mrefValues; case COMPOUND: return ""; default: return ""; } } }
EntityAttributesValidator { Object getDataValuesForType(Entity entity, Attribute attribute) { String attributeName = attribute.getName(); switch (attribute.getDataType()) { case DATE: return entity.getLocalDate(attributeName); case DATE_TIME: return entity.getInstant(attributeName); case BOOL: return entity.getBoolean(attributeName); case DECIMAL: return entity.getDouble(attributeName); case LONG: return entity.getLong(attributeName); case INT: return entity.getInt(attributeName); case HYPERLINK: case ENUM: case HTML: case TEXT: case SCRIPT: case EMAIL: case STRING: return entity.getString(attributeName); case CATEGORICAL: case XREF: case FILE: Entity refEntity = entity.getEntity(attributeName); if (refEntity != null) return refEntity.getIdValue(); else return ""; case CATEGORICAL_MREF: case MREF: List<String> mrefValues = newArrayList(); for (Entity mrefEntity : entity.getEntities(attributeName)) { if (mrefEntity != null) { mrefValues.add(mrefEntity.getIdValue().toString()); } } return mrefValues; case COMPOUND: return ""; default: return ""; } } EntityAttributesValidator(ExpressionValidator expressionValidator); }
EntityAttributesValidator { Object getDataValuesForType(Entity entity, Attribute attribute) { String attributeName = attribute.getName(); switch (attribute.getDataType()) { case DATE: return entity.getLocalDate(attributeName); case DATE_TIME: return entity.getInstant(attributeName); case BOOL: return entity.getBoolean(attributeName); case DECIMAL: return entity.getDouble(attributeName); case LONG: return entity.getLong(attributeName); case INT: return entity.getInt(attributeName); case HYPERLINK: case ENUM: case HTML: case TEXT: case SCRIPT: case EMAIL: case STRING: return entity.getString(attributeName); case CATEGORICAL: case XREF: case FILE: Entity refEntity = entity.getEntity(attributeName); if (refEntity != null) return refEntity.getIdValue(); else return ""; case CATEGORICAL_MREF: case MREF: List<String> mrefValues = newArrayList(); for (Entity mrefEntity : entity.getEntities(attributeName)) { if (mrefEntity != null) { mrefValues.add(mrefEntity.getIdValue().toString()); } } return mrefValues; case COMPOUND: return ""; default: return ""; } } EntityAttributesValidator(ExpressionValidator expressionValidator); Set<ConstraintViolation> validate(Entity entity, EntityType meta); }
EntityAttributesValidator { Object getDataValuesForType(Entity entity, Attribute attribute) { String attributeName = attribute.getName(); switch (attribute.getDataType()) { case DATE: return entity.getLocalDate(attributeName); case DATE_TIME: return entity.getInstant(attributeName); case BOOL: return entity.getBoolean(attributeName); case DECIMAL: return entity.getDouble(attributeName); case LONG: return entity.getLong(attributeName); case INT: return entity.getInt(attributeName); case HYPERLINK: case ENUM: case HTML: case TEXT: case SCRIPT: case EMAIL: case STRING: return entity.getString(attributeName); case CATEGORICAL: case XREF: case FILE: Entity refEntity = entity.getEntity(attributeName); if (refEntity != null) return refEntity.getIdValue(); else return ""; case CATEGORICAL_MREF: case MREF: List<String> mrefValues = newArrayList(); for (Entity mrefEntity : entity.getEntities(attributeName)) { if (mrefEntity != null) { mrefValues.add(mrefEntity.getIdValue().toString()); } } return mrefValues; case COMPOUND: return ""; default: return ""; } } EntityAttributesValidator(ExpressionValidator expressionValidator); Set<ConstraintViolation> validate(Entity entity, EntityType meta);  }