/** * Adds a response header to this builder. If there was already a header with this * name the values will be added. * <p> * Headers are treated case insensitive. * * @param name the header name * @param values the values for this header * @return this builder */ public Builder withHeader(final String name, final String... values) { return withHeader(name, asList(values)); }
/** * Builds a {@link Response} for the OpenAPI validator out of the * original {@link MockHttpServletResponse}. * * @param originalResponse the original {@link MockHttpServletResponse} */ @Nonnull public static Response of(@Nonnull final MockHttpServletResponse originalResponse) { requireNonNull(originalResponse, "An original response is required"); final SimpleResponse.Builder builder = new SimpleResponse.Builder(originalResponse.getStatus()) .withBody(getBody(originalResponse)); originalResponse.getHeaderNames() .forEach(header -> builder.withHeader(header, originalResponse.getHeaders(header))); return builder.build(); }
/** * Builds a {@link Response} for the OpenAPI validator out of the * original {@link com.github.tomakehurst.wiremock.http.Response}. * * @param originalResponse the original {@link com.github.tomakehurst.wiremock.http.Response} */ @Nonnull public static Response of(@Nonnull final com.github.tomakehurst.wiremock.http.Response originalResponse) { requireNonNull(originalResponse, "An original response is required"); final SimpleResponse.Builder builder = new SimpleResponse.Builder(originalResponse.getStatus()) .withBody(originalResponse.getBodyAsString()); originalResponse.getHeaders().all().forEach(header -> builder.withHeader(header.key(), header.values())); return builder.build(); } }
/** * Builds a {@link Response} for the OpenAPI validator out of the * original {@link io.restassured.response.Response}. * * @param originalResponse the original {@link io.restassured.response.Response} */ @Nonnull public static Response of(@Nonnull final io.restassured.response.Response originalResponse) { requireNonNull(originalResponse, "An original response is required"); final SimpleResponse.Builder builder = new SimpleResponse.Builder(originalResponse.getStatusCode()) .withBody(originalResponse.getBody().asString()); if (originalResponse.getHeaders() != null) { originalResponse.getHeaders().forEach(header -> builder.withHeader(header.getName(), header.getValue())); } return builder.build(); } }
/** * Sets the content type header on this builder. * <p> * Equivalent to: <pre>withHeader("Content-Type", contentType);</pre> * * @param contentType The content type to set * * @return this builder */ public Builder withContentType(final String contentType) { return withHeader(CONTENT_TYPE, contentType); }