Search in sources :

Example 1 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class JsonDesktopTest method testFormClosedBeforeRemovedInSameRequest.

@Test
public void testFormClosedBeforeRemovedInSameRequest() throws JSONException {
    DesktopWithOneOutline desktop = new DesktopWithOneOutline();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    FormWithOneField form = new FormWithOneField();
    form.setDisplayParent(desktop);
    form.setShowOnStart(false);
    JsonForm jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
    assertNull(jsonForm);
    desktop.showForm(form);
    jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
    assertNotNull(jsonForm);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formShow");
    assertEquals(1, responseEvents.size());
    form.start();
    form.doClose();
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formClosed");
    assertEquals(0, responseEvents.size());
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "disposeAdapter");
    assertEquals(1, responseEvents.size());
    desktop.hideForm(form);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
    assertEquals(0, responseEvents.size());
}
Also used : JsonForm(org.eclipse.scout.rt.ui.html.json.form.JsonForm) DesktopWithOneOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 2 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class JsonDesktopTest method testFormClosedBeforeRemovedInDifferentRequests.

@Test
public void testFormClosedBeforeRemovedInDifferentRequests() throws Exception {
    DesktopWithOneOutline desktop = new DesktopWithOneOutline();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    FormWithOneField form = new FormWithOneField();
    form.setDisplayParent(desktop);
    form.setShowOnStart(false);
    JsonForm jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
    assertNull(jsonForm);
    desktop.showForm(form);
    jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
    assertNotNull(jsonForm);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formShow");
    assertEquals(1, responseEvents.size());
    form.start();
    JsonTestUtility.endRequest(m_uiSession);
    // -------------------------------
    // New request:
    form.doClose();
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formClosed");
    assertEquals(0, responseEvents.size());
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "disposeAdapter");
    assertEquals(1, responseEvents.size());
    desktop.hideForm(form);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
    // 0 instead of 1, because formClosed includes "formHide" implicitly. The event itself cannot be sent, because
    // the form adapter is already disposed when the form is closed.
    assertEquals(0, responseEvents.size());
}
Also used : JsonForm(org.eclipse.scout.rt.ui.html.json.form.JsonForm) DesktopWithOneOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 3 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class JsonDesktopTest method testFormAddedAndRemoved.

@Test
public void testFormAddedAndRemoved() throws Exception {
    DesktopWithOneOutline desktop = new DesktopWithOneOutline();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    FormWithOneField form = new FormWithOneField();
    form.setDisplayParent(desktop);
    form.setShowOnStart(false);
    JsonForm formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
    assertNull(formAdapter);
    desktop.showForm(form);
    formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
    assertNotNull(formAdapter);
    JsonResponse jsonResp = m_uiSession.currentJsonResponse();
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(jsonResp, "formShow");
    assertTrue(responseEvents.size() == 1);
    JsonEvent event = responseEvents.get(0);
    String formId = event.getData().getString("form");
    // Add event must contain reference (by ID) to form.
    assertEquals(jsonDesktop.getId(), event.getTarget());
    assertEquals(formAdapter.getId(), formId);
    // adapter-data for form must exist in 'adapterData' property of response
    JSONObject json = jsonResp.toJson();
    JSONObject adapterData = JsonTestUtility.getAdapterData(json, formId);
    assertEquals(formAdapter.getId(), adapterData.getString("id"));
    assertEquals("Form", adapterData.getString("objectType"));
    String rootGroupBoxId = adapterData.getString("rootGroupBox");
    adapterData = JsonTestUtility.getAdapterData(json, rootGroupBoxId);
    assertEquals("GroupBox", adapterData.getString("objectType"));
    // we could continue to test the reference structure in the JSON response,
    // but for the moment this should be enough...
    JsonTestUtility.endRequest(m_uiSession);
    desktop.hideForm(form);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
    assertTrue(responseEvents.size() == 1);
    event = responseEvents.get(0);
    formId = event.getData().getString("form");
    // Remove event must only contain the id, no other properties
    assertEquals(jsonDesktop.getId(), event.getTarget());
    assertEquals(formAdapter.getId(), formId);
}
Also used : JsonForm(org.eclipse.scout.rt.ui.html.json.form.JsonForm) DesktopWithOneOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline) JSONObject(org.json.JSONObject) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) JsonResponse(org.eclipse.scout.rt.ui.html.json.JsonResponse) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 4 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class JsonDesktopTest method testDontSendNonDisplayableMenus.

/**
 * Tests whether non displayable menus are sent.
 * <p>
 * This reduces response size and also leverages security because the menus are never visible to the user, not even
 * with the dev tools of the browser
 */
@Test
public void testDontSendNonDisplayableMenus() throws Exception {
    IDesktop desktop = new DesktopWithNonDisplayableActions();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    JsonMenu<IMenu> jsonDisplayableMenu = jsonDesktop.getAdapter(desktop.getMenu(DesktopWithNonDisplayableActions.DisplayableMenu.class));
    JsonMenu<IMenu> jsonNonDisplayableMenu = jsonDesktop.getAdapter(desktop.getMenu(DesktopWithNonDisplayableActions.NonDisplayableMenu.class));
    JsonFormMenu<IFormMenu<IForm>> jsonDisplayableFormMenu = jsonDesktop.getAdapter(desktop.getMenu(DesktopWithNonDisplayableActions.DisplayableFormMenu.class));
    JsonFormMenu<IFormMenu<IForm>> jsonNonDisplayableFormMenu = jsonDesktop.getAdapter(desktop.getMenu(DesktopWithNonDisplayableActions.NonDisplayableFormMenu.class));
    // Adapter for NonDisplayableMenu/Menu must not exist
    assertNull(jsonNonDisplayableMenu);
    assertNull(jsonNonDisplayableFormMenu);
    // Json response must not contain NonDisplayableMenu/FormMenu
    JSONObject json = jsonDesktop.toJson();
    JSONArray jsonActions = json.getJSONArray("menus");
    assertEquals(2, jsonActions.length());
    List<String> ids = new ArrayList<String>();
    ids.add(jsonActions.getString(0));
    ids.add(jsonActions.getString(1));
    assertTrue(ids.contains(jsonDisplayableMenu.getId()));
    assertTrue(ids.contains(jsonDisplayableFormMenu.getId()));
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) JSONObject(org.json.JSONObject) DesktopWithNonDisplayableActions(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableActions) IFormMenu(org.eclipse.scout.rt.client.ui.form.IFormMenu) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 5 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class JsonOutlineViewButtonTest method testLazyLoadingOutline_onModelSelectionChanged.

@Test
public void testLazyLoadingOutline_onModelSelectionChanged() throws JSONException {
    OutlineWithOneNode outline = new OutlineWithOneNode();
    IDesktop desktop = Mockito.mock(IDesktop.class);
    Mockito.when(desktop.getAvailableOutlines()).thenReturn(Collections.<IOutline>singletonList(outline));
    IOutlineViewButton button = new OutlineViewButton(desktop, outline.getClass());
    JsonOutlineViewButton<IOutlineViewButton> jsonViewButton = UiSessionTestUtility.newJsonAdapter(m_uiSession, button, null);
    assertNull(jsonViewButton.getAdapter(outline));
    button.setSelected(true);
    IJsonAdapter<?> outlineAdapter = jsonViewButton.getAdapter(outline);
    assertNotNull(outlineAdapter);
    String outlineId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonViewButton.getId(), "outline");
    assertEquals(outlineAdapter.getId(), outlineId);
}
Also used : OutlineWithOneNode(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineWithOneNode) IOutlineViewButton(org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton) OutlineViewButton(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineViewButton) IOutlineViewButton(org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Aggregations

IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)61 Test (org.junit.Test)36 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)18 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)7 JsonAdapterRegistryTest (org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)7 IOutlineViewButton (org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton)5 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)5 JsonForm (org.eclipse.scout.rt.ui.html.json.form.JsonForm)5 JSONObject (org.json.JSONObject)5 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)4 IClientSession (org.eclipse.scout.rt.client.IClientSession)3 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)3 IForm (org.eclipse.scout.rt.client.ui.form.IForm)3 DesktopWithOneOutline (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline)3 OutlineViewButton (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineViewButton)3 OutlineWithOneNode (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineWithOneNode)3 FormWithOneField (org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 Locale (java.util.Locale)2