Search in sources :

Example 86 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class OptionsListDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    OptionsList optionsList = (OptionsList) factory.createComponent(OptionsList.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    optionsList.setDatasource(roleDs, "type");
    optionsList.setValue(RoleType.DENYING);
    optionsList.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<Role> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    roleDs.addItemPropertyChangeListener(listener);
    optionsList.setValue(RoleType.STANDARD);
    assertEquals(RoleType.DENYING, roleDs.getItem().getType());
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Ignore(org.junit.Ignore) Role(com.haulmont.cuba.security.entity.Role) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.Test)

Example 87 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class OptionsListDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    OptionsList optionsList = (OptionsList) factory.createComponent(OptionsList.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    optionsList.setDatasource(roleDs, "type");
    optionsList.setValue(RoleType.DENYING);
    optionsList.setDatasource(null, null);
    Component.ValueChangeListener listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    optionsList.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.READONLY);
    assertEquals(RoleType.DENYING, optionsList.getValue());
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Ignore(org.junit.Ignore) Role(com.haulmont.cuba.security.entity.Role) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Component(com.haulmont.cuba.gui.components.Component) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.Test)

Example 88 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class OptionsListDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    OptionsList optionsList = (OptionsList) factory.createComponent(OptionsList.NAME);
    // listener before datasource
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    optionsList.addValueChangeListener(listener);
    Datasource<Role> roleDs = getTestRoleDatasource();
    roleDs.getItem().setType(RoleType.READONLY);
    optionsList.setDatasource(roleDs, "type");
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    optionsList.removeValueChangeListener(listener);
    optionsList.setDatasource(null, null);
    // datasource before listener
    optionsList.setDatasource(roleDs, "type");
    optionsList.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.DENYING);
    assertTrue(valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Ignore(org.junit.Ignore) Role(com.haulmont.cuba.security.entity.Role) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Role(com.haulmont.cuba.security.entity.Role) Component(com.haulmont.cuba.gui.components.Component) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.Test)

Example 89 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class OptionsListDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    OptionsList optionsList = (OptionsList) factory.createComponent(OptionsList.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    roleDs.getItem().setType(RoleType.DENYING);
    optionsList.setDatasource(roleDs, "type");
    optionsList.setDatasource(null, null);
    // datasource before listener
    optionsList.setDatasource(roleDs, "type");
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    optionsList.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.READONLY);
    Assert.assertEquals(true, valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    optionsList.removeValueChangeListener(listener);
    optionsList.setDatasource(null, null);
    optionsList.setValue(null);
    // listener before datasource
    optionsList.addValueChangeListener(listener);
    optionsList.setDatasource(roleDs, "type");
    Assert.assertEquals(true, valueWasChanged[0]);
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Ignore(org.junit.Ignore) Role(com.haulmont.cuba.security.entity.Role) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Component(com.haulmont.cuba.gui.components.Component) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.Test)

Example 90 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class OptionsListDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    OptionsList optionsList = (OptionsList) factory.createComponent(OptionsList.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    roleDs.getItem().setType(RoleType.DENYING);
    optionsList.setDatasource(roleDs, "type");
    optionsList.setDatasource(null, null);
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<Role> listener = e -> valueWasChanged[0] = true;
    roleDs.addItemPropertyChangeListener(listener);
    optionsList.setDatasource(roleDs, "type");
    optionsList.setValue(RoleType.STANDARD);
    assertTrue(valueWasChanged[0]);
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Ignore(org.junit.Ignore) Role(com.haulmont.cuba.security.entity.Role) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.Test)

Aggregations

Datasource (com.haulmont.cuba.gui.data.Datasource)111 Ignore (org.junit.Ignore)66 Test (org.junit.Test)66 Component (com.haulmont.cuba.gui.components.Component)61 User (com.haulmont.cuba.security.entity.User)56 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)53 Assert.assertTrue (org.junit.Assert.assertTrue)49 Assert.assertEquals (org.junit.Assert.assertEquals)44 Group (com.haulmont.cuba.security.entity.Group)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 Assert (org.junit.Assert)22 List (java.util.List)20 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 Date (java.util.Date)11 Entity (com.haulmont.cuba.core.entity.Entity)10 Role (com.haulmont.cuba.security.entity.Role)10 MetaClass (com.haulmont.chile.core.model.MetaClass)9 LookupField (com.haulmont.cuba.gui.components.LookupField)9