use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject 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.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class DataAccessServiceCopyTest method shouldCopyEntity.
@Test
public void shouldCopyEntity() throws Exception {
// given
SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject();
simpleDatabaseObject.setId(13L);
simpleDatabaseObject.setName("Mr T");
simpleDatabaseObject.setAge(66);
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", entities.get(0).getField(NAME));
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class DataAccessServiceCopyTest method shouldCopyEntityWithHasManyField.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void shouldCopyEntityWithHasManyField() throws Exception {
// given
parentFieldDefinitionHasMany.withType(new HasManyEntitiesType("simple", "entity", "belongsTo", HasManyType.Cascade.DELETE, true, dataDefinitionService));
SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject();
simpleDatabaseObject.setId(12L);
simpleDatabaseObject.setName("Mr T");
simpleDatabaseObject.setAge(66);
SampleParentDatabaseObject parentDatabaseObject = new SampleParentDatabaseObject();
parentDatabaseObject.setId(13L);
parentDatabaseObject.setName("Mr T");
given(hibernateService.getTotalNumberOfEntities(Mockito.any(Criteria.class))).willReturn(1, 0);
given(session.get(Mockito.eq(SampleSimpleDatabaseObject.class), Mockito.eq(12L))).willReturn(simpleDatabaseObject);
given(session.get(Mockito.eq(SampleParentDatabaseObject.class), Mockito.eq(13L))).willReturn(parentDatabaseObject);
given(hibernateService.list(Mockito.any(Criteria.class))).willReturn((List) Lists.newArrayList(simpleDatabaseObject));
// when
List<Entity> entities = parentDataDefinition.copy(new Long[] { 13L });
// then
assertEquals(1, entities.size());
assertTrue(entities.get(0).isValid());
Assert.assertEquals("Mr T", entities.get(0).getField(NAME));
verify(session, times(2)).save(Mockito.any());
verify(session, never()).get(Mockito.eq(SampleSimpleDatabaseObject.class), anyInt());
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class DataAccessServiceDeleteTest method shouldProperlyDelete.
@Test
public void shouldProperlyDelete() throws Exception {
// given
SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject();
simpleDatabaseObject.setId(1L);
simpleDatabaseObject.setName("Mr T");
simpleDatabaseObject.setAge(66);
given(session.get(SampleSimpleDatabaseObject.class, 1L)).willReturn(simpleDatabaseObject);
// when
dataDefinition.delete(1L);
// then
verify(session).delete(simpleDatabaseObject);
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldReturnNullWhileGettingEmptyField.
@Test
public void shouldReturnNullWhileGettingEmptyField() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
// when
Object value = entityService.getField(databaseEntity, fieldDefinitionName);
// then
assertNull(value);
}
Aggregations