Search in sources :

Example 1 with TestDetailEntity

use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity 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 TestDetailEntity

use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity in project cuba by cuba-platform.

the class CollectionDatasourceTest method testRemoveThenAddToPropertyDs.

@Test
public void testRemoveThenAddToPropertyDs() throws Exception {
    DatasourceImpl<TestMasterEntity> ds = new DatasourceImpl<>();
    ds.setMetaClass(metadata.getClassNN(TestMasterEntity.class));
    ds.initialized();
    CollectionPropertyDatasourceImpl<TestDetailEntity, UUID> cpds = new CollectionPropertyDatasourceImpl<>();
    cpds.masterDs = ds;
    cpds.metaProperty = ds.getMetaClass().getProperty("details");
    TestMasterEntity masterEntity = new TestMasterEntity();
    masterEntity.setMasterName("master");
    masterEntity.setDetails(new HashSet<>());
    ds.setItem(masterEntity);
    TestDetailEntity detailEntity = new TestDetailEntity();
    BaseEntityInternalAccess.setNew(detailEntity, false);
    BaseEntityInternalAccess.setDetached(detailEntity, true);
    detailEntity.setMaster(masterEntity);
    detailEntity.setDetailName("detail");
    masterEntity.getDetails().add(detailEntity);
    cpds.removeItem(detailEntity);
    cpds.addItem(detailEntity);
    assertEquals(0, cpds.itemsToCreate.size());
    assertEquals(1, cpds.itemsToUpdate.size());
    assertEquals(0, cpds.itemsToDelete.size());
}
Also used : TestMasterEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 3 with TestDetailEntity

use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity 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 4 with TestDetailEntity

use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity in project cuba by cuba-platform.

the class DsContextTest method testAggregationNewEntity.

@Test
public void testAggregationNewEntity() {
    // Master editor
    createMasterDsContext();
    final TestMasterEntity master = new TestMasterEntity();
    master.setMasterName("new_master");
    masterDs.setItem(master);
    final TestDetailEntity detail = new TestDetailEntity();
    detail.setMaster(master);
    createDetailDsContext();
    setupParentDs(detailsDs, detailDs, detail);
    detailDs.getItem().setDetailName("new_detail");
    dataService.commitValidator = null;
    detailDsContext.commit();
    assertEquals(0, dataService.commitCount, "Commit Detail DsContext");
    // 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()));
            for (Entity entity : context.getCommitInstances()) {
                if (entity.getId().equals(detail.getId()))
                    assertEquals("new_detail", ((TestDetailEntity) entity).getDetailName());
            }
        }
    };
    masterDsContext.commit();
    assertEquals(1, dataService.commitCount, "Commit Master DsContext");
}
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) 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) Test(org.junit.jupiter.api.Test)

Example 5 with TestDetailEntity

use of com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity in project cuba by cuba-platform.

the class DsContextTest method testNestedAggregationNewEntity.

@Test
public void testNestedAggregationNewEntity() {
    new Expectations() {

        {
            PersistenceHelper.isNew(any);
            result = true;
            minTimes = 0;
        }
    };
    // 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(0, dataService.commitCount, "Commit Part");
    dataService.commitValidator = null;
    detailDsContext.commit();
    assertEquals(0, dataService.commitCount, "Commit Detail DsContext");
    // 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(1, dataService.commitCount, "Commit Master DsContext");
}
Also used : Expectations(mockit.Expectations) 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) 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) Test(org.junit.jupiter.api.Test)

Aggregations

TestDetailEntity (com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity)5 TestMasterEntity (com.haulmont.cuba.gui.data.impl.testmodel1.TestMasterEntity)5 TestEmbeddableEntity (com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity)4 TestPartEntity (com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity)4 Test (org.junit.jupiter.api.Test)3 Entity (com.haulmont.cuba.core.entity.Entity)2 CommitContext (com.haulmont.cuba.core.global.CommitContext)2 UUID (java.util.UUID)1 Expectations (mockit.Expectations)1