Search in sources :

Example 1 with CustomValidator

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

the class ValidatorTest method shouldCallFieldValidatorIfSourcePluginIsEnabled.

@Test
public final void shouldCallFieldValidatorIfSourcePluginIsEnabled() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "not equals to qwerty string");
    fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", PLUGIN_IDENTIFIER, applicationContext)));
    stubPluginIsEnabled(true);
    // 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) CustomEntityService(com.qcadoo.model.beans.sample.CustomEntityService) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldHookDefinitionImpl(com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) CustomValidator(com.qcadoo.model.internal.validators.CustomValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 2 with CustomValidator

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

the class ValidatorTest method shouldNotCallFieldValidatorIfSourcePluginIsNotEnabled.

@Test
public final void shouldNotCallFieldValidatorIfSourcePluginIsNotEnabled() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "EverythingButNotQWERTY :)");
    fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", 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) FieldHookDefinitionImpl(com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl) CustomValidator(com.qcadoo.model.internal.validators.CustomValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 3 with CustomValidator

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

the class ValidatorTest method shouldHasNoErrorIfCustomValidatorReturnsTrue.

@Test
public void shouldHasNoErrorIfCustomValidatorReturnsTrue() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "qwerty");
    fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", PLUGIN_IDENTIFIER, applicationContext)));
    // 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) CustomEntityService(com.qcadoo.model.beans.sample.CustomEntityService) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldHookDefinitionImpl(com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) CustomValidator(com.qcadoo.model.internal.validators.CustomValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 4 with CustomValidator

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

the class ValidatorTest method shouldHaveErrorIfCustomValidatorReturnsFalse.

@Test
public void shouldHaveErrorIfCustomValidatorReturnsFalse() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "qwert");
    fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", PLUGIN_IDENTIFIER, applicationContext)));
    // when
    entity = dataDefinition.save(entity);
    // then
    verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
    assertFalse(entity.isValid());
    assertEquals(1, entity.getErrors().size());
    assertEquals("qcadooView.validate.field.error.custom", entity.getError("name").getMessage());
    assertEquals(0, entity.getGlobalErrors().size());
}
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) FieldHookDefinitionImpl(com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) CustomValidator(com.qcadoo.model.internal.validators.CustomValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Aggregations

Entity (com.qcadoo.model.api.Entity)4 CustomEntityService (com.qcadoo.model.beans.sample.CustomEntityService)4 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)4 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)4 FieldHookDefinitionImpl (com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl)4 CustomValidator (com.qcadoo.model.internal.validators.CustomValidator)4 Test (org.junit.Test)4 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)3