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());
}
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());
}
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]);
}
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());
}
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());
}
Aggregations