use of com.qcadoo.model.internal.api.FieldHookDefinition in project qcadoo by qcadoo.
the class DataAccessServiceCopyTest method shouldCopyEntityWithUniqueField.
@Test
public void shouldCopyEntityWithUniqueField() throws Exception {
// given
FieldHookDefinition fieldHook = new UniqueValidator();
// fieldHook.initialize(dataDefinition, fieldDefinitionName);
fieldDefinitionName.withValidator(fieldHook);
SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject();
simpleDatabaseObject.setId(13L);
simpleDatabaseObject.setName("Mr T");
simpleDatabaseObject.setAge(66);
given(criteria.setProjection(Projections.rowCount()).uniqueResult()).willReturn(0);
given(session.get(any(Class.class), Matchers.anyInt())).willReturn(simpleDatabaseObject);
// when
List<Entity> entities = dataDefinition.copy(new Long[] { 13L });
// then
verify(session, times(1)).save(Mockito.any(SampleSimpleDatabaseObject.class));
assertEquals(1, entities.size());
assertTrue(entities.get(0).isValid());
Assert.assertEquals(66, entities.get(0).getField("age"));
Assert.assertEquals("Mr T(1)", entities.get(0).getField(NAME));
}
use of com.qcadoo.model.internal.api.FieldHookDefinition in project qcadoo by qcadoo.
the class DecimalType method getMissingValidators.
@Override
public Collection<FieldHookDefinition> getMissingValidators(final Iterable<FieldHookDefinition> validators) {
FieldHookDefinition defaultScaleValidator = new ScaleValidator(null, null, NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL);
FieldHookDefinition defaultUnscaledValueValidator = new UnscaledValueValidator(null, null, NumberService.DEFAULT_MAX_INTEGER_DIGITS_IN_DECIMAL);
Set<FieldHookDefinition> missingValidators = Sets.<FieldHookDefinition>newHashSet(defaultScaleValidator, defaultUnscaledValueValidator);
for (FieldHookDefinition validator : validators) {
if (validator instanceof UnscaledValueValidator && ((UnscaledValueValidator) validator).hasUppuerBoundDefined()) {
missingValidators.remove(defaultUnscaledValueValidator);
}
if (validator instanceof ScaleValidator && ((ScaleValidator) validator).hasUppuerBoundDefined()) {
missingValidators.remove(defaultScaleValidator);
}
}
return missingValidators;
}
use of com.qcadoo.model.internal.api.FieldHookDefinition in project qcadoo by qcadoo.
the class DataAccessServiceCopyTest method shouldCopyEntityWithUniqueFieldWhenNull.
@Test
public void shouldCopyEntityWithUniqueFieldWhenNull() throws Exception {
// given
FieldHookDefinition fieldHook = new UniqueValidator();
// fieldHook.initialize(dataDefinition, fieldDefinitionName);
fieldDefinitionName.withValidator(fieldHook);
SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject();
simpleDatabaseObject.setId(13L);
simpleDatabaseObject.setName(null);
simpleDatabaseObject.setAge(66);
given(hibernateService.getTotalNumberOfEntities(Mockito.any(Criteria.class))).willReturn(0);
given(session.get(any(Class.class), Matchers.anyInt())).willReturn(simpleDatabaseObject);
// when
List<Entity> entities = dataDefinition.copy(new Long[] { 13L });
// then
verify(session, times(1)).save(Mockito.any(SampleSimpleDatabaseObject.class));
assertEquals(1, entities.size());
assertTrue(entities.get(0).isValid());
Assert.assertEquals(66, entities.get(0).getField("age"));
Assert.assertEquals(null, entities.get(0).getField(NAME));
}
use of com.qcadoo.model.internal.api.FieldHookDefinition in project qcadoo by qcadoo.
the class DataAccessServiceCopyTest method shouldCopyEntityWithUniqueField2.
@Test
public void shouldCopyEntityWithUniqueField2() throws Exception {
// given
FieldHookDefinition fieldHook = new UniqueValidator();
// fieldHook.initialize(dataDefinition, fieldDefinitionName);
fieldDefinitionName.withValidator(fieldHook);
SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject();
simpleDatabaseObject.setId(13L);
simpleDatabaseObject.setName("Mr T(1)");
simpleDatabaseObject.setAge(66);
given(hibernateService.getTotalNumberOfEntities(Mockito.any(Criteria.class))).willReturn(1, 0);
given(session.get(any(Class.class), Matchers.anyInt())).willReturn(simpleDatabaseObject);
// when
List<Entity> entities = dataDefinition.copy(new Long[] { 13L });
// then
verify(session, times(1)).save(Mockito.any(SampleSimpleDatabaseObject.class));
assertEquals(1, entities.size());
assertTrue(entities.get(0).isValid());
Assert.assertEquals(66, entities.get(0).getField("age"));
Assert.assertEquals("Mr T(3)", entities.get(0).getField(NAME));
}
Aggregations