use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorsIfBigDecimalValuePresicionAndScaleIsOk.
@Test
public void shouldHasNoErrorsIfBigDecimalValuePresicionAndScaleIsOk() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", new BigDecimal("123.4"));
fieldDefinitionMoney.withValidator(new UnscaledValueValidator(null, null, 3)).withValidator(new ScaleValidator(null, null, 1));
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorIfBooleanTypeIsWrong.
@Test
public void shouldHasErrorIfBooleanTypeIsWrong() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", "a");
// 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 shouldIgnoreScaleValidatorForStringValue.
@Test
public void shouldIgnoreScaleValidatorForStringValue() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Qcadoo Framework RLZ!");
fieldDefinitionName.withValidator(new ScaleValidator(null, 1, null));
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorsIfAllFieldAreNotRequired.
@Test
public void shouldHasNoErrorsIfAllFieldAreNotRequired() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", null);
entity.setField("age", null);
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
assertTrue(entity.getErrors().isEmpty());
assertTrue(entity.getGlobalErrors().isEmpty());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasCustomErrorMessage.
@Test
public void shouldHasCustomErrorMessage() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", "");
RequiredValidator requiredValidator = new RequiredValidator();
requiredValidator.setErrorMessage("missing age");
fieldDefinitionAge.withValidator(requiredValidator);
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
assertEquals(1, entity.getErrors().size());
assertEquals("missing age", entity.getError("age").getMessage());
assertEquals(0, entity.getGlobalErrors().size());
}
Aggregations