Search in sources :

Example 21 with User

use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.

the class LookupPickerFieldDsTest method testOptionsDsUnsubscribe.

@Test
public void testOptionsDsUnsubscribe() {
    LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    component.setOptionsDatasource(groupsDs);
    List<Group> groups = new ArrayList<>(groupsDs.getItems());
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setGroup(groups.get(0));
    component.setDatasource(userDs, "group");
    // unbind
    component.setOptionsDatasource(null);
    Datasource.ItemChangeListener<Group> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    groupsDs.addItemChangeListener(listener);
    component.setValue(groups.get(1));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 22 with User

use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.

the class LookupPickerFieldDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    component.setOptionsDatasource(groupsDs);
    List<Group> groups = new ArrayList<>(groupsDs.getItems());
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setGroup(groups.get(0));
    component.setDatasource(userDs, "group");
    // unbind
    component.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    // datasource before listener
    component.setDatasource(userDs, "group");
    Subscription subscription = component.addValueChangeListener(listener);
    user.setGroup(metadata.create(Group.class));
    assertTrue(valueWasChanged[0]);
    // reset state
    component.setDatasource(null, null);
    subscription.remove();
    valueWasChanged[0] = false;
    component.setValue(null);
    // listener before datasource
    component.addValueChangeListener(listener);
    component.setDatasource(userDs, "group");
    assertTrue(valueWasChanged[0]);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 23 with User

use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.

the class LookupPickerFieldDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    component.setOptionsDatasource(groupsDs);
    List<Group> groups = new ArrayList<>(groupsDs.getItems());
    Datasource<User> userDs = createTestDatasource(User.class);
    userDs.getItem().setGroup(groups.get(0));
    component.setDatasource(userDs, "group");
    // unbind
    component.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<User> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(listener);
    component.setValue(metadata.create(Group.class));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 24 with User

use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.

the class LookupPickerFieldDsTest method testSetValueWithoutOptions.

@Test
public void testSetValueWithoutOptions() {
    LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    Group group = metadata.create(Group.class);
    group.setName("group #0");
    user.setGroup(group);
    component.setDatasource(userDs, "group");
    assertNotNull(component.getValue());
}
Also used : LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) Test(org.junit.jupiter.api.Test)

Example 25 with User

use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.

the class LookupPickerFieldDsTest method testUnsubscribeSubscribeOptions.

@Test
public void testUnsubscribeSubscribeOptions() {
    LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    component.setOptionsDatasource(groupsDs);
    List<Group> groups = new ArrayList<>(groupsDs.getItems());
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setGroup(groups.get(0));
    component.setDatasource(userDs, "group");
    // unbind
    component.setOptionsDatasource(null);
    Datasource.ItemChangeListener<Group> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    groupsDs.addItemChangeListener(listener);
    component.setValue(groups.get(1));
    // bind
    component.setOptionsDatasource(groupsDs);
    groupsDs.removeItemChangeListener(listener);
    boolean[] valueWasChanged = { false };
    listener = e -> valueWasChanged[0] = true;
    groupsDs.addItemChangeListener(listener);
    component.setValue(groups.get(2));
    assertTrue(valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

User (com.haulmont.cuba.core.model.common.User)154 Test (org.junit.jupiter.api.Test)133 Group (com.haulmont.cuba.core.model.common.Group)63 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)57 Datasource (com.haulmont.cuba.gui.data.Datasource)54 Subscription (io.jmix.core.common.event.Subscription)54 Consumer (java.util.function.Consumer)54 Disabled (org.junit.jupiter.api.Disabled)54 HasValue (io.jmix.ui.component.HasValue)49 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)44 UUID (java.util.UUID)29 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)23 ArrayList (java.util.ArrayList)21 List (java.util.List)19 Date (java.util.Date)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 View (com.haulmont.cuba.core.global.View)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13