Search in sources :

Example 1 with OptionsGroup

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

the class OptionsGroupDsTest method testUnsubscribeComponentListener.

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

Example 2 with OptionsGroup

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

the class OptionsGroupDsTest method testDatasourceRepeatableAssign.

@Test
public void testDatasourceRepeatableAssign() {
    OptionsGroup optionsGroup = (OptionsGroup) factory.createComponent(OptionsGroup.NAME);
    optionsGroup.setDatasource(null, null);
    optionsGroup.setDatasource(null, null);
    Datasource<Role> roleDs1 = getTestRoleDatasource();
    optionsGroup.setValue(RoleType.STANDARD);
    boolean exceptionWasThrown = false;
    try {
        optionsGroup.setDatasource(roleDs1, null);
    } catch (Exception e) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    exceptionWasThrown = false;
    try {
        optionsGroup.setDatasource(null, "group");
    } catch (Exception e) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    optionsGroup.setDatasource(roleDs1, "type");
    optionsGroup.setDatasource(roleDs1, "type");
    Datasource<Role> roleDs2 = getTestRoleDatasource();
    optionsGroup.setDatasource(roleDs2, "type");
    optionsGroup.setValue(RoleType.DENYING);
    Assert.assertEquals(RoleType.STANDARD, roleDs1.getItem().getType());
}
Also used : Role(com.haulmont.cuba.security.entity.Role) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Test(org.junit.Test)

Example 3 with OptionsGroup

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

the class OptionsGroupDsTest method testValueChangeListener.

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

Example 4 with OptionsGroup

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

the class OptionsGroupDsTest method testUnsubscribeSubscribeDsListener.

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

Example 5 with OptionsGroup

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

the class OptionsGroupDsTest method testUnsubscribeSubscribeComponentListener.

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

Aggregations

OptionsGroup (com.haulmont.cuba.gui.components.OptionsGroup)7 Role (com.haulmont.cuba.security.entity.Role)7 Test (org.junit.Test)7 Component (com.haulmont.cuba.gui.components.Component)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 RoleType (com.haulmont.cuba.security.entity.RoleType)5 Assert (org.junit.Assert)5 Ignore (org.junit.Ignore)5