All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.officefloor.server.http.mock.MockHttpRequestBuilder Maven / Gradle / Ivy

There is a newer version: 3.40.0
Show newest version
/*-
 * #%L
 * Testing of HTTP Server
 * %%
 * Copyright (C) 2005 - 2020 Daniel Sagenschneider
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 * #L%
 */

package net.officefloor.server.http.mock;

import java.io.OutputStream;

import net.officefloor.server.http.HttpHeader;
import net.officefloor.server.http.HttpMethod;
import net.officefloor.server.http.HttpRequest;
import net.officefloor.server.http.HttpRequestCookie;
import net.officefloor.server.http.HttpVersion;
import net.officefloor.server.http.WritableHttpCookie;

/**
 * Builder for a mock {@link HttpRequest}.
 * 
 * @author Daniel Sagenschneider
 */
public interface MockHttpRequestBuilder {

	/**
	 * Flags with the {@link HttpRequest} is secure.
	 * 
	 * @param isSecure
	 *            true if secure {@link HttpRequest}.
	 * @return this.
	 */
	MockHttpRequestBuilder secure(boolean isSecure);

	/**
	 * Specifies the {@link HttpMethod}.
	 * 
	 * @param method
	 *            {@link HttpMethod}.
	 * @return this.
	 */
	MockHttpRequestBuilder method(HttpMethod method);

	/**
	 * Specifies the request URI.
	 * 
	 * @param requestUri
	 *            Request URI.
	 * @return this.
	 */
	MockHttpRequestBuilder uri(String requestUri);

	/**
	 * Specifies the {@link HttpVersion}.
	 * 
	 * @param version
	 *            {@link HttpVersion}.
	 * @return this.
	 */
	MockHttpRequestBuilder version(HttpVersion version);

	/**
	 * Adds a {@link HttpHeader}.
	 * 
	 * @param name
	 *            {@link HttpHeader} name.
	 * @param value
	 *            {@link HttpHeader} value.
	 * @return this.
	 */
	MockHttpRequestBuilder header(String name, String value);

	/**
	 * Adds a {@link HttpRequestCookie}.
	 * 
	 * @param name
	 *            {@link HttpRequestCookie} name.
	 * @param value
	 *            {@link HttpRequestCookie} value.
	 * @return this.
	 */
	MockHttpRequestBuilder cookie(String name, String value);

	/**
	 * 

* Adds all the appropriate {@link WritableHttpCookie} instances from the * {@link MockHttpResponse}. *

* This is a convenience method to enable sending back * {@link HttpRequestCookie} instances received on a previous * {@link MockHttpResponse}. * * @param response * {@link MockHttpResponse}. * @return this. */ MockHttpRequestBuilder cookies(MockHttpResponse response); /** * Sets the HTTP entity. * * @param entity * Entity content. * @return this. */ MockHttpRequestBuilder entity(String entity); /** * Obtains the {@link OutputStream} to write the HTTP entity. * * @return {@link OutputStream} to write the HTTP entity. */ OutputStream getHttpEntity(); /** * Flags to turn off checks for {@link HttpRequest} and provide efficient * processing. * * @param isStress * true to turn off checks and process more * efficiently. * @return this. */ MockHttpRequestBuilder setEfficientForStressTests(boolean isStress); /** *

* Builds a mock {@link HttpRequest} from this * {@link MockHttpRequestBuilder} configuration. *

* This is useful for testing to create a mock {@link HttpRequest}. * * @return Mock {@link HttpRequest}. */ HttpRequest build(); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy