Search in sources :

Example 1 with RegexValidator

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

the class ValidatorTest method shouldHasErrorsIfStringNotMatchExpression.

@Test
public void shouldHasErrorsIfStringNotMatchExpression() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "Qcadoo Framework RLZ!");
    fieldDefinitionName.withValidator(new RegexValidator(".*MES.*"));
    // 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) RegexValidator(com.qcadoo.model.internal.validators.RegexValidator) 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 RegexValidator

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

the class ValidatorTest method shouldHaveNoErrorsIfStringMatchExpression.

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