Search in sources :

Example 6 with IDataTypeParser

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

Example 7 with IDataTypeParser

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) {
    }
}
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 8 with IDataTypeParser

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) {
    }
}
Also used : SchemaDataTypeParsers.normalizedString(org.whole.lang.xsd.parsers.SchemaDataTypeParsers.normalizedString) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Example 9 with IDataTypeParser

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

Example 10 with IDataTypeParser

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

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