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]);
}
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());
}
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());
}
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());
}
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());
}
Aggregations