Search in sources :

Example 1 with OptionsList

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

the class OptionsListDsTest method testDatasourceRepeatableAssign.

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

Example 2 with OptionsList

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

the class OptionsListDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    OptionsList optionsList = uiComponents.create(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 };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    optionsList.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.READONLY);
    Assertions.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");
    Assertions.assertEquals(true, valueWasChanged[0]);
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(com.haulmont.cuba.gui.components.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Role(com.haulmont.cuba.security.entity.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Disabled(org.junit.jupiter.api.Disabled) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.jupiter.api.Test)

Example 3 with OptionsList

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

the class OptionsListDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    OptionsList optionsList = uiComponents.create(OptionsList.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    optionsList.setDatasource(roleDs, "type");
    optionsList.setValue(RoleType.DENYING);
    optionsList.setDatasource(null, null);
    Consumer<HasValue.ValueChangeEvent> 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) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(com.haulmont.cuba.gui.components.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Role(com.haulmont.cuba.security.entity.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Disabled(org.junit.jupiter.api.Disabled) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.jupiter.api.Test)

Example 4 with OptionsList

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

the class OptionsListDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    OptionsList optionsList = uiComponents.create(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) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(com.haulmont.cuba.gui.components.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Role(com.haulmont.cuba.security.entity.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Disabled(org.junit.jupiter.api.Disabled) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.jupiter.api.Test)

Example 5 with OptionsList

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

the class OptionsListDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    OptionsList optionsList = uiComponents.create(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) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(com.haulmont.cuba.gui.components.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Role(com.haulmont.cuba.security.entity.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Disabled(org.junit.jupiter.api.Disabled) RoleType(com.haulmont.cuba.security.entity.RoleType) TestCase.assertEquals(junit.framework.TestCase.assertEquals) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Test(org.junit.jupiter.api.Test)

Aggregations

OptionsList (com.haulmont.cuba.gui.components.OptionsList)6 Role (com.haulmont.cuba.security.entity.Role)6 Test (org.junit.jupiter.api.Test)6 HasValue (com.haulmont.cuba.gui.components.HasValue)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 RoleType (com.haulmont.cuba.security.entity.RoleType)5 Consumer (java.util.function.Consumer)5 TestCase.assertEquals (junit.framework.TestCase.assertEquals)5 Assertions (org.junit.jupiter.api.Assertions)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 Disabled (org.junit.jupiter.api.Disabled)5