package org.mortbay.jetty.client;

import java.io.IOException;
import java.net.InetSocketAddress;

import junit.framework.TestCase;

import org.mortbay.io.Buffer;
import org.mortbay.io.ByteArrayBuffer;
import org.mortbay.jetty.MimeTypes;

/**
 * Functional testing for HttpExchange.
 * 
 * @author Matthew Purland
 */
public class HttpExchangeTest extends TestCase
{
    private HttpExchange httpExchange;

    public void setUp()
    {
        httpExchange=new HttpExchange()
        {
            protected void onProgress(Buffer content, boolean last)
            {
                System.err.println("Response content="+content);
                super.onProgress(content,last);
            }

            protected void onSuccess(int status)
            {
                System.err.println("Response status="+status);
                super.onSuccess(status);
            }
        };

        httpExchange.setURL("http://localhost:8080/test/dump/info");

        HttpConnectionPool connectionPool=new HttpConnectionPool();

        httpExchange.setConnectionPool(connectionPool);

        httpExchange.setMethod("GET"); // Optional. GET by default
        httpExchange.setAddress(new InetSocketAddress("localhost",8080)); // May use setURL instead
        httpExchange.setURI("/test/dump/info");
        httpExchange.setRequestContentType(MimeTypes.FORM_ENCODED);
        httpExchange.addRequestHeader("arbitrary","value");
        httpExchange.setRequestContent(new ByteArrayBuffer("param=value\n"));
    }

    /**
     * Test sending data through the exchange.
     * 
     * @throws IOException
     */
    public void testSend() throws IOException
    {
        httpExchange.send();
        httpExchange.send(true); // pipelined on last used connection
    }
}
