use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorsIfFieldIsNotDuplicated.
@Test
public void shouldHasNoErrorsIfFieldIsNotDuplicated() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "not existed");
given(criteria.uniqueResult()).willReturn(0);
fieldDefinitionName.withValidator(new UniqueValidator());
// 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 shouldHasErrorsIfRequiredFieldsAreNotSet.
@Test
public void shouldHasErrorsIfRequiredFieldsAreNotSet() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "");
entity.setField("age", null);
fieldDefinitionName.withValidator(new RequiredValidator());
fieldDefinitionAge.withValidator(new RequiredValidator());
// 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 shouldHasErrorsIfFieldIsDuplicated.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldHasErrorsIfFieldIsDuplicated() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "existed");
given(hibernateService.getTotalNumberOfEntities(any(Criteria.class))).willReturn(1);
given(hibernateService.list(any(Criteria.class))).willReturn((List) Collections.singletonList(entity));
fieldDefinitionName.withValidator(new UniqueValidator());
// 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 shouldHasErrorsIfDateValueIsOutsideTheRange.
@Test
public void shouldHasErrorsIfDateValueIsOutsideTheRange() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("birthDate", "2010-01-01");
fieldDefinitionBirthDate.withValidator(new RangeValidator(new Date(), new Date(), 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 shouldHasErrorsIfBigDecimalScaleAreTooShort.
@Test
public void shouldHasErrorsIfBigDecimalScaleAreTooShort() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", new BigDecimal("123.45"));
fieldDefinitionMoney.withValidator(new ScaleValidator(3, null, null));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
Aggregations