use of com.haulmont.cuba.core.global.PersistenceHelper in project cuba by cuba-platform.
the class DsContextTest method testNestedAggregationNewEntity.
@Test
public void testNestedAggregationNewEntity() {
new NonStrictExpectations() {
@Mocked
PersistenceHelper persistenceHelper;
{
PersistenceHelper.isNew(any);
result = true;
}
};
// 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("Commit Part", 0, dataService.commitCount);
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals("Commit Detail DsContext", 0, dataService.commitCount);
// 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("Commit Master DsContext", 1, dataService.commitCount);
}
Aggregations