Search in sources :

Example 6 with TestEntitiesEntityFactory

use of org.whole.lang.testentities.factories.TestEntitiesEntityFactory in project whole by wholeplatform.

the class DataTypeUtilsTest method testNonDataEntityFailure.

@Test
public void testNonDataEntityFailure() {
    TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
    IEntity e = ef.createSimpleTestEntity();
    try {
        // any DataTypeParsers
        DataTypeUtils.getAsString(e, null);
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        // any DataTypeParsers
        DataTypeUtils.setFromString(e, "any", null);
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.SimpleTestEntity, "any");
        fail();
    } catch (IllegalArgumentException iae) {
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) TestEntitiesEntityFactory(org.whole.lang.testentities.factories.TestEntitiesEntityFactory) Test(org.junit.Test)

Example 7 with TestEntitiesEntityFactory

use of org.whole.lang.testentities.factories.TestEntitiesEntityFactory in project whole by wholeplatform.

the class DataTypeUtilsTest method testDoubleData.

@Test
public void testDoubleData() {
    TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
    IEntity e = ef.createDoubleTestEntity(1.2d);
    assertGenericParseUnparseRoundtrip(e, "54.35");
    assertEquals("1.2", DataTypeUtils.getAsPresentationString(e));
    assertEquals("1.2", DataTypeUtils.getAsPersistenceString(e));
    DataTypeUtils.setFromPresentationString(e, "12.3d");
    assertEquals(12.3d, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPresentationString(e, "37.32");
    assertEquals(37.32d, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPersistenceString(e, "23.4d");
    assertEquals(23.4d, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPresentationString(e, "200");
    assertEquals(200d, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPresentationString(e, "2.5f");
    assertEquals(2.5d, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.NaN));
    assertEquals(Double.NaN, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.NEGATIVE_INFINITY));
    assertEquals(Double.NEGATIVE_INFINITY, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.POSITIVE_INFINITY));
    assertEquals(Double.POSITIVE_INFINITY, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.MIN_VALUE));
    assertEquals(Double.MIN_VALUE, e.wDoubleValue(), .01d);
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.MAX_VALUE));
    assertEquals(Double.MAX_VALUE, e.wDoubleValue(), .01d);
    e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.DoubleTestEntity, "12.3d");
    assertEquals(12.3d, e.wDoubleValue(), .01d);
    e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.DoubleTestEntity, "23.4d");
    assertEquals(23.4d, e.wDoubleValue(), .01d);
    final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
    IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
    try {
        parser.parseDouble(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 8 with TestEntitiesEntityFactory

use of org.whole.lang.testentities.factories.TestEntitiesEntityFactory in project whole by wholeplatform.

the class DataTypeUtilsTest method testShortData.

@Test
public void testShortData() {
    TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
    IEntity e = ef.createShortTestEntity((short) 123);
    assertGenericParseUnparseRoundtrip(e, "4132");
    assertEquals("123", DataTypeUtils.getAsPresentationString(e));
    assertEquals("123", DataTypeUtils.getAsPersistenceString(e));
    DataTypeUtils.setFromPresentationString(e, "123");
    assertEquals((short) 123, e.wShortValue());
    DataTypeUtils.setFromPersistenceString(e, "532");
    assertEquals((short) 532, e.wShortValue());
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Short.MIN_VALUE));
    assertEquals(Short.MIN_VALUE, e.wShortValue());
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Short.MAX_VALUE));
    assertEquals(Short.MAX_VALUE, e.wShortValue());
    e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.ShortTestEntity, "3324");
    assertEquals((short) 3324, e.wShortValue());
    e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.ShortTestEntity, "983");
    assertEquals((short) 983, e.wShortValue());
    final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
    IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
    try {
        parser.parseShort(ed, "string");
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        parser.parseShort(ed, "-38000");
        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 9 with TestEntitiesEntityFactory

use of org.whole.lang.testentities.factories.TestEntitiesEntityFactory in project whole by wholeplatform.

the class DataTypeUtilsTest method testBooleanData.

@Test
public void testBooleanData() {
    TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
    IEntity e = ef.createBooleanTestEntity(true);
    assertGenericParseUnparseRoundtrip(e, "false");
    assertEquals("true", DataTypeUtils.getAsPresentationString(e));
    assertEquals("true", DataTypeUtils.getAsPersistenceString(e));
    DataTypeUtils.setFromPresentationString(e, "FALSE");
    assertFalse(e.wBooleanValue());
    DataTypeUtils.setFromPersistenceString(e, "True");
    assertTrue(e.wBooleanValue());
    e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.BooleanTestEntity, "true");
    assertTrue(e.wBooleanValue());
    e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.BooleanTestEntity, "true");
    assertTrue(e.wBooleanValue());
    final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
    IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
    try {
        parser.parseBoolean(ed, "string");
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        parser.parseBoolean(ed, "0");
        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 10 with TestEntitiesEntityFactory

use of org.whole.lang.testentities.factories.TestEntitiesEntityFactory 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)

Aggregations

TestEntitiesEntityFactory (org.whole.lang.testentities.factories.TestEntitiesEntityFactory)14 Test (org.junit.Test)13 IEntity (org.whole.lang.model.IEntity)12 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)10 Date (java.util.Date)2 Calendar (java.util.Calendar)1 ByteTestEntity (org.whole.lang.testentities.model.ByteTestEntity)1 CharTestEntity (org.whole.lang.testentities.model.CharTestEntity)1 ITestEntity (org.whole.lang.testentities.model.ITestEntity)1 ShortTestEntity (org.whole.lang.testentities.model.ShortTestEntity)1 SimpleTestEntity (org.whole.lang.testentities.model.SimpleTestEntity)1