Search in sources :

Example 6 with LengthValidator

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

the class ValidatorTest method shouldHasNoErrorsIfStringValueLenghtIsOk.

@Test
public void shouldHasNoErrorsIfStringValueLenghtIsOk() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "qwert");
    fieldDefinitionName.withValidator(new LengthValidator(null, null, 5));
    // 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 7 with LengthValidator

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

the class ValidatorTest method shouldIgnoreLengthValidatorForBigDecimalValue.

@Test
public void shouldIgnoreLengthValidatorForBigDecimalValue() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("money", new BigDecimal("123.456"));
    fieldDefinitionMoney.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) BigDecimal(java.math.BigDecimal) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 8 with LengthValidator

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

the class ValidatorTest method shouldHasNoCheckLenghtOfDate.

@Test
public void shouldHasNoCheckLenghtOfDate() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("birthDate", "2010-01-01");
    fieldDefinitionBirthDate.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)

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