Search in sources :

Example 1 with Consumer

use of org.sonatype.goodies.httpfixture.server.jetty.behaviour.Consumer in project goodies by sonatype.

the class JettyProxyProviderTest method testProxyPut.

@Test
public void testProxyPut() throws Exception {
    JettyProxyProvider proxy = new JettyProxyProvider();
    Consumer consumer = new Consumer();
    proxy.addBehaviour("/*", new Debug(), consumer);
    proxy.start();
    URL url = new URL("http://speutel.invalid/foo");
    SocketAddress sa = new InetSocketAddress("localhost", proxy.getPort());
    Proxy p = new Proxy(Type.HTTP, sa);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection(p);
    conn.setDoOutput(true);
    conn.setRequestMethod("PUT");
    conn.connect();
    byte[] bytes = "TestPut".getBytes("US-ASCII");
    conn.getOutputStream().write(bytes);
    conn.getOutputStream().close();
    assertEquals(200, conn.getResponseCode());
    assertEquals(bytes.length, consumer.getTotal());
    conn.disconnect();
}
Also used : Proxy(java.net.Proxy) HttpURLConnection(java.net.HttpURLConnection) Consumer(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Consumer) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Debug(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Debug) URL(java.net.URL) Test(org.junit.Test)

Aggregations

HttpURLConnection (java.net.HttpURLConnection)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 SocketAddress (java.net.SocketAddress)1 URL (java.net.URL)1 Test (org.junit.Test)1 Consumer (org.sonatype.goodies.httpfixture.server.jetty.behaviour.Consumer)1 Debug (org.sonatype.goodies.httpfixture.server.jetty.behaviour.Debug)1