use of com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity 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.TestPartEntity 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.TestPartEntity in project cuba by cuba-platform.
the class DsContextTest method testNestedAggregationRepeatEdit.
@Test
public void testNestedAggregationRepeatEdit() {
createEntities();
// Master editor
createMasterDsContext();
masterDs.setItem(master);
assertEquals(detail1, detailsDs.getItem(detail1.getId()));
// Select Detail to edit
detailsDs.setItem(detail1);
// Detail editor
createDetailDsContext();
setupParentDs(detailsDs, detailDs, detail1.getId());
assertEquals(embeddable1.getId(), embeddableDs.getItem().getId());
// Select Part to edit
partsDs.setItem(part1);
// Part editor
createPartDsContext();
setupParentDs(partsDs, partDs, part1.getId());
// Edit item in Datasource
partDs.getItem().setPartName("part1_1");
// Commit Part editor
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
// Select Part to edit
partsDs.setItem(null);
partsDs.setItem(part1);
// Part editor 2nd time
createPartDsContext();
setupParentDs(partsDs, partDs, part1.getId());
assertEquals("part1_1", partDs.getItem().getPartName());
// Edit item in Datasource 2nd time
partDs.getItem().setPartName("part1_2");
// Commit Part editor 2nd time
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
// Commit Detail editor
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals("Commit Detail", 0, dataService.commitCount);
// Select Detail to edit
detailsDs.setItem(detail2);
detailsDs.setItem(detail1);
// Detail editor 2nd time
createDetailDsContext();
setupParentDs(detailsDs, detailDs, detail1.getId());
// Select Part to edit
partsDs.setItem(part1);
// Part editor 3rd time
createPartDsContext();
setupParentDs(partsDs, partDs, part1.getId());
assertEquals("part1_2", partDs.getItem().getPartName());
// Edit item in Datasource 3rd time
partDs.getItem().setPartName("part1_3");
// Commit Part editor 3rd time
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
// Add new part
final TestPartEntity newPart = new TestPartEntity();
newPart.setDetail(detail1);
newPart.setPartName("new_part");
createPartDsContext();
setupParentDs(partsDs, partDs, newPart);
// Edit item in Datasource
partDs.getItem().setPartName("new_part");
// Commit Part editor 4th time
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
// Commit Detail editor 2nd
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals("Commit Detail", 0, dataService.commitCount);
// Commit Master editor
dataService.commitValidator = new TestDataSupplier.CommitValidator() {
@Override
public void validate(CommitContext context) {
assertTrue(containsEntityInstance(context.getCommitInstances(), part1.getId()));
for (Entity entity : context.getCommitInstances()) {
if (entity.getId().equals(part1.getId())) {
assertEquals("part1_3", ((TestPartEntity) entity).getPartName());
assertTrue(((TestPartEntity) entity).getDetail() == detail1);
}
if (entity.getId().equals(newPart.getId())) {
assertEquals("new_part", ((TestPartEntity) entity).getPartName());
assertTrue(((TestPartEntity) entity).getDetail() == detail1);
}
}
}
};
masterDsContext.commit();
assertEquals("Commits Master", 1, dataService.commitCount);
}
use of com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity 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