Search in sources :

Example 6 with TextField

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

the class TextFieldDsTest method testDatasourceRepeatableAssign.

@Test
public void testDatasourceRepeatableAssign() {
    TextField textField = (TextField) factory.createComponent(TextField.NAME);
    textField.setDatasource(null, null);
    textField.setDatasource(null, null);
    Datasource<User> userDs1 = getTestUserDatasource();
    boolean exceptionWasThrown = false;
    try {
        textField.setDatasource(userDs1, null);
    } catch (Exception e) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    exceptionWasThrown = false;
    try {
        textField.setDatasource(null, "name");
    } catch (Exception e) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    textField.setDatasource(userDs1, "name");
    textField.setDatasource(userDs1, "name");
    userDs1.getItem().setName("Test name");
    textField.setDatasource(userDs1, "name");
    Datasource<User> userDs2 = getTestUserDatasource();
    textField.setDatasource(userDs2, "name");
    textField.setValue(false);
    assertEquals("Test name", userDs1.getItem().getName());
}
Also used : User(com.haulmont.cuba.security.entity.User) TextField(com.haulmont.cuba.gui.components.TextField) Test(org.junit.Test)

Aggregations

TextField (com.haulmont.cuba.gui.components.TextField)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