use of com.qcadoo.model.internal.validators.RequiredValidator in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorMessage.
@Test
public void shouldHasErrorMessage() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", "");
fieldDefinitionAge.withValidator(new RequiredValidator());
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
assertEquals(1, entity.getErrors().size());
assertEquals("qcadooView.validate.field.error.missing", entity.getError("age").getMessage());
assertEquals(0, entity.getGlobalErrors().size());
}
use of com.qcadoo.model.internal.validators.RequiredValidator in project qcadoo by qcadoo.
the class ValidatorTest method shouldBeRequiredIfHasRequiredValidator.
@Test
public void shouldBeRequiredIfHasRequiredValidator() throws Exception {
// given
fieldDefinitionName.withValidator(new RequiredValidator());
// then
assertTrue(fieldDefinitionName.isRequired());
}
use of com.qcadoo.model.internal.validators.RequiredValidator in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfRequiredFieldsAreNotSet.
@Test
public void shouldHasErrorsIfRequiredFieldsAreNotSet() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "");
entity.setField("age", null);
fieldDefinitionName.withValidator(new RequiredValidator());
fieldDefinitionAge.withValidator(new RequiredValidator());
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
use of com.qcadoo.model.internal.validators.RequiredValidator 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