Search in sources :

Example 16 with IDataTypeParser

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) {
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) TestEntitiesEntityFactory(org.whole.lang.testentities.factories.TestEntitiesEntityFactory) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Example 17 with IDataTypeParser

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) {
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) TestEntitiesEntityFactory(org.whole.lang.testentities.factories.TestEntitiesEntityFactory) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Example 18 with IDataTypeParser

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)));
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser)

Example 19 with IDataTypeParser

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) {
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) TestEntitiesEntityFactory(org.whole.lang.testentities.factories.TestEntitiesEntityFactory) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Example 20 with IDataTypeParser

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) {
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) TestEntitiesEntityFactory(org.whole.lang.testentities.factories.TestEntitiesEntityFactory) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Aggregations

IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)32 Test (org.junit.Test)18 IEntity (org.whole.lang.model.IEntity)12 TestEntitiesEntityFactory (org.whole.lang.testentities.factories.TestEntitiesEntityFactory)10 DataKinds (org.whole.lang.reflect.DataKinds)3 ILanguageKit (org.whole.lang.reflect.ILanguageKit)3 SchemaDataTypeParsers.normalizedString (org.whole.lang.xsd.parsers.SchemaDataTypeParsers.normalizedString)3 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 Grammar (org.whole.lang.grammars.model.Grammar)1 EnumValue (org.whole.lang.model.EnumValue)1 IOperation (org.whole.lang.operations.IOperation)1 ForwardEntityDescriptorStrategyDataTypeParser (org.whole.lang.parsers.ForwardEntityDescriptorStrategyDataTypeParser)1 AbstractLanguageExtensionDeployer (org.whole.lang.reflect.AbstractLanguageExtensionDeployer)1 DynamicLanguageKit (org.whole.lang.reflect.DynamicLanguageKit)1 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)1 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)1