/** * Verifies HTTP header against provided matcher, and throws * {@link AssertionError} in case of mismatch. * @param name Name of the header to match * @param value The value to expect in one of the headers * @return This object * @since 0.9 */ public RestResponse assertHeader(final String name, final String value) { return this.assertHeader(name, Matchers.hasItems(value)); }
/** * Follow LOCATION header. * @return New request */ public Request follow() { this.assertHeader( HttpHeaders.LOCATION, Matchers.not(Matchers.emptyIterableOf(String.class)) ); return this.jump( URI.create(this.headers().get(HttpHeaders.LOCATION).get(0)) ); }
@Override public String render( final JsonObject json) throws IOException { final StringWriter output = new StringWriter(); Json.createWriter(output).writeObject(json); return this.request .body() .set(output.toString()) .back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .assertHeader( HttpHeaders.CONTENT_TYPE, Matchers.everyItem( Matchers.startsWith(MediaType.TEXT_HTML) ) ) .body(); }
@Override public String raw( final String text) throws IOException { return this.request .body() .set(text) .back() .uri().path("raw").back() .reset(HttpHeaders.CONTENT_TYPE) .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN) .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .assertHeader( HttpHeaders.CONTENT_TYPE, Matchers.everyItem( Matchers.startsWith(MediaType.TEXT_HTML) ) ) .body(); }