use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testFloatData.
@Test
public void testFloatData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
IEntity e = ef.createFloatTestEntity(1.2f);
assertGenericParseUnparseRoundtrip(e, "36.3");
assertEquals("1.2", DataTypeUtils.getAsPresentationString(e));
assertEquals("1.2", DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, "12.3f");
assertEquals(12.3f, e.wFloatValue(), .01d);
DataTypeUtils.setFromPresentationString(e, "37.32");
assertEquals(37.32f, e.wFloatValue(), .01d);
DataTypeUtils.setFromPersistenceString(e, "23.4f");
assertEquals(23.4f, e.wFloatValue(), .01d);
DataTypeUtils.setFromPresentationString(e, "200");
assertEquals(200f, e.wFloatValue(), .01d);
DataTypeUtils.setFromPresentationString(e, "2.5d");
assertEquals(2.5f, e.wFloatValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Float.NaN));
assertEquals(Float.NaN, e.wFloatValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Float.NEGATIVE_INFINITY));
assertEquals(Float.NEGATIVE_INFINITY, e.wFloatValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Float.POSITIVE_INFINITY));
assertEquals(Float.POSITIVE_INFINITY, e.wFloatValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Float.MIN_VALUE));
assertEquals(Float.MIN_VALUE, e.wFloatValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Float.MAX_VALUE));
assertEquals(Float.MAX_VALUE, e.wFloatValue(), .01d);
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.FloatTestEntity, "12.3f");
assertEquals(12.3f, e.wFloatValue(), .01d);
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.FloatTestEntity, "23.4f");
assertEquals(23.4f, e.wFloatValue(), .01d);
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseFloat(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testLongData.
@Test
public void testLongData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
IEntity e = ef.createLongTestEntity(123l);
assertGenericParseUnparseRoundtrip(e, "486432");
assertEquals("123", DataTypeUtils.getAsPresentationString(e));
assertEquals("123", DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, "3324");
assertEquals(3324l, e.wLongValue());
DataTypeUtils.setFromPersistenceString(e, "532");
assertEquals(532l, e.wLongValue());
DataTypeUtils.setFromPresentationString(e, String.valueOf(Long.MIN_VALUE));
assertEquals(Long.MIN_VALUE, e.wLongValue());
DataTypeUtils.setFromPresentationString(e, String.valueOf(Long.MAX_VALUE));
assertEquals(Long.MAX_VALUE, e.wLongValue());
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.LongTestEntity, "3324");
assertEquals(3324l, e.wLongValue());
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.LongTestEntity, "983");
assertEquals(983l, e.wLongValue());
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseLong(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
try {
parser.parseLong(ed, "2.0f");
fail();
} catch (IllegalArgumentException iae) {
}
try {
parser.parseLong(ed, "-10000000000000000000");
fail();
} catch (IllegalArgumentException iae) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method assertGenericParseUnparseRoundtrip.
private void assertGenericParseUnparseRoundtrip(IEntity e, String value) {
EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PERSISTENCE);
assertEquals(value, parser.unparse(ed, parser.parse(ed, value)));
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testEnumData.
@Test
public void testEnumData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
IEntity e = ef.createEnumTestEntity(EnumTestEntityEnum.four);
assertGenericParseUnparseRoundtrip(e, "three");
assertEquals("four", DataTypeUtils.getAsPresentationString(e));
assertEquals("four", DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, "One");
assertEquals(EnumTestEntityEnum.one, e.wEnumValue());
DataTypeUtils.setFromPersistenceString(e, "four");
assertEquals(EnumTestEntityEnum.four, e.wEnumValue());
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.EnumTestEntity, "TWO");
assertEquals(EnumTestEntityEnum.two, e.wEnumValue());
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.EnumTestEntity, "five");
assertEquals(EnumTestEntityEnum.five, e.wEnumValue());
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseEnumValue(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testCharData.
@Test
public void testCharData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
IEntity e = ef.createCharTestEntity('a');
assertGenericParseUnparseRoundtrip(e, "x");
assertEquals("a", DataTypeUtils.getAsPresentationString(e));
assertEquals("a", DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, "b");
assertEquals('b', e.wCharValue());
DataTypeUtils.setFromPersistenceString(e, "c");
assertEquals('c', e.wCharValue());
DataTypeUtils.setFromPresentationString(e, String.valueOf(Character.MIN_VALUE));
assertEquals(Character.MIN_VALUE, e.wCharValue());
DataTypeUtils.setFromPresentationString(e, String.valueOf(Character.MAX_VALUE));
assertEquals(Character.MAX_VALUE, e.wCharValue());
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.CharTestEntity, "d");
assertEquals('d', e.wCharValue());
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.CharTestEntity, "e");
assertEquals('e', e.wCharValue());
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseChar(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
try {
parser.parseChar(ed, "200");
fail();
} catch (IllegalArgumentException iae) {
}
}
Aggregations