Beispiel #1
0
  @Test
  public void testSelectionAfterRemoveAll() {
    combo = new Combo(shell, SWT.READ_ONLY);
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    combo.add("item 1");
    combo.select(0);
    Button button = new Button(shell, SWT.PUSH);
    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            combo.removeAll();
            combo.add("replacement for item 1");
            combo.select(0);
          }
        });

    // Simulate button click that executes widgetSelected
    Fixture.fakeNotifyOperation(getId(button), ClientMessageConst.EVENT_SELECTION, null);
    Fixture.executeLifeCycleFromServerThread();

    Message message = Fixture.getProtocolMessage();
    assertEquals(new Integer(0), message.findSetProperty(combo, PROP_SELECTION_INDEX));
  }
Beispiel #2
0
  @Test
  public void testRenderTextLimitUnchanged() throws IOException {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);

    combo.setTextLimit(10);
    Fixture.preserveWidgets();
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "textLimit"));
  }
Beispiel #3
0
  @Test
  public void testRenderListVisibleUnchanged() throws IOException {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);

    combo.setListVisible(true);
    Fixture.preserveWidgets();
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "listVisible"));
  }
Beispiel #4
0
  @Test
  public void testRenderItemsUnchanged() throws IOException {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);

    combo.setItems(new String[] {"a", "b", "c"});
    Fixture.preserveWidgets();
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "items"));
  }
Beispiel #5
0
  @Test
  public void testRenderItemHeightUnchanged() throws IOException {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);

    combo.setFont(new Font(display, "Arial", 16, SWT.NONE));
    Fixture.preserveWidgets();
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "itemHeight"));
  }
  public void testRenderAddSelectionListener() throws Exception {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);
    Fixture.preserveWidgets();

    scale.addSelectionListener(new SelectionAdapter() {});
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertEquals(Boolean.TRUE, message.findListenProperty(scale, "selection"));
  }
Beispiel #7
0
  @Test
  public void testRenderMaxmumUnchanged() throws IOException {
    Fixture.markInitialized(display);
    Fixture.markInitialized(progressBar);

    progressBar.setMaximum(10);
    Fixture.preserveWidgets();
    lca.renderChanges(progressBar);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(progressBar, "maximum"));
  }
  public void testRenderPageIncrementUnchanged() throws IOException {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);

    scale.setPageIncrement(20);
    Fixture.preserveWidgets();
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(scale, "pageIncrement"));
  }
Beispiel #9
0
  @Test
  public void testRenderStateUnchanged() throws IOException {
    Fixture.markInitialized(display);
    Fixture.markInitialized(progressBar);

    progressBar.setState(SWT.ERROR);
    Fixture.preserveWidgets();
    lca.renderChanges(progressBar);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(progressBar, "state"));
  }
Beispiel #10
0
  @Test
  public void testListenDefaultSelection() throws Exception {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    Fixture.preserveWidgets();

    combo.addListener(SWT.DefaultSelection, mock(Listener.class));
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findListenOperation(combo, "Selection"));
    assertEquals(Boolean.TRUE, message.findListenProperty(combo, "DefaultSelection"));
  }
Beispiel #11
0
  @Test
  public void testRenderTextLimitResetWithNegative() throws IOException {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);

    combo.setTextLimit(10);
    Fixture.preserveWidgets();
    combo.setTextLimit(-5);
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertEquals(JSONObject.NULL, message.findSetProperty(combo, "textLimit"));
  }
Beispiel #12
0
  @Test
  public void testRenderSelectionUnchanged() throws IOException {
    combo.setText("foo bar");
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);

    combo.setSelection(new Point(1, 3));
    Fixture.preserveWidgets();
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "selection"));
  }
Beispiel #13
0
  @Test
  public void testRenderSelectionListenerUnchanged() throws Exception {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    Fixture.preserveWidgets();

    combo.addSelectionListener(new SelectionAdapter() {});
    Fixture.preserveWidgets();
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findListenOperation(combo, "selection"));
  }
  public void testRenderSelectionListenerUnchanged() throws Exception {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);
    Fixture.preserveWidgets();

    scale.addSelectionListener(new SelectionAdapter() {});
    Fixture.preserveWidgets();
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findListenOperation(scale, "selection"));
  }
Beispiel #15
0
  @Test
  public void testRemoveListenSelection() throws Exception {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    Listener listener = mock(Listener.class);
    combo.addListener(SWT.Selection, listener);
    Fixture.preserveWidgets();

    combo.removeListener(SWT.Selection, listener);
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertEquals(Boolean.FALSE, message.findListenProperty(combo, "Selection"));
  }
Beispiel #16
0
  @Test
  public void testTextIsNotRenderdBack() {
    Fixture.markInitialized(display);
    Fixture.markInitialized(shell);
    Fixture.markInitialized(combo);

    Fixture.fakeSetParameter(getId(combo), "text", "some text");
    Fixture.executeLifeCycleFromServerThread();

    // ensure that no text is sent back to the client
    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "text"));
    assertEquals("some text", combo.getText());
  }
Beispiel #17
0
  @Test
  public void testRenderAddVerifyListener() throws Exception {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    Fixture.preserveWidgets();

    combo.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent event) {}
        });
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertEquals(Boolean.TRUE, message.findListenProperty(combo, "Modify"));
  }
  @Test
  public void testFireFocusEventBeforeMouseEvent() {
    final java.util.List<TypedEvent> eventLog = new ArrayList<TypedEvent>();
    Button button = new Button(shell, SWT.PUSH);
    getRemoteObject(button).setHandler(new ButtonOperationHandler(button));
    Fixture.markInitialized(button);
    button.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(MouseEvent event) {
            eventLog.add(event);
          }
        });
    button.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent event) {
            eventLog.add(event);
          }
        });
    Fixture.fakeNewRequest();
    fakeMouseDownRequest(button, 1, 2);
    Fixture.fakeSetProperty(getId(display), "focusControl", getId(button));
    Fixture.fakeNotifyOperation(getId(button), EVENT_FOCUS_IN, null);

    Fixture.executeLifeCycleFromServerThread();

    assertEquals(FocusEvent.class, eventLog.get(0).getClass());
    assertEquals(MouseEvent.class, eventLog.get(1).getClass());
  }
Beispiel #19
0
  @Test
  public void testRenderVerifyListenerUnchanged() throws Exception {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    Fixture.preserveWidgets();

    combo.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent event) {}
        });
    Fixture.preserveWidgets();
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findListenOperation(combo, "verify"));
  }
Beispiel #20
0
  @Test
  public void testRenderRemoveModifyListener() throws Exception {
    ModifyListener listener =
        new ModifyListener() {
          public void modifyText(ModifyEvent event) {}
        };
    combo.addModifyListener(listener);
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    Fixture.preserveWidgets();

    combo.removeModifyListener(listener);
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertEquals(Boolean.FALSE, message.findListenProperty(combo, "Modify"));
  }
Beispiel #21
0
  @Test
  public void testTextSelectionWithVerifyEvent_EmptyListener() {
    Fixture.markInitialized(display);
    Fixture.markInitialized(shell);
    Fixture.markInitialized(combo);
    VerifyListener listener = mock(VerifyListener.class);
    combo.addVerifyListener(listener);

    fakeTextAndSelectionParameters("verify me", 1, 0);
    Fixture.executeLifeCycleFromServerThread();

    verify(listener, times(1)).verifyText(any(VerifyEvent.class));
    assertEquals("verify me", combo.getText());
    assertEquals(new Point(1, 1), combo.getSelection());
    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "text"));
    assertNull(message.findSetOperation(combo, "selection"));
  }
Beispiel #22
0
  @Test
  public void testReadText_WithVerifyListener() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);
    Fixture.markInitialized(display);
    Fixture.markInitialized(shell);
    Fixture.markInitialized(combo);
    combo.setText("some text");
    VerifyListener listener = mock(VerifyListener.class);
    combo.addVerifyListener(listener);

    Fixture.fakeSetParameter(getId(combo), "text", "verify me");
    Fixture.executeLifeCycleFromServerThread();

    assertEquals("verify me", combo.getText());
    ArgumentCaptor<VerifyEvent> captor = ArgumentCaptor.forClass(VerifyEvent.class);
    verify(listener, times(1)).verifyText(captor.capture());
    VerifyEvent event = captor.getValue();
    assertEquals("verify me", event.text);
    assertEquals(0, event.start);
    assertEquals(9, event.end);
  }
Beispiel #23
0
 @Test
 public void testEditablePreserveValues() {
   Fixture.markInitialized(display);
   Fixture.preserveWidgets();
   WidgetAdapter adapter = WidgetUtil.getAdapter(combo);
   assertEquals(Boolean.TRUE, adapter.getPreserved(ComboLCA.PROP_EDITABLE));
   Fixture.clearPreserved();
   // textLimit
   combo.setTextLimit(10);
   Fixture.preserveWidgets();
   Integer textLimit = (Integer) adapter.getPreserved(ComboLCA.PROP_TEXT_LIMIT);
   assertEquals(new Integer(10), textLimit);
 }
  @Test
  public void testPhase() {
    final StringBuilder log = new StringBuilder();
    Button button = new Button(shell, SWT.PUSH);
    getRemoteObject(button).setHandler(new ButtonOperationHandler(button));
    Fixture.markInitialized(button);
    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent event) {
            log.append(EVENT_FIRED);
          }
        });
    Fixture.fakeNewRequest();
    Fixture.fakeNotifyOperation(getId(button), ClientMessageConst.EVENT_SELECTION, null);
    LifeCycle lifeCycle = getApplicationContext().getLifeCycleFactory().getLifeCycle();
    lifeCycle.addPhaseListener(
        new PhaseListener() {
          private static final long serialVersionUID = 1L;

          public void beforePhase(PhaseEvent event) {
            log.append("before" + event.getPhaseId() + "|");
          }

          public void afterPhase(PhaseEvent event) {
            log.append("after" + event.getPhaseId() + "|");
          }

          public PhaseId getPhaseId() {
            return PhaseId.ANY;
          }
        });

    Fixture.executeLifeCycleFromServerThread();

    String expected =
        BEFORE_PREPARE_UI_ROOT
            + AFTER_PREPARE_UI_ROOT
            + BEFORE_READ_DATA
            + AFTER_READ_DATA
            + BEFORE_PROCESS_ACTION
            + EVENT_FIRED
            + AFTER_PROCESS_ACTION
            + BEFORE_RENDER
            + AFTER_RENDER;
    assertEquals(expected, log.toString());
  }
 public void testScalePreserveValues() {
   Scale scale = new Scale(shell, SWT.HORIZONTAL);
   Fixture.markInitialized(display);
   // Test preserved minimum, maximum,
   // selection, increment and ageIncrement
   Fixture.preserveWidgets();
   IWidgetAdapter adapter = WidgetUtil.getAdapter(scale);
   Integer minimum = (Integer) adapter.getPreserved(ScaleLCA.PROP_MINIMUM);
   assertEquals(0, minimum.intValue());
   Integer maximum = (Integer) adapter.getPreserved(ScaleLCA.PROP_MAXIMUM);
   assertEquals(100, maximum.intValue());
   Integer selection = (Integer) adapter.getPreserved(ScaleLCA.PROP_SELECTION);
   assertEquals(0, selection.intValue());
   Integer increment = (Integer) adapter.getPreserved(ScaleLCA.PROP_INCREMENT);
   assertEquals(1, increment.intValue());
   Integer pageIncrement = (Integer) adapter.getPreserved(ScaleLCA.PROP_PAGE_INCREMENT);
   assertEquals(10, pageIncrement.intValue());
   Fixture.clearPreserved();
   // Test preserved control properties
   testPreserveControlProperties(scale);
 }
Beispiel #26
0
 @Test
 public void testPreserveValues() {
   Combo combo = new Combo(shell, SWT.READ_ONLY);
   Fixture.markInitialized(display);
   // Test preserving a combo with no items and (naturally) no selection
   Fixture.preserveWidgets();
   WidgetAdapter adapter = WidgetUtil.getAdapter(combo);
   String[] items = ((String[]) adapter.getPreserved(PROP_ITEMS));
   assertEquals(0, items.length);
   assertEquals(new Integer(-1), adapter.getPreserved(PROP_SELECTION_INDEX));
   assertNull(adapter.getPreserved(ComboLCA.PROP_TEXT_LIMIT));
   Object visibleItemCount = adapter.getPreserved(ComboLCA.PROP_VISIBLE_ITEM_COUNT);
   assertEquals(new Integer(combo.getVisibleItemCount()), visibleItemCount);
   assertEquals(Boolean.FALSE, adapter.getPreserved(ComboLCA.PROP_EDITABLE));
   assertEquals(new Point(0, 0), adapter.getPreserved(ComboLCA.PROP_SELECTION));
   // Test preserving combo with items were one is selected
   Fixture.clearPreserved();
   combo.add("item 1");
   combo.add("item 2");
   combo.select(1);
   combo.setListVisible(true);
   SelectionListener selectionListener = new SelectionAdapter() {};
   combo.addSelectionListener(selectionListener);
   combo.addModifyListener(
       new ModifyListener() {
         public void modifyText(ModifyEvent event) {}
       });
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   items = ((String[]) adapter.getPreserved(PROP_ITEMS));
   assertEquals(2, items.length);
   assertEquals("item 1", items[0]);
   assertEquals("item 2", items[1]);
   assertEquals(new Integer(1), adapter.getPreserved(PROP_SELECTION_INDEX));
   visibleItemCount = adapter.getPreserved(ComboLCA.PROP_VISIBLE_ITEM_COUNT);
   assertEquals(new Integer(combo.getVisibleItemCount()), visibleItemCount);
   assertEquals("item 2", adapter.getPreserved(Props.TEXT));
   assertEquals(Boolean.FALSE, adapter.getPreserved(ComboLCA.PROP_EDITABLE));
   Fixture.clearPreserved();
   // foreground background font
   Color background = new Color(display, 122, 33, 203);
   combo.setBackground(background);
   Color foreground = new Color(display, 211, 178, 211);
   combo.setForeground(foreground);
   Font font = new Font(display, "font", 12, SWT.BOLD);
   combo.setFont(font);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals(background, adapter.getPreserved(Props.BACKGROUND));
   assertEquals(foreground, adapter.getPreserved(Props.FOREGROUND));
   assertEquals(font, adapter.getPreserved(Props.FONT));
   Fixture.clearPreserved();
   // tooltiptext
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals(null, combo.getToolTipText());
   Fixture.clearPreserved();
   combo.setToolTipText("some text");
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals("some text", combo.getToolTipText());
   Fixture.clearPreserved();
 }