use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity in project cuba by cuba-platform.
the class DsContextApplyChangesTest method createEntities.
private void createEntities() {
master = new TestMasterEntity();
master.setMasterName("master");
detail1 = new TestDetailEntity();
detail1.setDetailName("detail1");
detail1.setMaster(master);
detail1.setParts(new HashSet<TestPartEntity>());
embeddable1 = new TestEmbeddableEntity();
embeddable1.setName("embeddable1");
detail1.setEmbeddable(embeddable1);
master.setDetail(detail1);
}
use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity in project cuba by cuba-platform.
the class CollectionDatasourceTest method testRemoveThenAddToPropertyDs.
@Test
public void testRemoveThenAddToPropertyDs() throws Exception {
DatasourceImpl<TestMasterEntity> ds = new DatasourceImpl<>();
ds.setMetaClass(metadata.getClassNN(TestMasterEntity.class));
ds.initialized();
CollectionPropertyDatasourceImpl<TestDetailEntity, UUID> cpds = new CollectionPropertyDatasourceImpl<>();
cpds.masterDs = ds;
cpds.metaProperty = ds.getMetaClass().getProperty("details");
TestMasterEntity masterEntity = new TestMasterEntity();
masterEntity.setMasterName("master");
masterEntity.setDetails(new HashSet<>());
ds.setItem(masterEntity);
TestDetailEntity detailEntity = new TestDetailEntity();
BaseEntityInternalAccess.setNew(detailEntity, false);
BaseEntityInternalAccess.setDetached(detailEntity, true);
detailEntity.setMaster(masterEntity);
detailEntity.setDetailName("detail");
masterEntity.getDetails().add(detailEntity);
cpds.removeItem(detailEntity);
cpds.addItem(detailEntity);
assertEquals(0, cpds.itemsToCreate.size());
assertEquals(1, cpds.itemsToUpdate.size());
assertEquals(0, cpds.itemsToDelete.size());
}
use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity in project cuba by cuba-platform.
the class DsContextTest method createEntities.
private void createEntities() {
master = new TestMasterEntity();
master.setMasterName("master");
master.setDetails(new HashSet<TestDetailEntity>());
detail1 = new TestDetailEntity();
detail1.setDetailName("detail1");
detail1.setMaster(master);
detail1.setParts(new HashSet<TestPartEntity>());
embeddable1 = new TestEmbeddableEntity();
embeddable1.setName("embeddable1");
detail1.setEmbeddable(embeddable1);
detail1.setMaster(master);
part1 = new TestPartEntity();
part1.setPartName("part1");
part1.setDetail(detail1);
detail1.getParts().add(part1);
master.getDetails().add(detail1);
detail2 = new TestDetailEntity();
detail2.setDetailName("detail2");
detail2.setMaster(master);
master.getDetails().add(detail2);
}
use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity in project cuba by cuba-platform.
the class DsContextTest method testAggregationNewEntity.
@Test
public void testAggregationNewEntity() {
// Master editor
createMasterDsContext();
final TestMasterEntity master = new TestMasterEntity();
master.setMasterName("new_master");
masterDs.setItem(master);
final TestDetailEntity detail = new TestDetailEntity();
detail.setMaster(master);
createDetailDsContext();
setupParentDs(detailsDs, detailDs, detail);
detailDs.getItem().setDetailName("new_detail");
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals(0, dataService.commitCount, "Commit Detail DsContext");
// Commit Master editor
dataService.commitValidator = new TestDataSupplier.CommitValidator() {
@Override
public void validate(CommitContext context) {
assertTrue(containsEntityInstance(context.getCommitInstances(), detail.getId()));
assertTrue(containsEntityInstance(context.getCommitInstances(), master.getId()));
for (Entity entity : context.getCommitInstances()) {
if (entity.getId().equals(detail.getId()))
assertEquals("new_detail", ((TestDetailEntity) entity).getDetailName());
}
}
};
masterDsContext.commit();
assertEquals(1, dataService.commitCount, "Commit Master DsContext");
}
use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity in project cuba by cuba-platform.
the class DsContextTest method testNestedAggregationNewEntity.
@Test
public void testNestedAggregationNewEntity() {
new Expectations() {
{
PersistenceHelper.isNew(any);
result = true;
minTimes = 0;
}
};
// Master editor
createMasterDsContext();
final TestMasterEntity master = new TestMasterEntity();
master.setMasterName("new_master");
masterDs.setItem(master);
// Detail editor
final TestDetailEntity detail = new TestDetailEntity();
detail.setMaster(master);
createDetailDsContext();
setupParentDs(detailsDs, detailDs, detail);
detailDs.getItem().setDetailName("new_detail");
// Part editor
final TestPartEntity part = new TestPartEntity();
part.setDetail(detail);
createPartDsContext();
setupParentDs(partsDs, partDs, part);
// Edit item in Datasource
partDs.getItem().setPartName("new_part");
// Commit Part editor
dataService.commitValidator = null;
partDsContext.commit();
assertEquals(0, dataService.commitCount, "Commit Part");
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals(0, dataService.commitCount, "Commit Detail DsContext");
// Commit Master editor
dataService.commitValidator = new TestDataSupplier.CommitValidator() {
@Override
public void validate(CommitContext context) {
assertTrue(containsEntityInstance(context.getCommitInstances(), detail.getId()));
assertTrue(containsEntityInstance(context.getCommitInstances(), master.getId()));
assertTrue(containsEntityInstance(context.getCommitInstances(), part.getId()));
for (Entity entity : context.getCommitInstances()) {
if (entity.getId().equals(detail.getId()))
assertEquals("new_detail", ((TestDetailEntity) entity).getDetailName());
if (entity.getId().equals(part.getId()))
assertEquals("new_part", ((TestPartEntity) entity).getPartName());
}
}
};
masterDsContext.commit();
assertEquals(1, dataService.commitCount, "Commit Master DsContext");
}
Aggregations