@Test public void saveGlobalProperty_shouldSaveAGlobalPropertyWhoseTypedValueIsHandledByACustomDatatype() { GlobalProperty gp = new GlobalProperty(); gp.setProperty("What time is it?"); gp.setDatatypeClassname(DateDatatype.class.getName()); gp.setValue(new Date()); adminService.saveGlobalProperty(gp); assertNotNull(gp.getValueReference()); }
@Test public void updateGlobalProperty_shouldUpdateAGlobalPropertyWhoseTypedvalueIsHandledByACustomDatatype() { GlobalProperty gp = new GlobalProperty(); gp.setProperty("Flag"); gp.setDatatypeClassname(BooleanDatatype.class.getName()); gp.setValue(Boolean.FALSE); adminService.saveGlobalProperty(gp); assertEquals(adminService.getGlobalProperty("Flag"), "false"); adminService.updateGlobalProperty("Flag", Boolean.TRUE.toString()); assertEquals(adminService.getGlobalProperty("Flag"), "true"); }
/** * Sets value for given property. * * @param property * @param value */ @PropertySetter("value") public static void setValue(GlobalProperty property, String value) throws Exception { if (StringUtils.isNotEmpty(property.getDatatypeClassname())) { CustomDatatype customDataType = CustomDatatypeUtil.getDatatype(property.getDatatypeClassname(), property.getDatatypeConfig()); if (customDataType != null) { try { property.setValue(customDataType.fromReferenceString(value)); } catch (Exception ex) { throw new APIException("Exception in converting value to custom data type", ex); } } else throw new APIException("Custom data type is null as per provided parameters"); } else { property.setPropertyValue(value); } } }