Search in sources :

Example 21 with Role

use of com.haulmont.cuba.security.entity.Role 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 22 with Role

use of com.haulmont.cuba.security.entity.Role 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)

Example 23 with Role

use of com.haulmont.cuba.security.entity.Role in project cuba by cuba-platform.

the class OptionsGroupDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    OptionsGroup optionsGroup = (OptionsGroup) factory.createComponent(OptionsGroup.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setValue(RoleType.STANDARD);
    optionsGroup.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<Role> listener = e -> {
        throw new RuntimeException("");
    };
    roleDs.addItemPropertyChangeListener(listener);
    optionsGroup.setValue(RoleType.DENYING);
    assertEquals(RoleType.STANDARD, roleDs.getItem().getType());
}
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 24 with Role

use of com.haulmont.cuba.security.entity.Role in project cuba by cuba-platform.

the class OptionsGroupDsTest method testSetValue.

@Test
public void testSetValue() {
    OptionsGroup optionsGroup = (OptionsGroup) factory.createComponent(OptionsGroup.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setValue(RoleType.DENYING);
    assertNotNull(optionsGroup.getValue());
}
Also used : Role(com.haulmont.cuba.security.entity.Role) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Test(org.junit.Test)

Example 25 with Role

use of com.haulmont.cuba.security.entity.Role 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)

Aggregations

Role (com.haulmont.cuba.security.entity.Role)29 Test (org.junit.Test)18 Datasource (com.haulmont.cuba.gui.data.Datasource)12 Component (com.haulmont.cuba.gui.components.Component)10 RoleType (com.haulmont.cuba.security.entity.RoleType)10 Assert (org.junit.Assert)10 Ignore (org.junit.Ignore)10 User (com.haulmont.cuba.security.entity.User)9 UserRole (com.haulmont.cuba.security.entity.UserRole)9 OptionsGroup (com.haulmont.cuba.gui.components.OptionsGroup)7 OptionsList (com.haulmont.cuba.gui.components.OptionsList)6 Group (com.haulmont.cuba.security.entity.Group)6 TestCase.assertEquals (junit.framework.TestCase.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 EntityManager (com.haulmont.cuba.core.EntityManager)4 Transaction (com.haulmont.cuba.core.Transaction)4 Permission (com.haulmont.cuba.security.entity.Permission)4 Before (org.junit.Before)4 UUID (java.util.UUID)3 View (com.haulmont.cuba.core.global.View)2