示例#1
0
  public void testDataProvidedListChanged() throws Exception {
    DataProviderMetadata dataMeta =
        (DataProviderMetadata)
            form.getFormMetadata()
                .getDataProviderMetadatas()
                .get(new MethodEntry(form.getMethod("someDataProvider")));

    MockAbstractBinder binder =
        new MockAbstractBinder(root, form, handler) {
          protected void resetSelectedFields(DataProviderMetadata meta) throws Exception {
            put("resetSelectedFields(DataProviderMetadata)", meta);
          }
        };

    binder.bind();
    MockBoundDataProvider bound =
        (MockBoundDataProvider) binder.getBoundDataProvider(dataMeta.getWidgetName());

    final List list = Collections.singletonList("someValue");

    binder.dataProvidedListChanged(dataMeta, list);

    assertSame(list, bound.get("updateList(List)"));

    form.getController().setResetOnDataProviderChange(false);
    binder.clear();
    bound.clear();

    binder.dataProvidedListChanged(dataMeta, list);

    assertSame(list, bound.get("updateList(List)"));
    assertNull(binder.get("resetSelectedFields(DataProviderMetadata)"));
  }
示例#2
0
  public void testRefresh() throws Exception {
    final MockAbstractBinder binder = new MockAbstractBinder(root, form, handler);

    binder.bind();
    binder.refresh();

    assertNotNull(form.getController().get("update()"));
  }
示例#3
0
  public void testRefreshWithException() throws Exception {
    final MockAbstractBinder binder = new MockAbstractBinder(root, form, handler);
    final Exception ex = new IllegalArgumentException();
    form.getController().putException("update()", ex);

    binder.bind();
    binder.refresh();

    assertNull(form.getController().get("update()"));
    assertSame(ex, binder.get("handleException(Throwable)"));
  }
示例#4
0
  public void testValuesChanged() throws Exception {
    final MockAbstractBinder binder = new MockAbstractBinder(root, form, handler);

    binder.bind();

    final MockBoundField bound = (MockBoundField) binder.getBoundField("stringField");
    final Map map = new LinkedHashMap();
    map.put("unknownField", "unknownValue");
    map.put("stringField", "someValue");

    binder.valuesChanged(map);

    assertSame(bound.get("setValue(Object)"), "someValue");
  }
示例#5
0
  public void testBind() {
    MockAbstractBinder binder =
        new MockAbstractBinder(root, form, handler) {
          protected void setupController() throws Exception {
            put("setupController()", Boolean.TRUE);
          }
        };

    binder.bind();

    assertNotNull(binder.get("bindActionMetadata(String,FormMetadata,ActionMetadata)"));
    assertNotNull(binder.get("bindDataProvider(String,FormMetadata,DataProviderMetadata)"));
    assertNotNull(binder.get("bindFieldMetadata(String,FormMetadata,FieldMetadata)"));
    assertNotNull(binder.get("setupController()"));
  }
示例#6
0
  public void testUnbind() throws Exception {
    final MockAbstractBinder binder = new MockAbstractBinder(root, form, handler);

    binder.bind();

    assertNotNull(binder.getBoundField("stringField"));
    assertNotNull(binder.getBoundAction("someAction"));
    assertNotNull(binder.getBoundDataProvider("dataProviderField"));

    binder.unbind();

    assertNull(binder.getBoundField("stringField"));
    assertNull(binder.getBoundAction("someAction"));
    assertNull(binder.getBoundDataProvider("dataProviderField"));
  }
示例#7
0
  public void testInvokeAction() throws Exception {
    final MockAbstractBinder binder = new MockAbstractBinder(root, form, handler);

    binder.bind();
    binder.invokeAction("someAction");

    assertSame("someAction", form.getController().get("invokeAction(actionName)"));

    binder.clear();
    form.getController().clear();

    final Exception ex = new IllegalArgumentException();
    form.getController().putException("invokeAction(String,Map)", ex);
    binder.invokeAction("someAction");

    assertNull(form.getController().get("invokeAction(actionName)"));
    assertSame(ex, binder.get("handleException(Throwable)"));
  }
示例#8
0
  public void testEnabledConditionsChanged() throws Exception {
    final MockAbstractBinder binder = new MockAbstractBinder(root, form, handler);

    binder.bind();

    final MockBoundMember bound = (MockBoundMember) binder.getBoundMember("stringField");
    final Map map = new LinkedHashMap();
    map.put("unknownField", "unknownValue");
    map.put("stringField", Boolean.FALSE);

    binder.enabledConditionsChanged(map);
    assertEquals(Boolean.FALSE, bound.get("setEnabled(boolean)"));

    bound.clear();

    binder.visibleConditionsChanged(map);
    assertEquals(Boolean.FALSE, bound.get("setVisible(boolean)"));
  }
示例#9
0
  public void testDataProvidedIndexesChanged() throws Exception {
    DataProviderMetadata dataMeta =
        (DataProviderMetadata)
            form.getFormMetadata()
                .getDataProviderMetadatas()
                .get(new MethodEntry(form.getMethod("someDataProvider")));

    MockAbstractBinder binder = new MockAbstractBinder(root, form, handler);

    binder.bind();

    MockBoundDataProvider bound =
        (MockBoundDataProvider) binder.getBoundDataProvider(dataMeta.getWidgetName());

    final int[] indexes = new int[] {2, 5, 10};

    binder.dataProvidedIndexesChanged(dataMeta, indexes);

    assertSame(indexes, bound.get("updateIndexes(int[])"));
  }
示例#10
0
  public void testBindWithException() {
    MockAbstractBinder binder =
        new MockAbstractBinder(root, form, handler) {
          protected BoundField bindFieldMetadata(
              String name, FormMetadata formMetadata, FieldMetadata fieldMetadata) {
            throw new IllegalArgumentException();
          }

          public void unbind() {
            put("unbind()", Boolean.TRUE);
          }

          public void handleException(Throwable throwable) {
            put("handleException(Throwable)", throwable);
          }
        };

    binder.bind();

    assertNotNull(binder.get("unbind()"));
    assertTrue(binder.get("handleException(Throwable)") instanceof IllegalArgumentException);
  }