コード例 #1
0
  public void testDataEventCheckBox() throws Exception {
    WebForm form = W4TFixture.getEmptyWebFormInstance();
    W4TFixture.fakeBrowser(new Default(true));
    final WebDataEvent[] dataEvent = new WebDataEvent[1];
    WebDataListener dataListener =
        new WebDataListener() {
          public void webValueChanged(final WebDataEvent evt) {
            dataEvent[0] = evt;
          }
        };
    WebCheckBox checkBox = new WebCheckBox();
    form.add(checkBox, WebBorderLayout.NORTH);

    assertEquals(UNCHECKED, checkBox.getValue());
    checkBox.addWebDataListener(dataListener);

    checkBox.setValue(CHECKED);
    assertNull(dataEvent[0]);

    checkBox.removeWebDataListener(dataListener);
    checkBox.setValue(UNCHECKED);
    dataEvent[0] = null;
    checkBox.addWebDataListener(dataListener);
    String id = checkBox.getUniqueID();
    W4TFixture.fakeRequestParam(id, CHECKED);
    W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, UNCHECKED);
    getLifeCycleAdapter(form).readData();
    IServiceStateInfo stateInfo = ContextProvider.getStateInfo();
    String key = EventQueueFilter.ATTRIBUTE_KEY;
    EventQueueFilter eqv = (EventQueueFilter) stateInfo.getAttribute(key);
    eqv.filter();
    EventQueue.getEventQueue().fireEvents();
    assertNotNull(dataEvent[0]);
    assertSame(checkBox, dataEvent[0].getSource());
    assertSame(UNCHECKED, dataEvent[0].getOldValue());
    assertSame(CHECKED, dataEvent[0].getNewValue());
    assertEquals(CHECKED, checkBox.getValue());

    dataEvent[0] = null;
    W4TFixture.fakeRequestParam(checkBox.getUniqueID(), null);
    W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, CHECKED);
    getLifeCycleAdapter(form).readData();
    eqv.filter();
    EventQueue.getEventQueue().fireEvents();
    assertNotNull(dataEvent[0]);
    assertSame(checkBox, dataEvent[0].getSource());
    assertSame(CHECKED, dataEvent[0].getOldValue());
    assertSame(UNCHECKED, dataEvent[0].getNewValue());
    assertEquals(UNCHECKED, checkBox.getValue());

    W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, UNCHECKED);
    dataEvent[0] = null;
    getLifeCycleAdapter(form).readData();
    eqv.filter();
    EventQueue.getEventQueue().fireEvents();
    assertNull(dataEvent[0]);
    assertEquals(UNCHECKED, checkBox.getValue());
  }
コード例 #2
0
  public void testDataEventTriggering() throws Exception {
    WebForm form = W4TFixture.getEmptyWebFormInstance();
    W4TFixture.fakeBrowser(new Default(true));
    final WebDataEvent[] dataEvent = new WebDataEvent[1];
    WebDataListener dataListener =
        new WebDataListener() {
          public void webValueChanged(final WebDataEvent evt) {
            dataEvent[0] = evt;
          }
        };
    WebText text = new WebText();
    form.add(text, WebBorderLayout.NORTH);

    text.setValue(OLD_VALUE);
    assertEquals(OLD_VALUE, text.getValue());
    text.addWebDataListener(dataListener);
    text.setValue(NEW_VALUE);
    assertNull(dataEvent[0]);

    text.removeWebDataListener(dataListener);
    text.setValue(OLD_VALUE);
    dataEvent[0] = null;
    text.addWebDataListener(dataListener);
    W4TFixture.fakeRequestParam(text.getUniqueID(), NEW_VALUE);
    getLifeCycleAdapter(form).readData();
    IServiceStateInfo stateInfo = ContextProvider.getStateInfo();
    String key = EventQueueFilter.ATTRIBUTE_KEY;
    EventQueueFilter eqv = (EventQueueFilter) stateInfo.getAttribute(key);
    eqv.filter();
    EventQueue.getEventQueue().fireEvents();

    assertNotNull(dataEvent[0]);
    assertSame(text, dataEvent[0].getSource());
    assertSame(OLD_VALUE, dataEvent[0].getOldValue());
    assertSame(NEW_VALUE, dataEvent[0].getNewValue());
    assertEquals(NEW_VALUE, text.getValue());
  }