Search in sources :

Example 1 with PersistenceHelper

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);
}
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

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