Search in sources :

Example 1 with IntegerType

use of com.qcadoo.model.internal.types.IntegerType in project qcadoo by qcadoo.

the class DataAccessServiceGetTest method shouldNotFailIfFieldTypeIsNotValid.

@Test
public void shouldNotFailIfFieldTypeIsNotValid() throws Exception {
    // given
    fieldDefinitionName.withType(new IntegerType());
    SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject();
    simpleDatabaseObject.setId(1L);
    simpleDatabaseObject.setName("Mr T");
    simpleDatabaseObject.setAge(66);
    given(criteria.uniqueResult()).willReturn(simpleDatabaseObject);
    // when
    dataDefinition.get(1L);
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 2 with IntegerType

use of com.qcadoo.model.internal.types.IntegerType in project qcadoo by qcadoo.

the class EntityServiceImplTest method shouldNotThrownAnExceptionWhileGettingFieldWithInvalidType.

@Test
public void shouldNotThrownAnExceptionWhileGettingFieldWithInvalidType() throws Exception {
    // given
    SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
    databaseEntity.setName("Mr T");
    FieldDefinition fieldDefinition = new FieldDefinitionImpl(new DataDefinitionImpl("", "", null), "name").withType(new IntegerType());
    // when
    entityService.getField(databaseEntity, fieldDefinition);
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 3 with IntegerType

use of com.qcadoo.model.internal.types.IntegerType in project qcadoo by qcadoo.

the class FieldTypeFactoryTest method shouldReturnIntegerType.

@Test
public void shouldReturnIntegerType() throws Exception {
    // when
    FieldType fieldType = new IntegerType();
    // then
    assertEquals(Integer.class, fieldType.getType());
    assertTrue(fieldType.toObject(fieldDefinition, 1).isValid());
    assertTrue(fieldType.toObject(fieldDefinition, 1234567890).isValid());
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) FieldType(com.qcadoo.model.api.types.FieldType) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 4 with IntegerType

use of com.qcadoo.model.internal.types.IntegerType in project qcadoo by qcadoo.

the class ExpressionUtilTest method shouldReturnJoinedStringRepresentationsOfMultipleFieldWithoutExpression.

@Test
public void shouldReturnJoinedStringRepresentationsOfMultipleFieldWithoutExpression() throws Exception {
    // given
    Entity entity = new DefaultEntity(null, 1L);
    entity.setField("name", "Mr T");
    entity.setField("age", 33);
    entity.setField("sex", "F");
    FieldDefinition fieldDefinitionName = new FieldDefinitionImpl(null, "name").withType(new StringType());
    FieldDefinition fieldDefinitionAge = new FieldDefinitionImpl(null, "age").withType(new IntegerType());
    FieldDefinition fieldDefinitionSex = new FieldDefinitionImpl(null, "sex").withType(new StringType());
    // when
    String value = expressionService.getValue(entity, Lists.newArrayList(fieldDefinitionName, fieldDefinitionAge, fieldDefinitionSex), Locale.ENGLISH);
    // then
    assertEquals("Mr T, 33, F", value);
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl) Test(org.junit.Test)

Example 5 with IntegerType

use of com.qcadoo.model.internal.types.IntegerType in project qcadoo by qcadoo.

the class DefaultEntityTest method init.

@Before
public final void init() {
    belongsToFieldDefinition = mock(FieldDefinition.class);
    final BelongsToType belongsToType = mock(BelongsToType.class);
    when(belongsToFieldDefinition.getType()).thenReturn(belongsToType);
    belongsToFieldDataDefinition = mock(DataDefinition.class);
    when(belongsToFieldDefinition.getDataDefinition()).thenReturn(belongsToFieldDataDefinition);
    decimalFieldDefinition = mock(FieldDefinition.class);
    final DecimalType decimalType = new DecimalType();
    when(decimalFieldDefinition.getType()).thenReturn(decimalType);
    integerFieldDefinition = mock(FieldDefinition.class);
    final IntegerType integerType = new IntegerType();
    when(integerFieldDefinition.getType()).thenReturn(integerType);
    manyToManyFieldDefinition = mock(FieldDefinition.class);
    final ManyToManyType manyToManyType = mock(ManyToManyType.class);
    when(manyToManyFieldDefinition.getType()).thenReturn(manyToManyType);
    manyToManyDataDefinition = mock(DataDefinition.class);
    when(manyToManyFieldDefinition.getDataDefinition()).thenReturn(manyToManyDataDefinition);
    secondManyToManyFieldDefinition = mock(FieldDefinition.class);
    when(secondManyToManyFieldDefinition.getType()).thenReturn(manyToManyType);
    secondManyToManyDataDefinition = mock(DataDefinition.class);
    when(secondManyToManyFieldDefinition.getDataDefinition()).thenReturn(secondManyToManyDataDefinition);
    hasManyFieldDefinition = mock(FieldDefinition.class);
    final HasManyType hasManyType = mock(HasManyType.class);
    when(hasManyType.getJoinFieldName()).thenReturn(BELONGS_TO_FIELD_NAME);
    when(hasManyFieldDefinition.getType()).thenReturn(hasManyType);
    hasManyDataDefinition = mock(DataDefinition.class);
    when(hasManyFieldDefinition.getDataDefinition()).thenReturn(hasManyDataDefinition);
    stringFieldDefinition = mock(FieldDefinition.class);
    when(stringFieldDefinition.isPersistent()).thenReturn(false);
    dataDefinition = mock(DataDefinition.class);
    booleanFieldDefinition = mock(FieldDefinition.class);
    defaultEntity = new DefaultEntity(dataDefinition);
    final Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
    fieldsMap.put(BELONGS_TO_FIELD_NAME, belongsToFieldDefinition);
    fieldsMap.put(STRING_FIELD_NAME, stringFieldDefinition);
    fieldsMap.put(BOOLEAN_FIELD_NAME, booleanFieldDefinition);
    fieldsMap.put(DECIMAL_FIELD_NAME, decimalFieldDefinition);
    fieldsMap.put(INTEGER_FIELD_NAME, integerFieldDefinition);
    fieldsMap.put(MANY_TO_MANY_FIELD_NAME, manyToManyFieldDefinition);
    fieldsMap.put(SECOND_MANY_TO_MANY_FIELD_NAME, secondManyToManyFieldDefinition);
    fieldsMap.put(HAS_MANY_FIELD_NAME, hasManyFieldDefinition);
    for (Map.Entry<String, FieldDefinition> fieldEntry : fieldsMap.entrySet()) {
        when(dataDefinition.getField(fieldEntry.getKey())).thenReturn(fieldEntry.getValue());
    }
    when(dataDefinition.getFields()).thenReturn(fieldsMap);
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) ManyToManyType(com.qcadoo.model.api.types.ManyToManyType) DecimalType(com.qcadoo.model.internal.types.DecimalType) DataDefinition(com.qcadoo.model.api.DataDefinition) Map(java.util.Map) Before(org.junit.Before)

Aggregations

IntegerType (com.qcadoo.model.internal.types.IntegerType)6 Test (org.junit.Test)5 FieldDefinition (com.qcadoo.model.api.FieldDefinition)4 DataDefinition (com.qcadoo.model.api.DataDefinition)2 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)2 StringType (com.qcadoo.model.internal.types.StringType)2 Entity (com.qcadoo.model.api.Entity)1 BelongsToType (com.qcadoo.model.api.types.BelongsToType)1 FieldType (com.qcadoo.model.api.types.FieldType)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 ManyToManyType (com.qcadoo.model.api.types.ManyToManyType)1 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)1 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)1 FieldDefinitionImpl (com.qcadoo.model.internal.FieldDefinitionImpl)1 DecimalType (com.qcadoo.model.internal.types.DecimalType)1 EnumType (com.qcadoo.model.internal.types.EnumType)1 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)1 ComponentOption (com.qcadoo.view.internal.ComponentOption)1 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)1 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)1