use of com.qcadoo.model.internal.types.DecimalType 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);
}
use of com.qcadoo.model.internal.types.DecimalType in project qcadoo by qcadoo.
the class FieldTypeFactoryTest method shouldReturnDecimalType.
@Test
public void shouldReturnDecimalType() throws Exception {
// when
FieldType fieldType = new DecimalType();
// then
assertEquals(BigDecimal.class, fieldType.getType());
assertTrue(fieldType.toObject(fieldDefinition, BigDecimal.valueOf(1.21)).isValid());
assertTrue(fieldType.toObject(fieldDefinition, BigDecimal.valueOf(1)).isValid());
assertTrue(fieldType.toObject(fieldDefinition, BigDecimal.valueOf(1)).isValid());
assertTrue(fieldType.toObject(fieldDefinition, BigDecimal.valueOf(1234567)).isValid());
}
Aggregations