Search in sources :

Example 1 with RequiredValidator

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) RequiredValidator(com.qcadoo.model.internal.validators.RequiredValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 2 with RequiredValidator

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());
}
Also used : RequiredValidator(com.qcadoo.model.internal.validators.RequiredValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 3 with RequiredValidator

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) RequiredValidator(com.qcadoo.model.internal.validators.RequiredValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 4 with RequiredValidator

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) RequiredValidator(com.qcadoo.model.internal.validators.RequiredValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Aggregations

DataAccessTest (com.qcadoo.model.internal.DataAccessTest)4 RequiredValidator (com.qcadoo.model.internal.validators.RequiredValidator)4 Test (org.junit.Test)4 Entity (com.qcadoo.model.api.Entity)3 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)3 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)3