コード例 #1
0
 private void addShellConstruct(final Shell shell, final ProtocolMessageWriter writer) {
   String[] styles = new String[] {"SHELL_TRIM"};
   writer.addConstructPayload(
       WidgetUtil.getId(shell),
       DisplayUtil.getId(shell.getDisplay()),
       shell.getClass().getName(),
       styles,
       null);
 }
コード例 #2
0
 private void checkShellConstruct(final Shell shell, final JSONObject message)
     throws JSONException {
   JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
   JSONObject widgetObject = widgetArray.getJSONObject(0);
   String actualShellId = widgetObject.getString(IProtocolConstants.WIDGETS_ID);
   assertEquals(WidgetUtil.getId(shell), actualShellId);
   String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE);
   assertEquals(IProtocolConstants.PAYLOAD_CONSTRUCT, type);
   JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
   String actualDisplayId = payload.getString(IProtocolConstants.KEY_PARENT_ID);
   assertEquals(DisplayUtil.getId(shell.getDisplay()), actualDisplayId);
   JSONArray styles = payload.getJSONArray(IProtocolConstants.KEY_WIDGET_STYLE);
   assertEquals("SHELL_TRIM", styles.getString(0));
   Object params = payload.get(IProtocolConstants.KEY_PARAMETER_LIST);
   assertSame(JSONObject.NULL, params);
 }
コード例 #3
0
  public void testMessageWithWrongArguments() throws IOException {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    ProtocolMessageWriter writer = new JsonMessageWriter(printWriter);
    Display display = new Display();
    Shell shell = new Shell(display);
    Button button = new Button(shell, SWT.PUSH);
    boolean isExceptionThrown = false;
    try {
      writer.addConstructPayload(
          DisplayUtil.getId(display),
          WidgetUtil.getId(shell),
          "org.Text",
          new String[] {"TRIM"},
          new Object[] {"a", button});

    } catch (final IllegalArgumentException e) {
      isExceptionThrown = true;
    }
    assertTrue(isExceptionThrown);
  }
コード例 #4
0
 public void testMessageWithConstruct() throws IOException, JSONException {
   StringWriter stringWriter = new StringWriter();
   PrintWriter printWriter = new PrintWriter(stringWriter);
   ProtocolMessageWriter writer = new JsonMessageWriter(printWriter);
   Display display = new Display();
   Shell shell = new Shell(display);
   Button button = new Button(shell, SWT.PUSH);
   writer.addConstructPayload(
       WidgetUtil.getId(shell),
       DisplayUtil.getId(display),
       "org.Text",
       new String[] {"TRIM"},
       new Object[] {"a", "b"});
   String parentId = "";
   if (shell.getParent() != null) {
     parentId = WidgetUtil.getId(shell.getParent());
   } else {
     parentId = DisplayUtil.getId(display);
   }
   String widgetId = WidgetUtil.getId(shell);
   String actual = stringWriter.getBuffer().toString();
   JSONObject message = new JSONObject(actual + "]}");
   JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
   JSONObject widgetObject = widgetArray.getJSONObject(0);
   String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE);
   assertEquals(IProtocolConstants.PAYLOAD_CONSTRUCT, type);
   String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID);
   assertEquals(widgetId, actualId);
   JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
   String actualParentId = payload.getString(IProtocolConstants.KEY_PARENT_ID);
   assertEquals(parentId, actualParentId);
   String actualType = payload.getString(IProtocolConstants.KEY_WIDGET_TYPE);
   assertEquals("org.Text", actualType);
   JSONArray actualStyle = payload.getJSONArray(IProtocolConstants.KEY_WIDGET_STYLE);
   assertEquals("TRIM", actualStyle.getString(0));
   JSONArray actualParams = payload.getJSONArray(IProtocolConstants.KEY_PARAMETER_LIST);
   assertEquals("a", actualParams.getString(0));
   assertEquals("b", actualParams.getString(1));
   writer.addConstructPayload(
       WidgetUtil.getId(button),
       WidgetUtil.getId(shell),
       "org.Shell",
       new String[] {"PUSH", "BORDER"},
       new Object[] {"a", new Boolean(true)});
   writer.finish();
   actual = stringWriter.getBuffer().toString();
   message = new JSONObject(actual);
   widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
   widgetObject = widgetArray.getJSONObject(1);
   type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE);
   assertEquals(IProtocolConstants.PAYLOAD_CONSTRUCT, type);
   actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID);
   assertEquals(WidgetUtil.getId(button), actualId);
   payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
   JSONArray styles = payload.getJSONArray(IProtocolConstants.KEY_WIDGET_STYLE);
   assertEquals("PUSH", styles.getString(0));
   assertEquals("BORDER", styles.getString(1));
   String actualParent = payload.getString(IProtocolConstants.KEY_PARENT_ID);
   assertEquals(WidgetUtil.getId(shell), actualParent);
   JSONArray params = payload.getJSONArray(IProtocolConstants.KEY_PARAMETER_LIST);
   assertTrue(params.getBoolean(1));
 }