Search in sources :

Example 1 with User

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

the class CheckBoxDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    CheckBox checkBox = uiComponents.create(CheckBox.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setActive(true);
    // listener before datasource
    Boolean[] valueWasChanged = { false };
    Consumer listener = e -> valueWasChanged[0] = true;
    Subscription valueChangeListenerSub = checkBox.addValueChangeListener(listener);
    checkBox.setDatasource(userDs, "active");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    checkBox.setDatasource(null, null);
    valueChangeListenerSub.remove();
    valueWasChanged[0] = false;
    // datasource before listener
    checkBox.setDatasource(userDs, "active");
    checkBox.addValueChangeListener(listener);
    user.setActive(false);
    assertEquals(true, valueWasChanged[0]);
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) Consumer(java.util.function.Consumer) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 2 with User

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

the class CheckBoxDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    CheckBox checkBox = uiComponents.create(CheckBox.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setActive(true);
    checkBox.setDatasource(userDs, "active");
    // unbind
    checkBox.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    checkBox.setValue(false);
    assertEquals(true, user.getActive());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Test(org.junit.jupiter.api.Test)

Example 3 with User

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

the class CheckBoxDsTest method testDatasourceRepeatableAssign.

@Test
public void testDatasourceRepeatableAssign() {
    CheckBox checkBox = uiComponents.create(CheckBox.NAME);
    checkBox.setDatasource(null, null);
    checkBox.setDatasource(null, null);
    Datasource<User> userDs1 = createTestDatasource(User.class);
    checkBox.setDatasource(userDs1, "active");
    checkBox.setDatasource(userDs1, "active");
    boolean exceptionWasThrown = false;
    /*try { todo web tests
            checkBox.setDatasource(userDs1, null);
        } catch (Exception e) {
            exceptionWasThrown = true;
        }
        assertTrue(exceptionWasThrown);

        exceptionWasThrown = false;*/
    try {
        checkBox.setDatasource(null, "active");
    } catch (Exception e) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    userDs1.getItem().setActive(true);
    checkBox.setDatasource(userDs1, "active");
    Datasource<User> userDs2 = createTestDatasource(User.class);
    checkBox.setDatasource(userDs2, "active");
    checkBox.setValue(false);
    assertEquals(true, userDs1.getItem().getActive());
}
Also used : User(com.haulmont.cuba.core.model.common.User) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Test(org.junit.jupiter.api.Test)

Example 4 with User

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

the class DateFieldDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    DateField dateField = uiComponents.create(DateField.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    dateField.setDatasource(userDs, "updateTs");
    // unbind
    dateField.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    dateField.setValue(new Date());
    assertEquals(updateTs, user.getUpdateTs());
}
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) DateField(com.haulmont.cuba.gui.components.DateField) 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) DateField(com.haulmont.cuba.gui.components.DateField) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with User

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

the class DateFieldDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    DateField dateField = uiComponents.create(DateField.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    dateField.setDatasource(userDs, "updateTs");
    // unbind
    dateField.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
    userDs.addItemPropertyChangeListener(listener);
    dateField.setDatasource(userDs, "updateTs");
    dateField.setResolution(DateField.Resolution.SEC);
    Date updateTs2 = new Date();
    dateField.setValue(updateTs2);
    assertTrue(valueWasChanged[0]);
    assertEquals(updateTs2, user.getUpdateTs());
}
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) DateField(com.haulmont.cuba.gui.components.DateField) 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) DateField(com.haulmont.cuba.gui.components.DateField) Date(java.util.Date) 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