Search in sources :

Example 1 with TreeEntitiesType

use of com.qcadoo.model.internal.types.TreeEntitiesType in project qcadoo by qcadoo.

the class DataAccessServiceCopyTest method shouldCopyEntityWithTreeField.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldCopyEntityWithTreeField() throws Exception {
    // given
    parentFieldDefinitionTree.withType(new TreeEntitiesType("tree", "entity", "owner", TreeType.Cascade.DELETE, true, dataDefinitionService));
    SampleTreeDatabaseObject treeDatabaseObject = new SampleTreeDatabaseObject();
    treeDatabaseObject.setId(12L);
    treeDatabaseObject.setName("Mr T");
    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(treeDatabaseObject);
    given(session.get(Mockito.eq(SampleParentDatabaseObject.class), Mockito.eq(13L))).willReturn(parentDatabaseObject);
    given(hibernateService.list(Mockito.any(Criteria.class))).willReturn((List) Lists.newArrayList(treeDatabaseObject));
    // 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());
}
Also used : Entity(com.qcadoo.model.api.Entity) SampleParentDatabaseObject(com.qcadoo.model.beans.sample.SampleParentDatabaseObject) SampleTreeDatabaseObject(com.qcadoo.model.beans.sample.SampleTreeDatabaseObject) TreeEntitiesType(com.qcadoo.model.internal.types.TreeEntitiesType) Criteria(org.hibernate.Criteria) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Aggregations

Entity (com.qcadoo.model.api.Entity)1 SampleParentDatabaseObject (com.qcadoo.model.beans.sample.SampleParentDatabaseObject)1 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)1 SampleTreeDatabaseObject (com.qcadoo.model.beans.sample.SampleTreeDatabaseObject)1 TreeEntitiesType (com.qcadoo.model.internal.types.TreeEntitiesType)1 Criteria (org.hibernate.Criteria)1 Test (org.junit.Test)1