use of com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity in project cuba by cuba-platform.
the class CollectionDatasourceTest method testRemoveThenAdd.
@Test
public void testRemoveThenAdd() throws Exception {
CollectionDatasourceImpl<TestMasterEntity, UUID> cds = new CollectionDatasourceImpl<>();
cds.setMetaClass(metadata.getClassNN(TestMasterEntity.class));
cds.setRefreshMode(CollectionDatasource.RefreshMode.NEVER);
TestMasterEntity entity = new TestMasterEntity();
entity.setMasterName("master");
BaseEntityInternalAccess.setNew(entity, false);
BaseEntityInternalAccess.setDetached(entity, true);
cds.data.put(entity.getId(), entity);
cds.removeItem(entity);
cds.addItem(entity);
assertEquals(0, cds.itemsToCreate.size());
assertEquals(1, cds.itemsToUpdate.size());
assertEquals(0, cds.itemsToDelete.size());
}
use of com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity 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