Search in sources :

Example 66 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity 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 67 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity 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 68 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.

the class ValidatorTest method shouldNotCallEntityValidatorIfSourcePluginIsNotEnabled.

@Test
public final void shouldNotCallEntityValidatorIfSourcePluginIsNotEnabled() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    dataDefinition.addValidatorHook(new CustomEntityValidator(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "hasAge18AndNameMrT", PLUGIN_IDENTIFIER, applicationContext)));
    stubPluginIsEnabled(false);
    // when
    Entity savedEntity = dataDefinition.save(entity);
    // then
    assertTrue(savedEntity.isValid());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) CustomEntityService(com.qcadoo.model.beans.sample.CustomEntityService) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) CustomEntityValidator(com.qcadoo.model.internal.validators.CustomEntityValidator) EntityHookDefinitionImpl(com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 69 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.

the class ValidatorTest method shouldHasNoErrorsIfIntegerValueIsInsideTheRange.

@Test
public void shouldHasNoErrorsIfIntegerValueIsInsideTheRange() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("age", 5);
    fieldDefinitionAge.withValidator(new RangeValidator(4, null, 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 70 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity 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

DefaultEntity (com.qcadoo.model.internal.DefaultEntity)92 Test (org.junit.Test)91 Entity (com.qcadoo.model.api.Entity)90 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)66 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)53 EntityHookDefinitionImpl (com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl)16 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)12 DataDefinition (com.qcadoo.model.api.DataDefinition)10 RangeValidator (com.qcadoo.model.internal.validators.RangeValidator)9 CustomEntityService (com.qcadoo.model.beans.sample.CustomEntityService)8 LengthValidator (com.qcadoo.model.internal.validators.LengthValidator)8 UnscaledValueValidator (com.qcadoo.model.internal.validators.UnscaledValueValidator)8 JSONObject (org.json.JSONObject)8 BigDecimal (java.math.BigDecimal)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 ScaleValidator (com.qcadoo.model.internal.validators.ScaleValidator)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 FieldHookDefinitionImpl (com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl)4 CustomEntityValidator (com.qcadoo.model.internal.validators.CustomEntityValidator)4