Search in sources :

Example 1 with TestEntitiesEntityFactory

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

the class TestingModel method create.

public ListTestEntity create() {
    TestEntitiesEntityFactory lf1 = TestEntitiesEntityFactory.instance;
    SimpleTestEntity e1 = lf1.createSimpleTestEntity(CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.ITestEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IStructuralEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.ICompositeEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IDataEntity), lf1.createBooleanTestEntity(false), lf1.createByteTestEntity((byte) 23), lf1.createCharTestEntity('v'), lf1.createDoubleTestEntity(0.0), lf1.createFloatTestEntity(0.0f), lf1.createIntTestEntity(342), lf1.createLongTestEntity(8365), lf1.createShortTestEntity((short) 4355), lf1.createStringTestEntity("text"), lf1.createDateTestEntity(new Date()), lf1.createEnumTestEntity(EnumTestEntityEnum.zero), lf1.createObjectTestEntity(new Object()));
    SimpleTestEntity e2 = lf1.createSimpleTestEntity(e1, CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IStructuralEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.ICompositeEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IDataEntity), lf1.createBooleanTestEntity(true), lf1.createByteTestEntity((byte) 123), lf1.createCharTestEntity('x'), lf1.createDoubleTestEntity(1.2), lf1.createFloatTestEntity(234.432f), lf1.createIntTestEntity(0), lf1.createLongTestEntity(0), lf1.createShortTestEntity((short) 0), lf1.createStringTestEntity("id"), lf1.createDateTestEntity(new Date()), lf1.createEnumTestEntity(EnumTestEntityEnum.zero), lf1.createObjectTestEntity(new Object()));
    SimpleTestEntity e3 = lf1.createSimpleTestEntity(CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.ITestEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IStructuralEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.ICompositeEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IDataEntity), lf1.createBooleanTestEntity(true), lf1.createByteTestEntity((byte) 32), lf1.createCharTestEntity('h'), lf1.createDoubleTestEntity(2134.0), lf1.createFloatTestEntity(234432.44f), lf1.createIntTestEntity(653), lf1.createLongTestEntity(4325345), lf1.createShortTestEntity((short) 45), lf1.createStringTestEntity("id"), lf1.createDateTestEntity(new Date()), lf1.createEnumTestEntity(EnumTestEntityEnum.zero), lf1.createObjectTestEntity(new Object()));
    SimpleTestEntity e4 = lf1.createSimpleTestEntity(lf1.createListTestEntity(new ITestEntity[] { e2, e3 }), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IStructuralEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.ICompositeEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IDataEntity), lf1.createBooleanTestEntity(false), lf1.createByteTestEntity((byte) 1), lf1.createCharTestEntity('c'), lf1.createDoubleTestEntity(3.5), lf1.createFloatTestEntity(2.3f), lf1.createIntTestEntity(12), lf1.createLongTestEntity(1234), lf1.createShortTestEntity((short) 21), lf1.createStringTestEntity("str"), lf1.createDateTestEntity(new Date()), lf1.createEnumTestEntity(EnumTestEntityEnum.zero), lf1.createObjectTestEntity(new Object()));
    SimpleTestEntity e5 = lf1.createSimpleTestEntity(CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.ITestEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IStructuralEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.ICompositeEntity), CommonsEntityAdapterFactory.createResolver(TestEntitiesEntityDescriptorEnum.IDataEntity), lf1.createBooleanTestEntity(false), lf1.createByteTestEntity((byte) 43), lf1.createCharTestEntity('f'), lf1.createDoubleTestEntity(376364.43), lf1.createFloatTestEntity(12.43f), lf1.createIntTestEntity(6456), lf1.createLongTestEntity(35), lf1.createShortTestEntity((short) 34), lf1.createStringTestEntity("id"), lf1.createDateTestEntity(new Date()), lf1.createEnumTestEntity(EnumTestEntityEnum.zero), lf1.createObjectTestEntity(new Object()));
    return lf1.createListTestEntity(new ITestEntity[] { e4, e5 });
}
Also used : ITestEntity(org.whole.lang.testentities.model.ITestEntity) TestEntitiesEntityFactory(org.whole.lang.testentities.factories.TestEntitiesEntityFactory) SimpleTestEntity(org.whole.lang.testentities.model.SimpleTestEntity) Date(java.util.Date)

Example 2 with TestEntitiesEntityFactory

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

the class FactoriesTest method testDataFactoryMethodsWithPromotions.

@Test
public void testDataFactoryMethodsWithPromotions() {
    TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
    ByteTestEntity be1 = ef.createByteTestEntity((byte) 23);
    Assert.assertEquals((byte) 23, be1.wByteValue());
    ByteTestEntity be2 = ef.create(TestEntitiesEntityDescriptorEnum.ByteTestEntity, (byte) 23);
    Assert.assertEquals((byte) 23, be2.wByteValue());
    CharTestEntity ce1 = ef.createCharTestEntity('c');
    Assert.assertEquals('c', ce1.wCharValue());
    CharTestEntity ce2 = ef.create(TestEntitiesEntityDescriptorEnum.CharTestEntity, 'c');
    Assert.assertEquals('c', ce2.wCharValue());
    CharTestEntity ce3 = ef.create(TestEntitiesEntityDescriptorEnum.CharTestEntity, (char) 65);
    Assert.assertEquals(65, ce3.wCharValue());
    ShortTestEntity se1 = ef.createShortTestEntity((short) 12345);
    Assert.assertEquals((short) 12345, se1.wShortValue());
    ShortTestEntity se2 = ef.create(TestEntitiesEntityDescriptorEnum.ShortTestEntity, (short) 12345);
    Assert.assertEquals((short) 12345, se2.wShortValue());
}
Also used : ByteTestEntity(org.whole.lang.testentities.model.ByteTestEntity) CharTestEntity(org.whole.lang.testentities.model.CharTestEntity) TestEntitiesEntityFactory(org.whole.lang.testentities.factories.TestEntitiesEntityFactory) ShortTestEntity(org.whole.lang.testentities.model.ShortTestEntity) Test(org.junit.Test)

Example 3 with TestEntitiesEntityFactory

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

the class DataTypeUtilsTest method testByteData.

@Test
public void testByteData() {
    TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
    IEntity e = ef.createByteTestEntity((byte) 27);
    assertGenericParseUnparseRoundtrip(e, "32");
    assertEquals("27", DataTypeUtils.getAsPresentationString(e));
    assertEquals("27", DataTypeUtils.getAsPersistenceString(e));
    DataTypeUtils.setFromPresentationString(e, "35");
    assertEquals((byte) 35, e.wByteValue());
    DataTypeUtils.setFromPersistenceString(e, "56");
    assertEquals((byte) 56, e.wByteValue());
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Byte.MIN_VALUE));
    assertEquals(Byte.MIN_VALUE, e.wByteValue());
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Byte.MAX_VALUE));
    assertEquals(Byte.MAX_VALUE, e.wByteValue());
    e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.ByteTestEntity, "18");
    assertEquals((byte) 18, e.wByteValue());
    e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.ByteTestEntity, "76");
    assertEquals((byte) 76, e.wByteValue());
    final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
    IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
    try {
        parser.parseByte(ed, "string");
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        parser.parseByte(ed, "200");
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        parser.parseByte(ed, "2.5f");
        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 4 with TestEntitiesEntityFactory

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

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

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