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

net.javacrumbs.mocksocket.http.HttpMockSocket Maven / Gradle / Ivy

/**
 * Copyright 2009-2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.javacrumbs.mocksocket.http;

import net.javacrumbs.mocksocket.MockSocket;
import net.javacrumbs.mocksocket.connection.data.RequestSocketData;
import net.javacrumbs.mocksocket.http.matchers.ContentMatcher;
import net.javacrumbs.mocksocket.http.matchers.HeaderMatcher;
import net.javacrumbs.mocksocket.http.matchers.MethodMatcher;
import net.javacrumbs.mocksocket.http.matchers.StatusMatcher;
import net.javacrumbs.mocksocket.http.matchers.UriMatcher;

import org.hamcrest.Matcher;
import org.hamcrest.core.CombinableMatcher;

public class HttpMockSocket extends MockSocket{
	
	protected HttpMockSocket()
	{
	}
	
	public static HttpResponseGenerator response()
	{
		return new HttpResponseGenerator();
	}
	
	public static HttpRequest request(int index)
	{
		return new HttpParser(recordedConnections().get(index));
	}
	
	public static CombinableMatcher status(Matcher statusMatcher) {
		return new CombinableMatcher(new StatusMatcher(statusMatcher));
	}

	public static CombinableMatcher header(String header, Matcher headerMatcher) {
		return new CombinableMatcher(new HeaderMatcher(header, headerMatcher));
	}
	
	public static CombinableMatcher content(Matcher contentMatcher) {
		return new CombinableMatcher(new ContentMatcher(contentMatcher));
	}

	public static CombinableMatcher method(Matcher methodMatcher) {
		return new CombinableMatcher(new MethodMatcher(methodMatcher));
	}
	
	public static CombinableMatcher uri(Matcher uriMatcher) {
		return new CombinableMatcher(new UriMatcher(uriMatcher));
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy