Search in sources :

Example 1 with RangeValidator

use of com.qcadoo.model.internal.validators.RangeValidator in project qcadoo by qcadoo.

the class ValidatorTest method shouldHasErrorsIfIntegerValueIsOutsideTheRange.

@Test
public void shouldHasErrorsIfIntegerValueIsOutsideTheRange() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("age", "11");
    fieldDefinitionAge.withValidator(new RangeValidator(null, 10, true));
    // 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) RangeValidator(com.qcadoo.model.internal.validators.RangeValidator) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 2 with RangeValidator

use of com.qcadoo.model.internal.validators.RangeValidator in project qcadoo by qcadoo.

the class ValidatorTest method shouldHasNoErrorsIfDateValueIsInsideTheRange.

@Test
public void shouldHasNoErrorsIfDateValueIsInsideTheRange() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("birthDate", "2010-01-01");
    fieldDefinitionBirthDate.withValidator(new RangeValidator(null, new Date(), true));
    // when
    entity = dataDefinition.save(entity);
    // then
    verify(session).save(any(SampleSimpleDatabaseObject.class));
    assertTrue(entity.isValid());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) RangeValidator(com.qcadoo.model.internal.validators.RangeValidator) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Date(java.util.Date) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 3 with RangeValidator

use of com.qcadoo.model.internal.validators.RangeValidator in project qcadoo by qcadoo.

the class ValidatorTest method shouldHasErrorsIfStringValueIsOutsideTheRange.

@Test
public void shouldHasErrorsIfStringValueIsOutsideTheRange() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "ddd");
    fieldDefinitionName.withValidator(new RangeValidator("a", "c", true));
    // 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) RangeValidator(com.qcadoo.model.internal.validators.RangeValidator) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 4 with RangeValidator

use of com.qcadoo.model.internal.validators.RangeValidator in project qcadoo by qcadoo.

the class ValidatorTest method shouldHasNoErrorsIfBigDecimalValueIsInsideTheRange.

@Test
public void shouldHasNoErrorsIfBigDecimalValueIsInsideTheRange() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("money", "31.22");
    fieldDefinitionMoney.withValidator(new RangeValidator(30, 40, true));
    // when
    entity = dataDefinition.save(entity);
    // then
    verify(session).save(any(SampleSimpleDatabaseObject.class));
    assertTrue(entity.isValid());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) RangeValidator(com.qcadoo.model.internal.validators.RangeValidator) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 5 with RangeValidator

use of com.qcadoo.model.internal.validators.RangeValidator in project qcadoo by qcadoo.

the class ValidatorTest method shouldHasErrorsIfDateValueIsOutsideTheRange.

@Test
public void shouldHasErrorsIfDateValueIsOutsideTheRange() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("birthDate", "2010-01-01");
    fieldDefinitionBirthDate.withValidator(new RangeValidator(new Date(), new Date(), true));
    // 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) RangeValidator(com.qcadoo.model.internal.validators.RangeValidator) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Date(java.util.Date) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Aggregations

Entity (com.qcadoo.model.api.Entity)9 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)9 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)9 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)9 RangeValidator (com.qcadoo.model.internal.validators.RangeValidator)9 Test (org.junit.Test)9 Date (java.util.Date)2