use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldIgnoreUnscaledValueValidatorForStringValue.
@Test
public void shouldIgnoreUnscaledValueValidatorForStringValue() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Qcadoo Framework RLZ!");
fieldDefinitionName.withValidator(new UnscaledValueValidator(null, 1, null));
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfIntegerValueIsOutsideTheRange.
@Test
public void shouldHasErrorsIfIntegerValueIsOutsideTheRange() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", "11");
fieldDefinitionAge.withValidator(new RangeValidator(null, 10, true));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity 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());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorIfCustomEntityValidatorReturnsTrue.
@Test
public void shouldHasNoErrorIfCustomEntityValidatorReturnsTrue() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Mr T");
entity.setField("age", "18");
dataDefinition.addValidatorHook(new CustomEntityValidator(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "hasAge18AndNameMrT", PLUGIN_IDENTIFIER, applicationContext)));
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorsIfUpdatedFieldIsNotDuplicated.
@Test
public void shouldHasNoErrorsIfUpdatedFieldIsNotDuplicated() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition, 1L);
entity.setField("name", "not existed");
SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
given(session.get(SampleSimpleDatabaseObject.class, 1L)).willReturn(databaseObject);
given(criteria.uniqueResult()).willReturn(0);
fieldDefinitionName.withValidator(new UniqueValidator());
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
Aggregations