use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ExpressionUtilTest method shouldGenerateValueOfTheMultiFieldColumn.
@Test
public void shouldGenerateValueOfTheMultiFieldColumn() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
Entity entity = new DefaultEntity(dataDefinition, 1L);
entity.setField("name", "Mr T");
entity.setField("age", 33);
entity.setField("sex", "F");
given(dataDefinition.getField(eq("name")).getType().toString(eq("Mr T"), eq(Locale.ENGLISH))).willReturn("Mr X");
given(dataDefinition.getField(eq("sex")).getType().toString(eq("F"), eq(Locale.ENGLISH))).willReturn("F");
given(dataDefinition.getField(eq("age")).getType().toString(eq(33), eq(Locale.ENGLISH))).willReturn("34");
// when
String value = expressionService.getValue(entity, "#name + \" -> (\" + (#age) + \") -> \" + (#sex == \"F\" ? \"female\" : \"male\") + \".\"", Locale.ENGLISH);
// then
assertEquals("Mr X -> (34) -> female.", value);
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ExpressionUtilTest method shouldGenerateValueOfTheSingleFieldColumn.
@Test
public void shouldGenerateValueOfTheSingleFieldColumn() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
Entity entity = new DefaultEntity(dataDefinition, 1L);
entity.setField("name", "Mr T");
given(dataDefinition.getField(eq("name")).getType().toString(eq("Mr T"), eq(Locale.ENGLISH))).willReturn("Mr X");
// when
String value = expressionService.getValue(entity, "#name.toUpperCase()", Locale.ENGLISH);
// then
assertEquals("MR X", value);
}
use of com.qcadoo.model.internal.DefaultEntity 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);
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfBigDecimalScaleIsNotEqual.
@Test
public void shouldHasErrorsIfBigDecimalScaleIsNotEqual() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", new BigDecimal("123.45"));
fieldDefinitionMoney.withValidator(new ScaleValidator(null, 4, null));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfStringIsTooShort.
@Test
public void shouldHasErrorsIfStringIsTooShort() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Qcadoo Framework RLZ!");
fieldDefinitionName.withValidator(new LengthValidator(50, null, null));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
Aggregations