use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testDateData.
@Test
public void testDateData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Date date = c.getTime();
String eDate = DateFormat.getDateInstance(DateFormat.SHORT).format(date);
String eDate2 = DateFormat.getDateInstance(DateFormat.LONG).format(date);
String eDate3 = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date);
String pDate = StringUtils.toExtendedISO8601DateTime(date);
IEntity e = ef.createDateTestEntity(date);
assertGenericParseUnparseRoundtrip(e, pDate);
assertEquals(eDate, DataTypeUtils.getAsPresentationString(e));
assertEquals(pDate, DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, eDate2);
assertEquals(date, e.wDateValue());
DataTypeUtils.setFromPresentationString(e, eDate3);
assertEquals(date, e.wDateValue());
DataTypeUtils.setFromPresentationString(e, eDate);
assertEquals(date, e.wDateValue());
DataTypeUtils.setFromPersistenceString(e, pDate);
assertEquals(date, e.wDateValue());
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.DateTestEntity, eDate);
assertEquals(date, e.wDateValue());
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.DateTestEntity, pDate);
assertEquals(date, e.wDateValue());
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseDate(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testIntData.
@Test
public void testIntData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
IEntity e = ef.createIntTestEntity(123);
assertGenericParseUnparseRoundtrip(e, "4231");
assertEquals("123", DataTypeUtils.getAsPresentationString(e));
assertEquals("123", DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, "3324");
assertEquals(3324, e.wIntValue());
DataTypeUtils.setFromPersistenceString(e, "532");
assertEquals(532, e.wIntValue());
DataTypeUtils.setFromPresentationString(e, String.valueOf(Integer.MIN_VALUE));
assertEquals(Integer.MIN_VALUE, e.wIntValue());
DataTypeUtils.setFromPresentationString(e, String.valueOf(Integer.MAX_VALUE));
assertEquals(Integer.MAX_VALUE, e.wIntValue());
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.IntTestEntity, "3324");
assertEquals(3324, e.wIntValue());
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.IntTestEntity, "983");
assertEquals(983, e.wIntValue());
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseInt(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
try {
parser.parseInt(ed, "-3000000000");
fail();
} catch (IllegalArgumentException iae) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class SchemaDataTypeParsersTest method testFloat.
@Test
public void testFloat() throws Exception {
IDataTypeParser dtp = XsiDefaultDataTypeParser.instance;
// test float
String floatString = "-12.78e+28";
float fValue = dtp.parseFloat(null, floatString);
assertEquals("-1.278E29", dtp.unparseFloat(null, fValue));
floatString = "+1267.43233E12";
fValue = dtp.parseFloat(null, floatString);
assertEquals("1.26743237E15", dtp.unparseFloat(null, fValue));
floatString = "0";
fValue = dtp.parseFloat(null, floatString);
assertEquals("0.0E0", dtp.unparseFloat(null, fValue));
assertEquals("INF", dtp.unparseFloat(null, Float.POSITIVE_INFINITY));
assertEquals("-INF", dtp.unparseFloat(null, Float.NEGATIVE_INFINITY));
assertEquals("NaN", dtp.unparseFloat(null, Float.NaN));
try {
dtp.parseFloat(null, "123,456");
fail();
} catch (Exception e) {
}
try {
dtp.parseFloat(null, "1000FFFF");
fail();
} catch (Exception e) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class SchemaDataTypeParsersTest method testInt.
@Test
public void testInt() throws Exception {
IDataTypeParser dtp = XsiDefaultDataTypeParser.instance;
// test primitives
assertEquals("-2147483648", dtp.unparseInt(null, dtp.parseInt(null, "-2147483648")));
assertEquals("2147483647", dtp.unparseInt(null, dtp.parseInt(null, "2147483647")));
try {
dtp.parseInt(null, "2147483648");
fail();
} catch (Exception e) {
}
try {
dtp.parseInt(null, "-2147483649");
fail();
} catch (Exception e) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataEntityDirectEditPolicy method getDirectEditCommand.
protected Command getDirectEditCommand(DirectEditRequest request) {
IEntity hostEntity = (IEntity) getHost().getModel();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(hostEntity, DataTypeParsers.PRESENTATION);
try {
return getDirectEditCommand(hostEntity, getCellEditorValue(request), parser);
} catch (Exception e) {
return UnexecutableCommand.INSTANCE;
}
}
Aggregations