// Path: core/src/main/java/net/javacrumbs/mocksocket/MockSocket.java
// public static Matcher<RequestSocketData> address(Matcher<String> addressMatcher)
// {
// 	return new CombinableMatcher<RequestSocketData>(new AddressMatcher(addressMatcher));
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/MockSocket.java
// public static List<RequestSocketData> recordedConnections()
// {
// 	return StaticConnectionFactory.getRequestRecorder().requestData();
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static CombinableMatcher<RequestSocketData> header(String header, Matcher<String> headerMatcher) {
// 	return new CombinableMatcher<RequestSocketData>(new HeaderMatcher(header, headerMatcher));
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static CombinableMatcher<RequestSocketData> method(Matcher<String> methodMatcher) {
// 	return new CombinableMatcher<RequestSocketData>(new MethodMatcher(methodMatcher));
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static HttpRequest request(int index)
// {
// 	return new HttpParser(recordedConnections().get(index));
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static HttpResponseGenerator response()
// {
// 	return new HttpResponseGenerator();
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static CombinableMatcher<RequestSocketData> uri(Matcher<String> uriMatcher) {
// 	return new CombinableMatcher<RequestSocketData>(new UriMatcher(uriMatcher));
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/MockSocketException.java
// public class MockSocketException extends RuntimeException {
// 	private static final long serialVersionUID = -6476984055059688027L;
// 
// 	public MockSocketException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public MockSocketException(String message) {
// 		super(message);
// 	}
// 
// 	public MockSocketException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 
// }


import static net.javacrumbs.mocksocket.MockSocket.address;
import static net.javacrumbs.mocksocket.MockSocket.recordedConnections;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.expectCall;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.header;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.method;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.request;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.response;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.uri;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItem;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import net.javacrumbs.mocksocket.MockSocketException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.After;
import org.junit.Test;
/**
 * 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;





public class SampleTest {
	private static final String ADDRESS = "http://localhost/";

	@After
	public void reset()
	{
		HttpMockSocket.reset();
	}

	@Test
	public void testHttpClientMethod() throws ClientProtocolException, IOException {
		expectCall()
			.andWhenRequest(method(is("POST")).and(address(is("localhost:80")))).thenReturn(response().withStatus(404))
			.andWhenRequest(method(is("GET"))).thenReturn(response().withStatus(200).withContent("Text"));
		
		HttpClient httpclient = new DefaultHttpClient();
		
		HttpGet httpget = new HttpGet(ADDRESS);
		httpget.addHeader("Accept","text/plain");
		HttpResponse getResponse = httpclient.execute(httpget);
		assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
		
		assertThat(recordedConnections(), hasItem(header("Accept", is("text/plain"))));
		assertThat(recordedConnections().get(0), method(is("GET")));
// Path: core/src/main/java/net/javacrumbs/mocksocket/MockSocket.java
// public static Matcher<RequestSocketData> address(Matcher<String> addressMatcher)
// {
// 	return new CombinableMatcher<RequestSocketData>(new AddressMatcher(addressMatcher));
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/MockSocket.java
// public static List<RequestSocketData> recordedConnections()
// {
// 	return StaticConnectionFactory.getRequestRecorder().requestData();
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static CombinableMatcher<RequestSocketData> header(String header, Matcher<String> headerMatcher) {
// 	return new CombinableMatcher<RequestSocketData>(new HeaderMatcher(header, headerMatcher));
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static CombinableMatcher<RequestSocketData> method(Matcher<String> methodMatcher) {
// 	return new CombinableMatcher<RequestSocketData>(new MethodMatcher(methodMatcher));
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static HttpRequest request(int index)
// {
// 	return new HttpParser(recordedConnections().get(index));
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static HttpResponseGenerator response()
// {
// 	return new HttpResponseGenerator();
// }
// 
// Path: http/src/main/java/net/javacrumbs/mocksocket/http/HttpMockSocket.java
// public static CombinableMatcher<RequestSocketData> uri(Matcher<String> uriMatcher) {
// 	return new CombinableMatcher<RequestSocketData>(new UriMatcher(uriMatcher));
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/MockSocketException.java
// public class MockSocketException extends RuntimeException {
// 	private static final long serialVersionUID = -6476984055059688027L;
// 
// 	public MockSocketException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public MockSocketException(String message) {
// 		super(message);
// 	}
// 
// 	public MockSocketException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 
// }


// Path: http/src/test/java/net/javacrumbs/mocksocket/http/SampleTest.java
import static net.javacrumbs.mocksocket.MockSocket.address;
import static net.javacrumbs.mocksocket.MockSocket.recordedConnections;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.expectCall;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.header;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.method;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.request;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.response;
import static net.javacrumbs.mocksocket.http.HttpMockSocket.uri;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItem;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import net.javacrumbs.mocksocket.MockSocketException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.After;
import org.junit.Test;

/**
 * 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;





public class SampleTest {
	private static final String ADDRESS = "http://localhost/";

	@After
	public void reset()
	{
		HttpMockSocket.reset();
	}

	@Test
	public void testHttpClientMethod() throws ClientProtocolException, IOException {
		expectCall()
			.andWhenRequest(method(is("POST")).and(address(is("localhost:80")))).thenReturn(response().withStatus(404))
			.andWhenRequest(method(is("GET"))).thenReturn(response().withStatus(200).withContent("Text"));
		
		HttpClient httpclient = new DefaultHttpClient();
		
		HttpGet httpget = new HttpGet(ADDRESS);
		httpget.addHeader("Accept","text/plain");
		HttpResponse getResponse = httpclient.execute(httpget);
		assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
		
		assertThat(recordedConnections(), hasItem(header("Accept", is("text/plain"))));
		assertThat(recordedConnections().get(0), method(is("GET")));
		assertThat(request(0).getMethod(), is("GET"));