Search in sources :

Example 56 with IDesktop

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

the class JsonDesktopTest method testHandleModelDownloadResource.

@Test
public void testHandleModelDownloadResource() throws Exception {
    IDesktop desktop = new DesktopWithNonDisplayableOutline();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    jsonDesktop.handleModelOpenUri(new BinaryResource("foo.txt", null), OpenUriAction.DOWNLOAD);
    jsonDesktop.handleModelOpenUri(new BinaryResource("TP6 ARL ; Zulassung (UVV) - Bearbeitung elektr. Fax-Eingang [-8874 , ABC-Prüfbericht] (1).pdf", null), OpenUriAction.DOWNLOAD);
    List<JsonEvent> events = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "openUri");
    JSONObject[] data = new JSONObject[2];
    data[0] = events.get(0).getData();
    data[1] = events.get(1).getData();
    // counter = 0 first for test run
    assertEquals("dynamic/" + m_uiSession.getUiSessionId() + "/2/0/foo.txt", data[0].getString("uri"));
    assertEquals("dynamic/" + m_uiSession.getUiSessionId() + "/2/1/TP6%2520ARL%2520%253B%2520Zulassung%2520%2528UVV%2529%2520-%2520Bearbeitung%2520elektr.%2520Fax-Eingang%2520%255B-8874%2520%252C%2520ABC-Pr%25C3%25BCfbericht%255D%2520%25281%2529.pdf", // counter = 1 second for test run
    data[1].getString("uri"));
    assertEquals("download", data[0].getString("action"));
    assertEquals("download", data[1].getString("action"));
    // cleanup
    Jobs.getJobManager().cancel(Jobs.newFutureFilterBuilder().andMatchExecutionHint(DownloadHandlerStorage.RESOURCE_CLEANUP_JOB_MARKER).toFilter(), true);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) JSONObject(org.json.JSONObject) DesktopWithNonDisplayableOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableOutline) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 57 with IDesktop

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

the class JsonDesktopTest method testDontSendNonDisplayableViewButtons.

/**
 * Tests whether non displayable view buttons 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 testDontSendNonDisplayableViewButtons() throws Exception {
    IDesktop desktop = new DesktopWithNonDisplayableActions();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    JsonOutlineViewButton<IOutlineViewButton> jsonDisplayableAction = jsonDesktop.getAdapter(desktop.getViewButton(DesktopWithNonDisplayableActions.DisplayableOutlineViewButton.class));
    JsonOutlineViewButton<IOutlineViewButton> jsonNonDisplayableAction = jsonDesktop.getAdapter(desktop.getViewButton(DesktopWithNonDisplayableActions.NonDisplayableOutlineViewButton.class));
    // Adapter for NonDisplayableMenu must not exist
    assertNull(jsonNonDisplayableAction);
    // Json response must not contain NonDisplayableAction
    JSONObject json = jsonDesktop.toJson();
    JSONArray jsonActions = json.getJSONArray("viewButtons");
    assertEquals(1, jsonActions.length());
    assertEquals(jsonDisplayableAction.getId(), jsonActions.get(0));
}
Also used : JSONObject(org.json.JSONObject) DesktopWithNonDisplayableActions(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableActions) JSONArray(org.json.JSONArray) IOutlineViewButton(org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 58 with IDesktop

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

the class JsonDesktopTest method testDontSendNonDisplayableOutline.

/**
 * Tests whether non displayable outline is 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 testDontSendNonDisplayableOutline() throws Exception {
    IDesktop desktop = new DesktopWithNonDisplayableOutline();
    desktop.initDesktop();
    desktop.setOutline(NonDisplayableOutlineWithOneNode.class);
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    JsonOutline<IOutline> jsonNonDisplayableOutline = jsonDesktop.getAdapter(desktop.findOutline(NonDisplayableOutlineWithOneNode.class));
    // Adapter for NonDisplayableMenu must not exist
    assertNull(jsonNonDisplayableOutline);
    // Json response must not contain outline
    JSONObject json = jsonDesktop.toJson();
    String outlineId = json.optString("outline", null);
    assertNull(outlineId);
}
Also used : NonDisplayableOutlineWithOneNode(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.NonDisplayableOutlineWithOneNode) JSONObject(org.json.JSONObject) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) DesktopWithNonDisplayableOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableOutline) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 59 with IDesktop

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

the class JsonOutlineViewButtonTest method testNonLazyLoadingOutlineWhenSelected.

@Test
public void testNonLazyLoadingOutlineWhenSelected() 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());
    button.setSelected(true);
    JsonOutlineViewButton<IOutlineViewButton> jsonViewButton = UiSessionTestUtility.newJsonAdapter(m_uiSession, button, null);
    IJsonAdapter<?> outlineAdapter = jsonViewButton.getAdapter(outline);
    assertNotNull(outlineAdapter);
    // Expects outlineId is sent along with the button and not with a separate property change event
    String outlineId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonViewButton.getId(), "outline");
    assertNull(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)

Example 60 with IDesktop

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

the class JsonOutlineViewButtonTest method testLazyLoadingOutline_onUiSelectionChanged.

@Test
public void testLazyLoadingOutline_onUiSelectionChanged() throws Exception {
    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));
    JsonEvent event = createJsonActionEvent(jsonViewButton.getId());
    assertEquals("action", event.getType());
    jsonViewButton.handleUiEvent(event);
    // Outline needs to be created and sent if selection changes to 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) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) 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