Search in sources :

Example 1 with Group

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

the class LookupFieldTest method testDatasource.

@Test
public void testDatasource() {
    LookupField component = factory.createComponent(LookupField.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    Group g = new Group();
    g.setName("Group 0");
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    Group g1 = new Group();
    g1.setName("Group 1");
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    g2.setName("Group 2");
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setValue(g2);
    assertEquals(g2, groupsDs.getItem());
    component.setDatasource(testDs, "group");
    assertEquals(g, component.getValue());
    assertEquals(g, groupsDs.getItem());
    // due to #PL-4625
    assertFalse(groupsDs.containsItem(g.getId()));
    component.setValue(g1);
    assertEquals(g1, testDs.getItem().getGroup());
    assertEquals(g1, groupsDs.getItem());
    testDs.getItem().setGroup(g2);
    assertEquals(g2, component.getValue());
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 2 with Group

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

the class LookupPickerFieldTest method testDatasource.

@Test
public void testDatasource() {
    LookupPickerField component = factory.createComponent(LookupPickerField.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    Group g = new Group();
    g.setName("Group 0");
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    Group g1 = new Group();
    g1.setName("Group 1");
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    g2.setName("Group 2");
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setValue(g2);
    assertEquals(g2, groupsDs.getItem());
    component.setDatasource(testDs, "group");
    assertEquals(g, component.getValue());
    assertEquals(g, groupsDs.getItem());
    // due to #PL-4625
    assertFalse(groupsDs.containsItem(g.getId()));
    component.setValue(g1);
    assertEquals(g1, testDs.getItem().getGroup());
    assertEquals(g1, groupsDs.getItem());
    testDs.getItem().setGroup(g2);
    assertEquals(g2, component.getValue());
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 3 with Group

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

the class LookupPickerFieldTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    LookupPickerField component = factory.createComponent(LookupPickerField.class);
    final AtomicInteger counter = new AtomicInteger(0);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    final Group g = new Group();
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    groupsDs.includeItem(g);
    Group g1 = new Group();
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    Component.ValueChangeListener listener1 = e -> {
        assertNull(e.getPrevValue());
        assertEquals(g2, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener1);
    component.setValue(g2);
    component.removeValueChangeListener(listener1);
    assertEquals(1, counter.get());
    Component.ValueChangeListener listener2 = e -> {
        assertEquals(g2, e.getPrevValue());
        assertEquals(g, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener2);
    component.setDatasource(testDs, "group");
    assertEquals(g, component.getValue());
    assertEquals(2, counter.get());
    component.removeValueChangeListener(listener2);
    component.setValue(g1);
    assertEquals(g1, testDs.getItem().getGroup());
    assertEquals(2, counter.get());
    Component.ValueChangeListener listener3 = e -> {
        assertEquals(g1, e.getPrevValue());
        assertEquals(g2, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener3);
    testDs.getItem().setGroup(g2);
    assertEquals(g2, component.getValue());
    assertEquals(3, counter.get());
}
Also used : PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) Arrays(java.util.Arrays) Datasource(com.haulmont.cuba.gui.data.Datasource) NonStrictExpectations(mockit.NonStrictExpectations) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test) PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) UUID(java.util.UUID) AppBeans(com.haulmont.cuba.core.global.AppBeans) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Group(com.haulmont.cuba.security.entity.Group) View(com.haulmont.cuba.core.global.View) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Assert(org.junit.Assert) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Mocked(mockit.Mocked) Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 4 with Group

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

the class OptionsGroupTest method testOptionsDatasource.

@Test
public void testOptionsDatasource() {
    OptionsGroup component = factory.createComponent(OptionsGroup.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    Group g = new Group();
    g.setName("Group 0");
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    Group g1 = new Group();
    g1.setName("Group 1");
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    g2.setName("Group 2");
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setValue(g2);
    assertEquals(g2, component.getValue());
    component.setDatasource(testDs, "group");
    component.setValue(g);
    assertEquals(g, testDs.getItem().getGroup());
    component.setValue(g1);
    assertEquals(g1, testDs.getItem().getGroup());
    testDs.getItem().setGroup(g2);
    assertEquals(g2, component.getValue());
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 5 with Group

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

the class OptionsListTest method testOptionsDatasource.

@Test
public void testOptionsDatasource() {
    OptionsList component = factory.createComponent(OptionsList.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    Group g = new Group();
    g.setName("Group 0");
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    Group g1 = new Group();
    g1.setName("Group 1");
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    g2.setName("Group 2");
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setValue(g2);
    assertEquals(g2, component.getValue());
    component.setDatasource(testDs, "group");
    component.setValue(g);
    assertEquals(g, testDs.getItem().getGroup());
    component.setValue(g1);
    assertEquals(g1, testDs.getItem().getGroup());
    testDs.getItem().setGroup(g2);
    assertEquals(g2, component.getValue());
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Aggregations

Group (com.haulmont.cuba.security.entity.Group)79 User (com.haulmont.cuba.security.entity.User)65 Test (org.junit.Test)60 UUID (java.util.UUID)30 Datasource (com.haulmont.cuba.gui.data.Datasource)29 Ignore (org.junit.Ignore)29 Component (com.haulmont.cuba.gui.components.Component)24 ArrayList (java.util.ArrayList)24 Assert.assertEquals (org.junit.Assert.assertEquals)24 Assert.assertTrue (org.junit.Assert.assertTrue)24 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)23 List (java.util.List)20 View (com.haulmont.cuba.core.global.View)15 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)11 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)10 Before (org.junit.Before)10 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)9 EntityManager (com.haulmont.cuba.core.EntityManager)8 Transaction (com.haulmont.cuba.core.Transaction)7