@Test public void testGetValidatedDefaultValue() { MetaAttribute ma1 = new MetaAttribute(); expectValidateException(ma1); Assert.assertEquals("MetaAttribute".hashCode(), ma1.hashCode()); ma1.setName("attribute1"); Assert.assertEquals("attribute1".hashCode(), ma1.hashCode()); ma1.setDataType(DataTypeEnum.STRING); ma1.setDefaultValue("defaultvalue"); noValidateException(ma1); ma1.setDataType(DataTypeEnum.JSON); ma1.setDefaultValue("json default value"); expectValidateException(ma1); ma1.setDataType(DataTypeEnum.INTEGER); ma1.setDefaultValue("non-integer"); expectValidateException(ma1); ma1.setDefaultValue("1"); noValidateException(ma1); ma1.setDataType(DataTypeEnum.LONG); ma1.setDefaultValue("non-long"); expectValidateException(ma1); ma1.setDefaultValue("3"); noValidateException(ma1); ma1.setDataType(DataTypeEnum.BOOLEAN); ma1.setDefaultValue("non-boolean"); expectValidateException(ma1); ma1.setDefaultValue("true"); noValidateException(ma1); ma1.setDefaultValue("false"); noValidateException(ma1); ma1.setDataType(DataTypeEnum.DATE); ma1.setDefaultValue("non-date"); expectValidateException(ma1); ma1.setDefaultValue(MetaAttribute.DATE_DEFAULT_VALUE); noValidateException(ma1); ma1.setDataType(DataTypeEnum.DOUBLE); ma1.setDefaultValue("non-double"); expectValidateException(ma1); ma1.setDefaultValue("2.3"); noValidateException(ma1); ma1.setDataType(DataTypeEnum.ENUM); expectValidateException(ma1); ma1.addEnumValue("enumvalue1"); ma1.addEnumValue("enumvalue2"); ma1.setDefaultValue("non-enum"); expectValidateException(ma1); ma1.setDefaultValue("enumvalue1"); noValidateException(ma1); ma1.addEnumValue(""); expectValidateException(ma1); ma1.addEnumValue("enumvalue1"); expectValidateException(ma1); ma1.setDataType(DataTypeEnum.RELATIONSHIP); expectValidateException(ma1); ma1.setName("ma1"); ma1.setDefaultValue("dv"); ma1.setDataType(DataTypeEnum.STRING); MetaAttribute ma2 = new MetaAttribute(); ma2.setName("ma2"); ma2.setDefaultValue("dv"); ma2.setDataType(DataTypeEnum.STRING); Assert.assertTrue(!ma1.equals(ma2)); ma2.setName("ma1"); ma1.setEnumValues(null); Assert.assertEquals(ma1.equals(ma2), ma2.equals(ma1)); MetaAttribute ma3 = new MetaAttribute(); ma3.setName("testattr"); ma3.setDbName("dbname"); expectValidateException(ma3); MetaAttribute ma4 = new MetaAttribute(); ma4.setName("testattr"); ma4.setValueDbName("valuedbname"); expectValidateException(ma4); }
@JsonIgnore public Object getValidatedDefaultValue() { Object convertedValue = defaultValue; if (defaultValue != null) { switch (getDataType()) { case INTEGER: try { convertedValue = Integer.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of Integer format error: " + defaultValue, e); } break; case JSON: throw new IllegalMetaClassException("json field's default value must be null"); case LONG: try { convertedValue = Long.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of long format error: " + defaultValue , e); } break; case STRING: break; case DOUBLE: try { convertedValue = Double.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of double format error: " + defaultValue, e); } break; case BOOLEAN: if (!defaultValue.equals("true") && !defaultValue.equals("false")) { throw new IllegalMetaClassException("default value of boolean format error"); } convertedValue = Boolean.valueOf(defaultValue); break; case DATE: if (!defaultValue.equals(MetaField.DATE_DEFAULT_VALUE)) { throw new IllegalMetaClassException("default value of DATE can only be null or Now"); } break; case ENUM: HashSet<String> set = new HashSet<String>(); set.addAll(getEnumValues()); if (!set.contains(defaultValue)) { throw new IllegalMetaClassException("default value for enum must be one of enum values"); } break; default: throw new IllegalMetaClassException("unknow datatype: " + getDataType().toString()); } } return convertedValue; }
MetaAttribute extends MetaField { @JsonIgnore public Object getValidatedDefaultValue() { Object convertedValue = defaultValue; if (defaultValue != null) { switch (getDataType()) { case INTEGER: try { convertedValue = Integer.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of Integer format error: " + defaultValue, e); } break; case JSON: throw new IllegalMetaClassException("json field's default value must be null"); case LONG: try { convertedValue = Long.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of long format error: " + defaultValue , e); } break; case STRING: break; case DOUBLE: try { convertedValue = Double.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of double format error: " + defaultValue, e); } break; case BOOLEAN: if (!defaultValue.equals("true") && !defaultValue.equals("false")) { throw new IllegalMetaClassException("default value of boolean format error"); } convertedValue = Boolean.valueOf(defaultValue); break; case DATE: if (!defaultValue.equals(MetaField.DATE_DEFAULT_VALUE)) { throw new IllegalMetaClassException("default value of DATE can only be null or Now"); } break; case ENUM: HashSet<String> set = new HashSet<String>(); set.addAll(getEnumValues()); if (!set.contains(defaultValue)) { throw new IllegalMetaClassException("default value for enum must be one of enum values"); } break; default: throw new IllegalMetaClassException("unknow datatype: " + getDataType().toString()); } } return convertedValue; } }
MetaAttribute extends MetaField { @JsonIgnore public Object getValidatedDefaultValue() { Object convertedValue = defaultValue; if (defaultValue != null) { switch (getDataType()) { case INTEGER: try { convertedValue = Integer.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of Integer format error: " + defaultValue, e); } break; case JSON: throw new IllegalMetaClassException("json field's default value must be null"); case LONG: try { convertedValue = Long.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of long format error: " + defaultValue , e); } break; case STRING: break; case DOUBLE: try { convertedValue = Double.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of double format error: " + defaultValue, e); } break; case BOOLEAN: if (!defaultValue.equals("true") && !defaultValue.equals("false")) { throw new IllegalMetaClassException("default value of boolean format error"); } convertedValue = Boolean.valueOf(defaultValue); break; case DATE: if (!defaultValue.equals(MetaField.DATE_DEFAULT_VALUE)) { throw new IllegalMetaClassException("default value of DATE can only be null or Now"); } break; case ENUM: HashSet<String> set = new HashSet<String>(); set.addAll(getEnumValues()); if (!set.contains(defaultValue)) { throw new IllegalMetaClassException("default value for enum must be one of enum values"); } break; default: throw new IllegalMetaClassException("unknow datatype: " + getDataType().toString()); } } return convertedValue; } MetaAttribute();  MetaAttribute(boolean intern); }
MetaAttribute extends MetaField { @JsonIgnore public Object getValidatedDefaultValue() { Object convertedValue = defaultValue; if (defaultValue != null) { switch (getDataType()) { case INTEGER: try { convertedValue = Integer.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of Integer format error: " + defaultValue, e); } break; case JSON: throw new IllegalMetaClassException("json field's default value must be null"); case LONG: try { convertedValue = Long.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of long format error: " + defaultValue , e); } break; case STRING: break; case DOUBLE: try { convertedValue = Double.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of double format error: " + defaultValue, e); } break; case BOOLEAN: if (!defaultValue.equals("true") && !defaultValue.equals("false")) { throw new IllegalMetaClassException("default value of boolean format error"); } convertedValue = Boolean.valueOf(defaultValue); break; case DATE: if (!defaultValue.equals(MetaField.DATE_DEFAULT_VALUE)) { throw new IllegalMetaClassException("default value of DATE can only be null or Now"); } break; case ENUM: HashSet<String> set = new HashSet<String>(); set.addAll(getEnumValues()); if (!set.contains(defaultValue)) { throw new IllegalMetaClassException("default value for enum must be one of enum values"); } break; default: throw new IllegalMetaClassException("unknow datatype: " + getDataType().toString()); } } return convertedValue; } MetaAttribute();  MetaAttribute(boolean intern); String getDefaultValue(); void setDefaultValue(String defaultValue); @JsonIgnore Object getValidatedDefaultValue(); List<String> getEnumValues(); void setEnumValues(List<String> enumValues); void addEnumValue(String enumValue); String getExpression(); void setExpression(String expression); @JsonIgnore IExpression getCompiledExpression(); String getValidation(); void setValidation(String validation); @JsonIgnore IExpression getCompiledValidation(); @Override String toString(); void validate(boolean readOnlyCheck); @Override int hashCode(); @Override boolean equals(Object other); @Override boolean isOverridable(MetaField parentAttr); }
MetaAttribute extends MetaField { @JsonIgnore public Object getValidatedDefaultValue() { Object convertedValue = defaultValue; if (defaultValue != null) { switch (getDataType()) { case INTEGER: try { convertedValue = Integer.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of Integer format error: " + defaultValue, e); } break; case JSON: throw new IllegalMetaClassException("json field's default value must be null"); case LONG: try { convertedValue = Long.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of long format error: " + defaultValue , e); } break; case STRING: break; case DOUBLE: try { convertedValue = Double.valueOf(defaultValue); } catch (NumberFormatException e) { throw new IllegalMetaClassException("default value of double format error: " + defaultValue, e); } break; case BOOLEAN: if (!defaultValue.equals("true") && !defaultValue.equals("false")) { throw new IllegalMetaClassException("default value of boolean format error"); } convertedValue = Boolean.valueOf(defaultValue); break; case DATE: if (!defaultValue.equals(MetaField.DATE_DEFAULT_VALUE)) { throw new IllegalMetaClassException("default value of DATE can only be null or Now"); } break; case ENUM: HashSet<String> set = new HashSet<String>(); set.addAll(getEnumValues()); if (!set.contains(defaultValue)) { throw new IllegalMetaClassException("default value for enum must be one of enum values"); } break; default: throw new IllegalMetaClassException("unknow datatype: " + getDataType().toString()); } } return convertedValue; } MetaAttribute();  MetaAttribute(boolean intern); String getDefaultValue(); void setDefaultValue(String defaultValue); @JsonIgnore Object getValidatedDefaultValue(); List<String> getEnumValues(); void setEnumValues(List<String> enumValues); void addEnumValue(String enumValue); String getExpression(); void setExpression(String expression); @JsonIgnore IExpression getCompiledExpression(); String getValidation(); void setValidation(String validation); @JsonIgnore IExpression getCompiledValidation(); @Override String toString(); void validate(boolean readOnlyCheck); @Override int hashCode(); @Override boolean equals(Object other); @Override boolean isOverridable(MetaField parentAttr);  }