Search in sources :

Example 1 with Role

use of com.haulmont.cuba.core.model.common.Role in project jmix by jmix-framework.

the class OptionsGroupDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    OptionsGroup optionsGroup = uiComponents.create(OptionsGroup.NAME);
    Datasource<Role> roleDs = createTestDatasource(Role.class);
    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.core.model.common.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Disabled(org.junit.jupiter.api.Disabled) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) RoleType(com.haulmont.cuba.core.model.common.RoleType) Role(com.haulmont.cuba.core.model.common.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Assert.assertEquals(org.junit.Assert.assertEquals) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Test(org.junit.jupiter.api.Test)

Example 2 with Role

use of com.haulmont.cuba.core.model.common.Role in project jmix by jmix-framework.

the class OptionsGroupDsTest method testDatasourceRepeatableAssign.

@Test
public void testDatasourceRepeatableAssign() {
    OptionsGroup optionsGroup = uiComponents.create(OptionsGroup.NAME);
    optionsGroup.setDatasource(null, null);
    optionsGroup.setDatasource(null, null);
    Datasource<Role> roleDs1 = createTestDatasource(Role.class);
    optionsGroup.setValue(RoleType.STANDARD);
    boolean 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 = createTestDatasource(Role.class);
    optionsGroup.setDatasource(roleDs2, "type");
    optionsGroup.setValue(RoleType.DENYING);
    Assertions.assertEquals(RoleType.STANDARD, roleDs1.getItem().getType());
}
Also used : Role(com.haulmont.cuba.core.model.common.Role) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Test(org.junit.jupiter.api.Test)

Example 3 with Role

use of com.haulmont.cuba.core.model.common.Role in project jmix by jmix-framework.

the class OptionsGroupDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    OptionsGroup optionsGroup = uiComponents.create(OptionsGroup.NAME);
    Datasource<Role> roleDs = createTestDatasource(Role.class);
    roleDs.getItem().setType(RoleType.DENYING);
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setDatasource(null, null);
    // datasource before listener
    optionsGroup.setDatasource(roleDs, "type");
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = optionsGroup.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.READONLY);
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    subscription.remove();
    optionsGroup.setDatasource(null, null);
    optionsGroup.setValue(null);
    // listener before datasource
    optionsGroup.addValueChangeListener(listener);
    optionsGroup.setDatasource(roleDs, "type");
    assertTrue(valueWasChanged[0]);
}
Also used : Role(com.haulmont.cuba.core.model.common.Role) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Disabled(org.junit.jupiter.api.Disabled) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) RoleType(com.haulmont.cuba.core.model.common.RoleType) Role(com.haulmont.cuba.core.model.common.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Assert.assertEquals(org.junit.Assert.assertEquals) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 4 with Role

use of com.haulmont.cuba.core.model.common.Role in project jmix by jmix-framework.

the class OptionsGroupDsTest method testSetValue.

@Test
public void testSetValue() {
    OptionsGroup optionsGroup = uiComponents.create(OptionsGroup.NAME);
    Datasource<Role> roleDs = createTestDatasource(Role.class);
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setValue(RoleType.DENYING);
    assertNotNull(optionsGroup.getValue());
}
Also used : Role(com.haulmont.cuba.core.model.common.Role) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Test(org.junit.jupiter.api.Test)

Example 5 with Role

use of com.haulmont.cuba.core.model.common.Role in project jmix by jmix-framework.

the class OptionsGroupDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    OptionsGroup optionsGroup = uiComponents.create(OptionsGroup.NAME);
    Datasource<Role> roleDs = createTestDatasource(Role.class);
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setValue(RoleType.STANDARD);
    optionsGroup.setDatasource(null, null);
    Consumer<HasValue.ValueChangeEvent> 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.core.model.common.Role) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Disabled(org.junit.jupiter.api.Disabled) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) RoleType(com.haulmont.cuba.core.model.common.RoleType) Role(com.haulmont.cuba.core.model.common.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Assert.assertEquals(org.junit.Assert.assertEquals) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Test(org.junit.jupiter.api.Test)

Aggregations

Role (com.haulmont.cuba.core.model.common.Role)21 Test (org.junit.jupiter.api.Test)16 RoleType (com.haulmont.cuba.core.model.common.RoleType)10 Datasource (com.haulmont.cuba.gui.data.Datasource)10 Subscription (io.jmix.core.common.event.Subscription)10 HasValue (io.jmix.ui.component.HasValue)10 Consumer (java.util.function.Consumer)10 Assert.assertEquals (org.junit.Assert.assertEquals)10 Assertions (org.junit.jupiter.api.Assertions)10 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)10 Disabled (org.junit.jupiter.api.Disabled)10 OptionsGroup (com.haulmont.cuba.gui.components.OptionsGroup)7 OptionsList (com.haulmont.cuba.gui.components.OptionsList)6 Group (com.haulmont.cuba.core.model.common.Group)5 User (com.haulmont.cuba.core.model.common.User)5 UiComponents (com.haulmont.cuba.gui.UiComponents)5 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 UserRole (com.haulmont.cuba.core.model.common.UserRole)4