Example #1
0
  @Override
  public boolean equals(final Object o) {
    if (this == o) {
      return true;
    } else if (o instanceof StubRequest) {
      final StubRequest dataStoreRequest = (StubRequest) o;

      if (!urlsMatch(dataStoreRequest.url, url)) {
        return false;
      }
      if (!arraysIntersect(dataStoreRequest.getMethod(), getMethod())) {
        ANSITerminal.dump(
            String.format(
                "METHOD %s failed match for %s", dataStoreRequest.getMethod(), getMethod()));
        return false;
      }
      if (!postBodiesMatch(dataStoreRequest.getPostBody(), getPostBody())) {
        ANSITerminal.dump(
            String.format(
                "POST BODY %s failed match for %s", dataStoreRequest.getPostBody(), getPostBody()));
        return false;
      }
      if (!headersMatch(dataStoreRequest.getHeaders(), getHeaders())) {
        ANSITerminal.dump(
            String.format(
                "HEADERS %s failed match for %s", dataStoreRequest.getHeaders(), getHeaders()));
        return false;
      }
      if (!queriesMatch(dataStoreRequest.getQuery(), getQuery())) {
        ANSITerminal.dump(
            String.format("QUERY %s failed match for %s", dataStoreRequest.getQuery(), getQuery()));
        return false;
      }
      return true;
    }

    return false;
  }
Example #2
0
  public static StubRequest createFromHttpServletRequest(final HttpServletRequest request)
      throws IOException {
    final StubRequest assertionRequest =
        StubRequest.newStubRequest(
            request.getPathInfo(), HandlerUtils.extractPostRequestBody(request, "stubs"));
    assertionRequest.addMethod(request.getMethod());

    final Enumeration<String> headerNamesEnumeration = request.getHeaderNames();
    final List<String> headerNames =
        ObjectUtils.isNotNull(headerNamesEnumeration)
            ? Collections.list(request.getHeaderNames())
            : new LinkedList<String>();
    for (final String headerName : headerNames) {
      final String headerValue = request.getHeader(headerName);
      assertionRequest.getHeaders().put(StringUtils.toLower(headerName), headerValue);
    }

    assertionRequest.getQuery().putAll(CollectionUtils.constructParamMap(request.getQueryString()));

    return assertionRequest;
  }