public HttpRequest clone() { return not(request(), not) .withMethod(method) .withPath(path) .withQueryStringParameters(getQueryStringParameters().clone()) .withBody(body) .withHeaders(getHeaders().clone()) .withCookies(getCookies().clone()) .withKeepAlive(keepAlive) .withSecure(secure); }
public HttpResponse clone() { return response() .withStatusCode(statusCode) .withReasonPhrase(reasonPhrase) .withBody(body) .withHeaders(headers.clone()) .withCookies(cookies.clone()) .withDelay(getDelay()) .withConnectionOptions(connectionOptions); } }
/** * Static builder to create a response with a 200 status code and the string response body. * * @param body a string */ public static HttpResponse response(String body) { return new HttpResponse().withStatusCode(OK_200.code()).withReasonPhrase(OK_200.reasonPhrase()).withBody(body); }
/** * The path to match on such as "/some_mocked_path" any servlet context path is ignored for matching and should not be specified here * regex values are also supported such as ".*_path", see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html * for full details of the supported regex syntax * * @param path the path such as "/some_mocked_path" or a regex */ public HttpRequest withPath(String path) { withPath(string(path)); return this; }
/** * The HTTP method to match on such as "GET" or "POST" * * @param method the HTTP method such as "GET" or "POST" */ public HttpRequest withMethod(String method) { return withMethod(string(method)); }
@Override public HttpResponse handle(HttpRequest httpRequest) { if (httpRequest.getPath().getValue().endsWith("/callback")) { return httpResponse; } else { return notFoundResponse(); } } }
public String getURI(HttpRequest httpRequest) { QueryStringEncoder queryStringEncoder = new QueryStringEncoder(httpRequest.getPath().getValue()); for (Parameter parameter : httpRequest.getQueryStringParameterList()) { for (NottableString value : parameter.getValues()) { queryStringEncoder.addParam(parameter.getName().getValue(), value.getValue()); } } return queryStringEncoder.toString(); }
/** * Adds one header to match which can specified using plain strings or regular expressions * (for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html) * * @param name the header name * @param values the header values which can be a varags of strings or regular expressions */ public HttpRequest withHeader(String name, String... values) { this.headers.withEntry(header(name, values)); return this; }
@Override public void serialize(ParameterBody parameterBody, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); if (parameterBody.getNot() != null && parameterBody.getNot()) { jgen.writeBooleanField("not", parameterBody.getNot()); } jgen.writeStringField("type", parameterBody.getType().name()); if (!parameterBody.getValue().isEmpty()) { jgen.writeObjectField("value", parameterBody.getValue()); } jgen.writeEndObject(); } }
@Override public void serialize(Cookies collection, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); for (Cookie cookie : collection.getEntries()) { jgen.writeStringField(serialiseNottableString(cookie.getName()), serialiseNottableString(cookie.getValue())); } jgen.writeEndObject(); }
public boolean containsEntry(String name, String value) { return containsEntry(string(name), string(value)); }
/** * Static builder which will allow overriding proxied request with the specified request. * * @param httpRequest the HttpRequest specifying what to override */ public static HttpOverrideForwardedRequest forwardOverriddenRequest(HttpRequest httpRequest) { return new HttpOverrideForwardedRequest().withHttpRequest(httpRequest); }
/** * The query string parameters to match on as a list of Parameter objects where the values or keys of each parameter can be either a string or a regex * (for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html) * * @param parameters the list of Parameter objects where the values or keys of each parameter can be either a string or a regex */ public HttpRequest withQueryStringParameters(List<Parameter> parameters) { this.queryStringParameters.withEntries(parameters); return this; }
/** * Adds one header to match on as a Header object where the header values list can be a list of strings or regular expressions * (for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html) * * @param header the Header object which can have a values list of strings or regular expressions */ public HttpRequest replaceHeader(Header header) { this.headers.replaceEntry(header); return this; }
/** * Returns true if a header with the specified name has been added * * @param name the Header name * @return true if a header has been added with that name otherwise false */ public boolean containsHeader(String name) { return this.headers.containsEntry(name); }
public MultiValueMapMatcher(MockServerLogger mockServerLogger, KeysToMultiValues keysToMultiValues) { this.mockServerLogger = mockServerLogger; if (keysToMultiValues != null) { this.multiMap = keysToMultiValues.toCaseInsensitiveRegexMultiMap(); } else { this.multiMap = null; } }
/** * Static builder to create a not found response. */ public static HttpResponse notFoundResponse() { return new HttpResponse().withStatusCode(NOT_FOUND_404.code()).withReasonPhrase(NOT_FOUND_404.reasonPhrase()); }
/** * Add a header to return as a Header object, if a header with * the same name already exists this will NOT be modified but * two headers will exist * * @param name the header name as a NottableString * @param values the header values which can be a varags of NottableStrings */ public HttpResponse withHeader(NottableString name, NottableString... values) { this.headers.withEntry(header(name, values)); return this; }
/** * Adds one header to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, * such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString * can also be a plain string or a regex (for more details of the supported regex syntax * see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html) * * @param name the header name as a NottableString * @param values the header values which can be a varags of NottableStrings */ public HttpRequest withHeader(NottableString name, NottableString... values) { this.headers.withEntry(header(name, values)); return this; }