This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
HTTP
dart0 edited this page Jul 6, 2011
·
7 revisions
import static net.javacrumbs.mocksocket.http.HttpMockSocket.*;
@Test
public void testHttpClientSequential() throws ClientProtocolException, IOException {
expectCall()
.andReturn(response().withContent("Test"))
.andReturn(response().withStatus(404));
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"))));
httpget.abort();
HttpPost httppost = new HttpPost(ADDRESS);
HttpResponse postResponse = httpclient.execute(httppost);
assertThat(postResponse.getStatusLine().getStatusCode(), is(404));
httppost.abort();
}
@After
public void reset()
{
HttpMockSocket.reset();
}