Search in sources :

Example 1 with TestPartEntity

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);
}
Also used : TestMasterEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) TestPartEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity) TestEmbeddableEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity)

Example 2 with TestPartEntity

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);
}
Also used : TestMasterEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) TestPartEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity) TestEmbeddableEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity)

Example 3 with TestPartEntity

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);
}
Also used : TestPartEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity) TestEmbeddableEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity) TestMasterEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity) Entity(com.haulmont.cuba.core.entity.Entity) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) CommitContext(com.haulmont.cuba.core.global.CommitContext) TestPartEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity) Test(org.junit.Test)

Example 4 with TestPartEntity

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);
}
Also used : TestPartEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity) TestEmbeddableEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity) TestMasterEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity) Entity(com.haulmont.cuba.core.entity.Entity) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) PersistenceHelper(com.haulmont.cuba.core.global.PersistenceHelper) TestMasterEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity) CommitContext(com.haulmont.cuba.core.global.CommitContext) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) TestPartEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

TestDetailEntity (com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity)4 TestEmbeddableEntity (com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity)4 TestMasterEntity (com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity)4 TestPartEntity (com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity)4 Entity (com.haulmont.cuba.core.entity.Entity)2 CommitContext (com.haulmont.cuba.core.global.CommitContext)2 Test (org.junit.Test)2 PersistenceHelper (com.haulmont.cuba.core.global.PersistenceHelper)1 NonStrictExpectations (mockit.NonStrictExpectations)1