Search in sources :

Example 1 with LengthValidator

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

Example 2 with LengthValidator

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

the class ValidatorTest method shouldHasErrorsIfStringValueIsTooLong.

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

Example 3 with LengthValidator

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

the class ValidatorTest method shouldIgnoreLengthValidatorForIntegerValue.

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

Example 4 with LengthValidator

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

the class ValidatorTest method shouldHasNoCheckLenghtOfBoolean.

@Test
public void shouldHasNoCheckLenghtOfBoolean() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("retired", false);
    fieldDefinitionRetired.withValidator(new LengthValidator(null, null, 0));
    // 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) LengthValidator(com.qcadoo.model.internal.validators.LengthValidator) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 5 with LengthValidator

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

the class ValidatorTest method shouldHasErrorsIfStringLengthIsNotEqual.

@Test
public void shouldHasErrorsIfStringLengthIsNotEqual() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "Qcadoo Framework RLZ!");
    fieldDefinitionName.withValidator(new LengthValidator(null, 4, null));
    // 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) LengthValidator(com.qcadoo.model.internal.validators.LengthValidator) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Aggregations

Entity (com.qcadoo.model.api.Entity)8 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)8 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)8 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)8 LengthValidator (com.qcadoo.model.internal.validators.LengthValidator)8 Test (org.junit.Test)8 BigDecimal (java.math.BigDecimal)1