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