Search in sources :

Example 1 with DesktopWithNonDisplayableActions

use of org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableActions 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 2 with DesktopWithNonDisplayableActions

use of org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableActions 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)

Aggregations

IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)2 JsonAdapterRegistryTest (org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)2 DesktopWithNonDisplayableActions (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableActions)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 IOutlineViewButton (org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton)1 IFormMenu (org.eclipse.scout.rt.client.ui.form.IFormMenu)1