Search in sources :

Example 6 with CheckBox

use of com.haulmont.cuba.gui.components.CheckBox in project cuba by cuba-platform.

the class CheckBoxDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    CheckBox checkBox = (CheckBox) factory.createComponent(CheckBox.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setActive(true);
    checkBox.setDatasource(userDs, "active");
    // unbind
    checkBox.setDatasource(null, null);
    Component.ValueChangeListener valueChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    checkBox.addValueChangeListener(valueChangeListener);
    user.setActive(false);
    assertEquals(true, checkBox.getValue());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Aggregations

CheckBox (com.haulmont.cuba.gui.components.CheckBox)6 User (com.haulmont.cuba.security.entity.User)6 Test (org.junit.Test)6 Component (com.haulmont.cuba.gui.components.Component)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Ignore (org.junit.Ignore)5