Search in sources :

Example 6 with UnscaledValueValidator

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

the class ValidatorTest method shouldHasErrorsIfIntegerValueIsTooLong.

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

Example 7 with UnscaledValueValidator

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

the class ValidatorTest method shouldHasNoErrorsIfBigDecimalValuePresicionAndScaleIsOk.

@Test
public void shouldHasNoErrorsIfBigDecimalValuePresicionAndScaleIsOk() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("money", new BigDecimal("123.4"));
    fieldDefinitionMoney.withValidator(new UnscaledValueValidator(null, null, 3)).withValidator(new ScaleValidator(null, null, 1));
    // 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) UnscaledValueValidator(com.qcadoo.model.internal.validators.UnscaledValueValidator) ScaleValidator(com.qcadoo.model.internal.validators.ScaleValidator) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) BigDecimal(java.math.BigDecimal) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 8 with UnscaledValueValidator

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

the class ValidatorTest method shouldHasErrorsIfBigDecimalUnscaledValueAreTooShort.

@Test
public void shouldHasErrorsIfBigDecimalUnscaledValueAreTooShort() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("money", new BigDecimal("123.45"));
    fieldDefinitionMoney.withValidator(new UnscaledValueValidator(5, 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) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) UnscaledValueValidator(com.qcadoo.model.internal.validators.UnscaledValueValidator) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) BigDecimal(java.math.BigDecimal) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 9 with UnscaledValueValidator

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

the class ValidatorTest method shouldHasErrorsIfIntegerUnscaledValueAreTooShort.

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

Aggregations

UnscaledValueValidator (com.qcadoo.model.internal.validators.UnscaledValueValidator)9 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 Test (org.junit.Test)8 BigDecimal (java.math.BigDecimal)4 ScaleValidator (com.qcadoo.model.internal.validators.ScaleValidator)3 FieldHookDefinition (com.qcadoo.model.internal.api.FieldHookDefinition)1