Search in sources :

Example 1 with DsBuilder

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

the class DsContextApplyChangesTest method createMasterDsContext.

private void createMasterDsContext() {
    masterDsContext = new DsContextImpl(dataService);
    DsBuilder masterDsBuilder = new DsBuilder(masterDsContext);
    masterDsBuilder.reset().setId("masterDs").setMetaClass(metadataSession.getClass(TestMasterEntity.class)).setViewName("withDetail");
    masterDs = masterDsBuilder.buildDatasource();
    masterDsBuilder.reset().setId("detailDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setMaster(masterDs).setProperty("detail");
    detailDs = masterDsBuilder.buildDatasource();
    masterDsBuilder.reset().setId("embeddedDs").setMetaClass(metadataSession.getClass(TestEmbeddableEntity.class)).setMaster(detailDs).setProperty("embeddable");
    embeddableDs = masterDsBuilder.buildDatasource();
    for (Datasource ds : masterDsContext.getAll()) {
        ((DatasourceImplementation) ds).initialized();
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) TestEmbeddableEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Example 2 with DsBuilder

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

the class DsContextTest method createDetailDsContext.

private void createDetailDsContext() {
    detailDsContext = new DsContextImpl(dataService);
    DsBuilder detailDsBuilder = new DsBuilder(detailDsContext);
    detailDsBuilder.reset().setId("detailDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setViewName("_local");
    detailDs = detailDsBuilder.buildDatasource();
    detailDsBuilder.reset().setId("embeddedDs").setMetaClass(metadataSession.getClass(TestEmbeddableEntity.class)).setMaster(detailDs).setProperty("embeddable");
    embeddableDs = detailDsBuilder.buildDatasource();
    detailDsBuilder.reset().setId("partsDs").setMetaClass(metadataSession.getClass(TestPartEntity.class)).setMaster(detailDs).setProperty("parts");
    partsDs = detailDsBuilder.buildCollectionDatasource();
    for (Datasource ds : detailDsContext.getAll()) {
        ((DatasourceImplementation) ds).initialized();
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) TestEmbeddableEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity) TestPartEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestPartEntity) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Example 3 with DsBuilder

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

the class TextFieldTest method testDatasource.

@Test
public void testDatasource() {
    TextField component = uiComponents.create(TextField.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());
    testDs.getItem().setLogin("Ok");
    component.setValue("none");
    component.setDatasource(testDs, "login");
    assertEquals("Ok", component.getValue());
    component.setValue("user");
    assertEquals("user", testDs.getItem().getLogin());
    testDs.getItem().setLogin("login");
    assertEquals("login", component.getValue());
}
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.jupiter.api.Test)

Example 4 with DsBuilder

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

the class TextFieldTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    TextField component = uiComponents.create(TextField.class);
    AtomicInteger counter = new AtomicInteger(0);
    Consumer<HasValue.ValueChangeEvent> okListener = e -> {
        assertNull(e.getPrevValue());
        assertEquals("OK", e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(okListener);
    component.setValue("OK");
    assertEquals(1, counter.get());
    component.removeValueChangeListener(okListener);
    component.setValue("Test");
    assertEquals(1, counter.get());
    // 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();
    Consumer<HasValue.ValueChangeEvent> dsLoadListener = e -> {
        assertEquals("Test", e.getPrevValue());
        assertNull(e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(dsLoadListener);
    component.setDatasource(testDs, "login");
    assertEquals(2, counter.get());
    component.removeValueChangeListener(dsLoadListener);
    Consumer<HasValue.ValueChangeEvent> dsListener = e -> {
        assertNull(e.getPrevValue());
        assertEquals("dsValue", e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(dsListener);
    testDs.getItem().setLogin("dsValue");
    assertEquals(3, counter.get());
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) View(com.haulmont.cuba.core.global.View) Datasource(com.haulmont.cuba.gui.data.Datasource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Assertions(org.junit.jupiter.api.Assertions) Datatypes(com.haulmont.chile.core.datatypes.Datatypes) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with DsBuilder

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

the class DsApiConsistencyTestCase method getTestRoleDatasource.

protected Datasource<Role> getTestRoleDatasource() {
    // noinspection unchecked
    Datasource<Role> roleDs = (Datasource<Role>) new DsBuilder().setId("roleDs").setJavaClass(Role.class).setView(viewRepository.getView(Role.class, View.LOCAL)).buildDatasource();
    roleDs.refresh();
    Role role = metadata.create(Role.class);
    roleDs.setItem(role);
    ((DatasourceImpl) roleDs).valid();
    return roleDs;
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) 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.jupiter.api.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 Consumer (java.util.function.Consumer)7 Assertions (org.junit.jupiter.api.Assertions)7 Disabled (org.junit.jupiter.api.Disabled)7 Expectations (mockit.Expectations)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 Arrays (java.util.Arrays)4 Mocked (mockit.Mocked)4 CollectionDatasourceImpl (com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl)3