コード例 #1
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()"));
  }
コード例 #2
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)"));
  }
コード例 #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 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);
  }
コード例 #5
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)"));
  }