Search in sources :

Example 16 with DsBuilder

use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.

the class OptionsGroupTest method testDatasource.

@Test
public void testDatasource() {
    OptionsGroup component = factory.createComponent(OptionsGroup.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    component.setDatasource(testDs, "group");
    assertNotNull(component.getDatasource());
}
Also used : User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 17 with DsBuilder

use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.

the class PickerFieldTest method testDatasource.

@Test
public void testDatasource() {
    PickerField component = factory.createComponent(PickerField.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    Group g = new Group();
    testDs.getItem().setGroup(g);
    Group g1 = new Group();
    Group g2 = new Group();
    component.setMetaClass(metadata.getClass(Group.class));
    component.setValue(g2);
    component.setDatasource(testDs, "group");
    assertEquals(g, component.getValue());
    component.setValue(g1);
    assertEquals(g1, testDs.getItem().getGroup());
    testDs.getItem().setGroup(g2);
    assertEquals(g2, component.getValue());
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 18 with DsBuilder

use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.

the class DsApiConsistencyTestCase method getTestCollectionDatasource.

protected CollectionDatasource<Group, UUID> getTestCollectionDatasource() {
    // noinspection unchecked
    CollectionDatasource<Group, UUID> collectionDatasource = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    for (int i = 0; i < 3; i++) {
        Group group = metadata.create(Group.class);
        group.setName("Group #" + (i + 1));
        Group parentGroup = metadata.create(Group.class);
        parentGroup.setName("Parent group #" + (i + 1));
        group.setParent(parentGroup);
        collectionDatasource.addItem(group);
    }
    ((CollectionDatasourceImpl) collectionDatasource).valid();
    return collectionDatasource;
}
Also used : Group(com.haulmont.cuba.security.entity.Group) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Example 19 with DsBuilder

use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.

the class DsApiConsistencyTestCase method getTestUserDatasource.

protected Datasource<User> getTestUserDatasource() {
    // noinspection unchecked
    Datasource<User> datasource = new DsBuilder().setId("userDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    User user = metadata.create(User.class);
    datasource.setItem(user);
    ((DatasourceImpl) datasource).valid();
    return datasource;
}
Also used : User(com.haulmont.cuba.security.entity.User) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Example 20 with DsBuilder

use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.

the class DsContextTest method createMasterDsContext.

private void createMasterDsContext() {
    masterDsContext = new DsContextImpl(dataService);
    DsBuilder masterDsBuilder = new DsBuilder(masterDsContext);
    masterDsBuilder.reset().setId("masterDs").setMetaClass(metadataSession.getClass(TestMasterEntity.class)).setViewName("withDetails");
    masterDs = masterDsBuilder.buildDatasource();
    masterDsBuilder.reset().setId("detailsDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setMaster(masterDs).setProperty("details");
    detailsDs = masterDsBuilder.buildCollectionDatasource();
    masterDsBuilder.reset().setId("masterPartsDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setMaster(detailsDs).setProperty("parts");
    masterPartsDs = masterDsBuilder.buildCollectionDatasource();
    for (Datasource ds : masterDsContext.getAll()) {
        ((DatasourceImplementation) ds).initialized();
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Aggregations

DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)23 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)18 User (com.haulmont.cuba.security.entity.User)17 Test (org.junit.Test)16 Datasource (com.haulmont.cuba.gui.data.Datasource)12 Group (com.haulmont.cuba.security.entity.Group)11 UUID (java.util.UUID)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 View (com.haulmont.cuba.core.global.View)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Assert (org.junit.Assert)7 Ignore (org.junit.Ignore)7 NonStrictExpectations (mockit.NonStrictExpectations)5 PersistenceManagerClient (com.haulmont.cuba.client.sys.PersistenceManagerClient)4 PersistenceManagerService (com.haulmont.cuba.core.app.PersistenceManagerService)4 AppBeans (com.haulmont.cuba.core.global.AppBeans)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 Mocked (mockit.Mocked)4 CollectionDatasourceImpl (com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl)3