Search in sources :

Example 6 with DsBuilder

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

the class OptionsGroupTest method testOptionsDatasource.

@Test
public void testOptionsDatasource() {
    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());
    Group g = new Group();
    g.setName("Group 0");
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    Group g1 = new Group();
    g1.setName("Group 1");
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    g2.setName("Group 2");
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setValue(g2);
    assertEquals(g2, component.getValue());
    component.setDatasource(testDs, "group");
    component.setValue(g);
    assertEquals(g, testDs.getItem().getGroup());
    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) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 7 with DsBuilder

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

the class OptionsListTest method testOptionsDatasource.

@Test
public void testOptionsDatasource() {
    OptionsList component = factory.createComponent(OptionsList.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();
    g.setName("Group 0");
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    Group g1 = new Group();
    g1.setName("Group 1");
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    g2.setName("Group 2");
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setValue(g2);
    assertEquals(g2, component.getValue());
    component.setDatasource(testDs, "group");
    component.setValue(g);
    assertEquals(g, testDs.getItem().getGroup());
    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) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 8 with DsBuilder

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

the class OptionsListTest method testDatasource.

@Test
public void testDatasource() {
    OptionsList component = factory.createComponent(OptionsList.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 9 with DsBuilder

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

the class PickerFieldTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    PickerField component = factory.createComponent(PickerField.class);
    final AtomicInteger counter = new AtomicInteger(0);
    // 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());
    final Group g = new Group();
    testDs.getItem().setGroup(g);
    final Group g1 = new Group();
    final Group g2 = new Group();
    Component.ValueChangeListener listener1 = e -> {
        assertNull(e.getPrevValue());
        assertEquals(g2, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener1);
    component.setMetaClass(metadata.getClass(Group.class));
    component.setValue(g2);
    component.removeValueChangeListener(listener1);
    assertEquals(1, counter.get());
    Component.ValueChangeListener listener2 = e -> {
        assertEquals(g2, e.getPrevValue());
        assertEquals(g, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener2);
    component.setDatasource(testDs, "group");
    assertEquals(g, component.getValue());
    assertEquals(2, counter.get());
    component.removeValueChangeListener(listener2);
    component.setValue(g1);
    assertEquals(g1, testDs.getItem().getGroup());
    assertEquals(2, counter.get());
    Component.ValueChangeListener listener3 = e -> {
        assertEquals(g1, e.getPrevValue());
        assertEquals(g2, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener3);
    testDs.getItem().setGroup(g2);
    assertEquals(g2, component.getValue());
    assertEquals(3, counter.get());
    component.removeValueChangeListener(listener3);
    component.setValue(g);
    Group gCopy = (Group) SerializationSupport.deserialize(SerializationSupport.serialize(g));
    Component.ValueChangeListener listener4 = e -> {
        assertEquals(g, e.getPrevValue());
        assertEquals(gCopy, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener4);
    component.setValue(gCopy);
    assertEquals(4, counter.get());
    component.removeValueChangeListener(listener4);
    Component.ValueChangeListener listener5 = e -> {
        assertEquals(g, e.getPrevValue());
        assertEquals(gCopy, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener5);
    testDs.getItem().setGroup(g);
    assertEquals(5, counter.get());
    component.removeValueChangeListener(listener5);
}
Also used : Group(com.haulmont.cuba.security.entity.Group) View(com.haulmont.cuba.core.global.View) Datasource(com.haulmont.cuba.gui.data.Datasource) NonStrictExpectations(mockit.NonStrictExpectations) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) SerializationSupport(com.haulmont.cuba.core.sys.serialization.SerializationSupport) Test(org.junit.Test) Assert(org.junit.Assert) User(com.haulmont.cuba.security.entity.User) Group(com.haulmont.cuba.security.entity.Group) 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.Test)

Example 10 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 = factory.createComponent(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.Test)

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