Search in sources :

Example 16 with User

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

the class LookupFieldDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    LookupField lookupField = uiComponents.create(LookupField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    lookupField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = createTestDatasource(User.class);
    Group group = groupsDs.getItems().iterator().next();
    User user = userDs.getItem();
    user.setGroup(group);
    lookupField.setDatasource(userDs, "group");
    // unbind
    lookupField.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    // datasource before listener
    lookupField.setDatasource(userDs, "group");
    Subscription subscription = lookupField.addValueChangeListener(listener);
    user.setGroup(metadata.create(Group.class));
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    lookupField.setDatasource(null, null);
    subscription.remove();
    lookupField.setValue(null);
    // listener before datasource
    lookupField.addValueChangeListener(listener);
    lookupField.setDatasource(userDs, "group");
    assertTrue(valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LookupField(com.haulmont.cuba.gui.components.LookupField) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 17 with User

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

the class LookupFieldDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    LookupField lookupField = uiComponents.create(LookupField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    lookupField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = createTestDatasource(User.class);
    Group group = groupsDs.getItems().iterator().next();
    userDs.getItem().setGroup(group);
    lookupField.setDatasource(userDs, "group");
    // unbind
    lookupField.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    lookupField.setValue(metadata.create(Group.class));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LookupField(com.haulmont.cuba.gui.components.LookupField) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 18 with User

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

the class LookupFieldDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    LookupField lookupField = uiComponents.create(LookupField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    lookupField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = createTestDatasource(User.class);
    Group group = groupsDs.getItems().iterator().next();
    User user = userDs.getItem();
    user.setGroup(group);
    lookupField.setDatasource(userDs, "group");
    // unbind
    lookupField.setDatasource(null, null);
    Consumer<HasValue.ValueChangeEvent> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    lookupField.addValueChangeListener(listener);
    user.setGroup(metadata.create(Group.class));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LookupField(com.haulmont.cuba.gui.components.LookupField) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 19 with User

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

the class LookupFieldDsTest method testDatasourceRepeatableAssign.

@Test
public void testDatasourceRepeatableAssign() {
    LookupField lookupField = uiComponents.create(LookupField.NAME);
    lookupField.setDatasource(null, null);
    lookupField.setDatasource(null, null);
    Datasource<User> userDs1 = createTestDatasource(User.class);
    boolean exceptionWasThrown = false;
    /*try { todo web tests
            lookupField.setDatasource(userDs1, null);
        } catch (Exception e) {
            exceptionWasThrown = true;
        }

        assertTrue(exceptionWasThrown);*/
    exceptionWasThrown = false;
    try {
        lookupField.setDatasource(null, "name");
    } catch (Exception e) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    lookupField.setDatasource(userDs1, "name");
    lookupField.setDatasource(userDs1, "name");
    userDs1.getItem().setName("Test name");
    lookupField.setDatasource(userDs1, "name");
    Datasource<User> userDs2 = createTestDatasource(User.class);
    lookupField.setDatasource(userDs2, "name");
    lookupField.setValue(null);
    assertEquals("Test name", userDs1.getItem().getName());
}
Also used : User(com.haulmont.cuba.core.model.common.User) LookupField(com.haulmont.cuba.gui.components.LookupField) Test(org.junit.jupiter.api.Test)

Example 20 with User

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

the class LookupPickerFieldDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    component.setOptionsDatasource(groupsDs);
    List<Group> groups = new ArrayList<>(groupsDs.getItems());
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setGroup(groups.get(0));
    // listener before datasource
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = component.addValueChangeListener(listener);
    component.setDatasource(userDs, "group");
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    subscription.remove();
    component.setDatasource(null, null);
    // datasource before listener
    component.setDatasource(userDs, "group");
    component.addValueChangeListener(listener);
    user.setGroup(null);
    assertTrue(valueWasChanged[0]);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Aggregations

User (com.haulmont.cuba.core.model.common.User)154 Test (org.junit.jupiter.api.Test)133 Group (com.haulmont.cuba.core.model.common.Group)63 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)57 Datasource (com.haulmont.cuba.gui.data.Datasource)54 Subscription (io.jmix.core.common.event.Subscription)54 Consumer (java.util.function.Consumer)54 Disabled (org.junit.jupiter.api.Disabled)54 HasValue (io.jmix.ui.component.HasValue)49 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)44 UUID (java.util.UUID)29 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)23 ArrayList (java.util.ArrayList)21 List (java.util.List)19 Date (java.util.Date)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 View (com.haulmont.cuba.core.global.View)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13