Search in sources :

Example 11 with User

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

the class DatePickerDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    DatePicker datePicker = uiComponents.create(DatePicker.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    datePicker.setDatasource(userDs, "updateTs");
    // unbind
    datePicker.setDatasource(null, null);
    Consumer<HasValue.ValueChangeEvent> valueChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    datePicker.addValueChangeListener(valueChangeListener);
    user.setUpdateTs(new Date());
    assertEquals(updateTs, datePicker.getValue());
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Date(java.util.Date) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 12 with User

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

the class LabelDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    Label label = uiComponents.create(Label.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    // listener after datasource
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = label.addValueChangeListener(listener);
    user.setName("anotherName");
    assertTrue(valueWasChanged[0]);
    // reset state
    subscription.remove();
    label.setDatasource(null, null);
    valueWasChanged[0] = false;
    label.setValue("testName");
    // datasource after listener
    label.addValueChangeListener(listener);
    label.setDatasource(userDs, "name");
    assertTrue(valueWasChanged[0]);
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Assertions(org.junit.jupiter.api.Assertions) Label(com.haulmont.cuba.gui.components.Label) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) Label(com.haulmont.cuba.gui.components.Label) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 13 with User

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

the class LabelDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    Label label = uiComponents.create(Label.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    // unbind
    label.setDatasource(null, null);
    assertNotNull(label.getValue());
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    label.setValue("anotherName");
    assertEquals("testName", user.getName());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Assertions(org.junit.jupiter.api.Assertions) Label(com.haulmont.cuba.gui.components.Label) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.jupiter.api.Test)

Example 14 with User

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

the class LabelDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    Label label = uiComponents.create(Label.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    // unbind
    label.setDatasource(null, null);
    assertNotNull(label.getValue());
    Consumer<HasValue.ValueChangeEvent> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    label.addValueChangeListener(listener);
    user.setName("anotherName");
    assertEquals("testName", label.getValue());
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Assertions(org.junit.jupiter.api.Assertions) Label(com.haulmont.cuba.gui.components.Label) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.jupiter.api.Test)

Example 15 with User

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

the class LookupFieldDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    LookupField lookupField = uiComponents.create(LookupField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    lookupField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = createTestDatasource(User.class);
    Group group = groupsDs.getItems().iterator().next();
    userDs.getItem().setGroup(group);
    lookupField.setDatasource(userDs, "group");
    // unbind
    lookupField.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
    userDs.addItemPropertyChangeListener(listener);
    lookupField.setDatasource(userDs, "group");
    lookupField.setValue(null);
    assertTrue(valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Datasource(com.haulmont.cuba.gui.data.Datasource) 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) LookupField(com.haulmont.cuba.gui.components.LookupField) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) LookupField(com.haulmont.cuba.gui.components.LookupField) 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