@Nonnull @Override public Optional<String> getBody() { return delegate.getBody(); }
@Nonnull @Override public Collection<String> getHeaderValues(final String name) { return delegate.getHeaderValues(name); }
@Override public int getStatus() { return delegate.getStatus(); }
final Optional<String> responseBody = response.getBody(); if (response.getContentType().isPresent()) { log.info("Validation of '{}' not supported. Response body not validated.", response.getContentType().get());
/** * Determine whether a given response has a formdata content-type. * * @return Whether the content-type of the response (defined in the Content-Type header) is a FORM_DATA type. */ public static boolean isFormDataContentType(final Response response) { return isFormDataContentType(response.getContentType().orElse(null)); }
/** * Get the content-type header of this response, if it has been set. * * @return The content-type header, or empty if it has not been set. */ @Nonnull default Optional<String> getContentType() { return getHeaderValue(CONTENT_TYPE); }
/** * @return Whether the content-type of this response (defined in the Content-Type header) is a JSON type. */ public static boolean isJsonContentType(final Response response) { return isJsonContentType(response.getContentType().orElse(null)); }
/** * Determine whether a given request has a content-type header. * * @return Whether a content-type header is defined on the response */ public static boolean hasContentType(final Response response) { return response.getHeaderValue(Headers.CONTENT_TYPE).isPresent(); }
@Override public int getStatus() { return delegate.getStatus(); }
@Nonnull @Override public Collection<String> getHeaderValues(final String name) { return delegate.getHeaderValues(name); }
@Nonnull @Override public Optional<String> getBody() { return delegate.getBody(); }
final ApiOperation apiOperation) { final Optional<String> requestHeader = response.getContentType(); if (!requestHeader.isPresent()) { return ValidationReport.empty();
/** * Find the content-type that most specifically matches the content-type defined on the given response. * <p> * e.g. If the response has {@code Content-Type=text/plain} and the list of types is <code>[text/*, */*, text/plain]</code> * (all of which could match), the most specific match {@code text/plain} will be returned. * <p> * If there are no matches, will return empty. * * @param response The response to find a matching content type for * @param apiContentTypes The list of content types to search * * @return The most specific content type that matches the given request, or empty if none match. */ public static Optional<String> findMostSpecificMatch(final Response response, final Set<String> apiContentTypes) { return findMostSpecificMatch(response.getHeaderValue(Headers.CONTENT_TYPE).orElse("*/*"), apiContentTypes); }
@Override public int getStatus() { return delegate.getStatus(); }
@Nonnull @Override public Collection<String> getHeaderValues(final String name) { return delegate.getHeaderValues(name); }
@Nonnull @Override public Optional<String> getBody() { return delegate.getBody(); }
/** * Matches all responses with the given status. */ public static WhitelistRule responseStatusIs(final int status) { return new PrintableWhitelistRule( "Response status is " + status, (message, operation, request, response) -> response != null && response.getStatus() == status); }
@Override public boolean matches(final ValidationReport.Message message, final ApiOperation operation, final Response response) { return response.getHeaderValues(header) .stream() .anyMatch(value -> regexpContain(value, regexp)); } });
/** * Matches all responses with the given status type. */ public static WhitelistRule responseStatusTypeIs(final StatusType statusType) { return new PrintableWhitelistRule( "Response status is " + statusType, (message, operation, request, response) -> response != null && statusType.matches(response.getStatus())); }
/** * Get the first of header value for the header param with the given name (if any exist). * * @param name The (case insensitive) name of the parameter to retrieve * * @return The first header value for that param (if it exists) */ @Nonnull default Optional<String> getHeaderValue(final String name) { return getHeaderValues(name).stream().findFirst(); }