Search in sources :

Example 6 with DatePicker

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

the class DatePickerDsTest method testDatasourceRepeatableAssign.

@Test
public void testDatasourceRepeatableAssign() {
    DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
    datePicker.setDatasource(null, null);
    datePicker.setDatasource(null, null);
    Datasource<User> userDs1 = getTestUserDatasource();
    datePicker.setDatasource(userDs1, "updateTs");
    datePicker.setDatasource(userDs1, "updateTs");
    boolean exceptionWasThrown = false;
    try {
        datePicker.setDatasource(userDs1, null);
    } catch (Exception e) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    exceptionWasThrown = false;
    try {
        datePicker.setDatasource(null, "updateTs");
    } catch (Exception e) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    Date updateTs = new Date();
    userDs1.getItem().setUpdateTs(updateTs);
    datePicker.setDatasource(userDs1, "updateTs");
    Datasource<User> userDs2 = getTestUserDatasource();
    datePicker.setDatasource(userDs2, "updateTs");
    datePicker.setValue(new Date());
    assertEquals(updateTs, userDs1.getItem().getUpdateTs());
}
Also used : User(com.haulmont.cuba.security.entity.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DatePicker (com.haulmont.cuba.gui.components.DatePicker)6 User (com.haulmont.cuba.security.entity.User)6 Date (java.util.Date)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