public static Object sendAndReceive(
      RouterController controller,
      MockHttpServletRequest request,
      final String action,
      String method,
      boolean namedParameter,
      Object data,
      final Object result) {

    MockHttpServletResponse response = new MockHttpServletResponse();

    int tid = (int) (Math.random() * 1000);
    Map<String, Object> edRequest = createRequestJson(action, method, namedParameter, tid, data);

    request.setContent(ControllerUtil.writeAsByte(edRequest));
    try {
      controller.router(request, response, Locale.ENGLISH);
    } catch (IOException e) {
      fail("call controller.router: " + e.getMessage());
    }
    List<ExtDirectResponse> responses = readDirectResponses(response.getContentAsByteArray());
    assertThat(responses).hasSize(1);

    ExtDirectResponse edResponse = responses.get(0);

    assertThat(edResponse.getAction()).isEqualTo(action);
    assertThat(edResponse.getMethod()).isEqualTo(method);
    assertThat(edResponse.getTid()).isEqualTo(tid);
    assertThat(edResponse.getWhere()).isNull();

    if (result == null) {
      assertThat(edResponse.getType()).isEqualTo("exception");
      assertThat(edResponse.getResult()).isNull();
      assertThat(edResponse.getMessage()).isEqualTo("Server Error");
    } else {
      assertThat(edResponse.getType()).isEqualTo("rpc");
      assertThat(edResponse.getMessage()).isNull();
      if (result == Void.TYPE) {
        assertThat(edResponse.getResult()).isNull();
      } else if (result instanceof Class<?>) {
        Object r = ControllerUtil.convertValue(edResponse.getResult(), (Class<?>) result);
        return r;
      } else if (result instanceof TypeReference) {
        Object r = ControllerUtil.convertValue(edResponse.getResult(), (TypeReference<?>) result);
        return r;
      } else {
        assertThat(edResponse.getResult()).isEqualTo(result);
      }
    }

    return edResponse.getResult();
  }
  @Test
  public void testFilters() throws Exception {

    int index = 1;
    for (String json : jsonList) {
      MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, json);
      List<ExtDirectResponse> responses =
          ControllerUtil.readDirectResponses(result.getResponse().getContentAsByteArray());

      assertThat(responses).hasSize(1);
      ExtDirectResponse resp = responses.get(0);
      assertThat(resp.getAction()).isEqualTo("remoteProviderStoreRead");
      assertThat(resp.getMethod()).isEqualTo("methodFilter");
      assertThat(resp.getType()).isEqualTo("rpc");
      assertThat(resp.getTid()).isEqualTo(index);
      assertThat(resp.getMessage()).isNull();
      assertThat(resp.getWhere()).isNull();
      assertThat(resp.getResult()).isNotNull();

      List<Row> rows =
          ControllerUtil.convertValue(
              resp.getResult(),
              new TypeReference<List<Row>>() {
                // nothing here
              });

      assertThat(rows).hasSize(1);
      assertThat(rows.get(0).getId()).isEqualTo(index);

      index++;
    }

    assertThat(index).isEqualTo(34);
  }