Search in sources :

Example 11 with HttpTrace

use of org.apache.http.client.methods.HttpTrace in project vespa by vespa-engine.

the class JDiscHttpServletTest method requireThatServerRespondsToAllMethods.

@Test
public void requireThatServerRespondsToAllMethods() throws Exception {
    final TestDriver driver = TestDrivers.newInstance(newEchoHandler());
    final URI uri = driver.client().newUri("/status.html");
    driver.client().execute(new HttpGet(uri)).expectStatusCode(is(OK));
    driver.client().execute(new HttpPost(uri)).expectStatusCode(is(OK));
    driver.client().execute(new HttpHead(uri)).expectStatusCode(is(OK));
    driver.client().execute(new HttpPut(uri)).expectStatusCode(is(OK));
    driver.client().execute(new HttpDelete(uri)).expectStatusCode(is(OK));
    driver.client().execute(new HttpOptions(uri)).expectStatusCode(is(OK));
    driver.client().execute(new HttpTrace(uri)).expectStatusCode(is(OK));
    driver.client().execute(new HttpPatch(uri)).expectStatusCode(is(OK));
    assertThat(driver.close(), is(true));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpTrace(org.apache.http.client.methods.HttpTrace) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpGet(org.apache.http.client.methods.HttpGet) HttpOptions(org.apache.http.client.methods.HttpOptions) URI(java.net.URI) HttpHead(org.apache.http.client.methods.HttpHead) HttpPut(org.apache.http.client.methods.HttpPut) HttpPatch(org.apache.http.client.methods.HttpPatch) Test(org.testng.annotations.Test)

Example 12 with HttpTrace

use of org.apache.http.client.methods.HttpTrace in project nanohttpd by NanoHttpd.

the class SSLServerSocketFactoryTest method testSSLConnection.

@Test
public void testSSLConnection() throws ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpTrace httphead = new HttpTrace("https://localhost:9043/index.html");
    HttpResponse response = httpclient.execute(httphead);
    HttpEntity entity = response.getEntity();
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertEquals(9043, this.testServer.getListeningPort());
    Assert.assertTrue(this.testServer.isAlive());
}
Also used : HttpTrace(org.apache.http.client.methods.HttpTrace) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Example 13 with HttpTrace

use of org.apache.http.client.methods.HttpTrace in project nanohttpd by NanoHttpd.

the class TestNanoFileUpLoad method testNormalRequest.

@Test
public void testNormalRequest() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpTrace httphead = new HttpTrace("http://localhost:8192/index.html");
    CloseableHttpResponse response = httpclient.execute(httphead);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    response.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpTrace(org.apache.http.client.methods.HttpTrace) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Test(org.junit.Test)

Example 14 with HttpTrace

use of org.apache.http.client.methods.HttpTrace in project nanohttpd by NanoHttpd.

the class HttpSSLServerTest method testSSLConnection.

@Test
public void testSSLConnection() throws ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpTrace httphead = new HttpTrace("https://localhost:9043/index.html");
    HttpResponse response = httpclient.execute(httphead);
    HttpEntity entity = response.getEntity();
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertEquals(9043, this.testServer.getListeningPort());
    Assert.assertTrue(this.testServer.isAlive());
}
Also used : HttpTrace(org.apache.http.client.methods.HttpTrace) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Example 15 with HttpTrace

use of org.apache.http.client.methods.HttpTrace in project nanohttpd by NanoHttpd.

the class TestNanolets method staticFiles.

@Test
public void staticFiles() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpTrace httphead = new HttpTrace("http://localhost:9090/browse/blabla.html");
    CloseableHttpResponse response = httpclient.execute(httphead);
    HttpEntity entity = response.getEntity();
    String string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("<html><body><h3>just a page</h3></body></html>", string);
    response.close();
    httphead = new HttpTrace("http://localhost:9090/browse/dir/blabla.html");
    response = httpclient.execute(httphead);
    entity = response.getEntity();
    string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("<html><body><h3>just an other page</h3></body></html>", string);
    response.close();
    httphead = new HttpTrace("http://localhost:9090/browse/dir/nanohttpd_logo.png");
    response = httpclient.execute(httphead);
    entity = response.getEntity();
    Assert.assertEquals("image/png", entity.getContentType().getValue());
    response.close();
    httphead = new HttpTrace("http://localhost:9090/browse/dir/xxx.html");
    response = httpclient.execute(httphead);
    entity = response.getEntity();
    string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("<html><body><h3>Error 404: the requested page doesn't exist.</h3></body></html>", string);
    response.close();
    httphead = new HttpTrace("http://localhost:9090/browse/dir/");
    response = httpclient.execute(httphead);
    entity = response.getEntity();
    string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("<html><body><h3>just an index page</h3></body></html>", string);
    response.close();
    httphead = new HttpTrace("http://localhost:9090/browse/exception.html");
    response = httpclient.execute(httphead);
    Assert.assertEquals(Status.REQUEST_TIMEOUT.getRequestStatus(), response.getStatusLine().getStatusCode());
    entity = response.getEntity();
    string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("", string);
    response.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpTrace(org.apache.http.client.methods.HttpTrace) HttpEntity(org.apache.http.HttpEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Test(org.junit.Test)

Aggregations

HttpTrace (org.apache.http.client.methods.HttpTrace)17 Test (org.junit.Test)10 HttpEntity (org.apache.http.HttpEntity)6 HttpHead (org.apache.http.client.methods.HttpHead)6 HttpOptions (org.apache.http.client.methods.HttpOptions)6 HttpPost (org.apache.http.client.methods.HttpPost)6 HttpPut (org.apache.http.client.methods.HttpPut)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 HttpPatch (org.apache.http.client.methods.HttpPatch)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 TestRequest (com.android.volley.mock.TestRequest)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 HttpResponse (org.apache.http.HttpResponse)3 HttpGet (org.apache.http.client.methods.HttpGet)3 StringEntity (org.apache.http.entity.StringEntity)3 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)3 IOException (java.io.IOException)2 URL (java.net.URL)2