use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class OptionsGroupTest method testDatasource.
@Test
public void testDatasource() {
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());
component.setDatasource(testDs, "group");
assertNotNull(component.getDatasource());
}
use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class PickerFieldTest method testDatasource.
@Test
public void testDatasource() {
PickerField component = factory.createComponent(PickerField.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();
testDs.getItem().setGroup(g);
Group g1 = new Group();
Group g2 = new Group();
component.setMetaClass(metadata.getClass(Group.class));
component.setValue(g2);
component.setDatasource(testDs, "group");
assertEquals(g, component.getValue());
component.setValue(g1);
assertEquals(g1, testDs.getItem().getGroup());
testDs.getItem().setGroup(g2);
assertEquals(g2, component.getValue());
}
use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class DsApiConsistencyTestCase method getTestCollectionDatasource.
protected CollectionDatasource<Group, UUID> getTestCollectionDatasource() {
// noinspection unchecked
CollectionDatasource<Group, UUID> collectionDatasource = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
for (int i = 0; i < 3; i++) {
Group group = metadata.create(Group.class);
group.setName("Group #" + (i + 1));
Group parentGroup = metadata.create(Group.class);
parentGroup.setName("Parent group #" + (i + 1));
group.setParent(parentGroup);
collectionDatasource.addItem(group);
}
((CollectionDatasourceImpl) collectionDatasource).valid();
return collectionDatasource;
}
use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class DsApiConsistencyTestCase method getTestUserDatasource.
protected Datasource<User> getTestUserDatasource() {
// noinspection unchecked
Datasource<User> datasource = new DsBuilder().setId("userDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
User user = metadata.create(User.class);
datasource.setItem(user);
((DatasourceImpl) datasource).valid();
return datasource;
}
use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class DsContextTest method createMasterDsContext.
private void createMasterDsContext() {
masterDsContext = new DsContextImpl(dataService);
DsBuilder masterDsBuilder = new DsBuilder(masterDsContext);
masterDsBuilder.reset().setId("masterDs").setMetaClass(metadataSession.getClass(TestMasterEntity.class)).setViewName("withDetails");
masterDs = masterDsBuilder.buildDatasource();
masterDsBuilder.reset().setId("detailsDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setMaster(masterDs).setProperty("details");
detailsDs = masterDsBuilder.buildCollectionDatasource();
masterDsBuilder.reset().setId("masterPartsDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setMaster(detailsDs).setProperty("parts");
masterPartsDs = masterDsBuilder.buildCollectionDatasource();
for (Datasource ds : masterDsContext.getAll()) {
((DatasourceImplementation) ds).initialized();
}
}
Aggregations