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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations