john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

ProxyTestTest

// 2012-09-10 johnpfeiffer requires a proxy server i.e. Squid server
import static org.junit.Assert.fail;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.http.client.ClientProtocolException;
import org.junit.Before;
import org.junit.Test;

public class ProxyTestTest
{
    private static final String CLASSVERSION = "0.28";
    private static final String PROXYSERVERHOST = "10.10.10.205";
    private static final int PROXYSERVERPORT = 3128;
    private URL defaultTargetUrl;

    @Before
    public void setUp() throws Exception
    {
        defaultTargetUrl = new URL( "https://issues.apache.org:443/" );
    }

    @Test
    public void testProxyTestGetVersion()
    {
        assertEquals( CLASSVERSION , ProxyTest.CLASSVERSION );
    }

    @Test
    public void testProxyTestUrlNull()
    {
        try
        {
            new ProxyTest.Builder().targetUrl( null ).build();
        }catch( IllegalArgumentException e )
        {
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }

    @Test
    public void testProxyTestUrlMissingPort() throws MalformedURLException
    {
        URL targetUrlMissingPort = new URL( "https://issues.apache.org/" );
        try
        {
            new ProxyTest.Builder().targetUrl( targetUrlMissingPort ).proxyServer( PROXYSERVERHOST ).proxyServerPort( PROXYSERVERPORT ).build();
        }catch( IllegalArgumentException e )
        {
            assertEquals( "ERROR: targetURL port must be configured, positive integer between 0 and 65536" , e.getMessage() );
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }

    @Test
    public void testProxyTestProxyServerNull()
    {
        try
        {
            new ProxyTest.Builder().proxyServer( null ).build();
        }catch( IllegalArgumentException e )
        {
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }

    @Test
    public void testProxyTestProxyServerEmpty()
    {
        try
        {
            new ProxyTest.Builder().proxyServer( "" ).build();
        }catch( IllegalArgumentException e )
        {
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }


    @Test
    public void testProxyTestProxyServerPortNegative()
    {
        try
        {
            new ProxyTest.Builder().proxyServerPort( -1 ).build();
        }catch( IllegalArgumentException e )
        {
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }

    @Test
    public void testProxyTestProxyServerPortMax()
    {
        try
        {
            new ProxyTest.Builder().proxyServerPort( 65537 ).build();
        }catch( IllegalArgumentException e )
        {
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }

    @Test
    public void testProxyTestMissingURL()
    {
        try
        {
            new ProxyTest.Builder().proxyServer( PROXYSERVERHOST ).proxyServerPort( PROXYSERVERPORT ).build();
        }catch( IllegalArgumentException e )
        {
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }

    @Test
    public void testProxyTestMissingProxyServer()
    {
        try
        {
            new ProxyTest.Builder().targetUrl( defaultTargetUrl ).proxyServerPort( PROXYSERVERPORT ).build();
        }catch( IllegalArgumentException e )
        {
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }

    @Test
    public void testProxyTestMissingProxyServerPort()
    {
        try
        {
            new ProxyTest.Builder().targetUrl( defaultTargetUrl ).proxyServer( PROXYSERVERHOST ).build();
        }catch( IllegalArgumentException e )
        {
            return;
        }
        fail( "Expected IllegalArgumentException" );
    }

    @Test
    public void testConnect() throws ClientProtocolException , IOException
    {
        ProxyTest main = new ProxyTest.Builder().targetUrl( defaultTargetUrl ).proxyServer( PROXYSERVERHOST ).proxyServerPort( PROXYSERVERPORT ).build();
        main.Connect();
        System.out.println( main.getResponse() );
    }

//  @Test public void testGetResponse()

} //end class

  • « Squid proxy ubuntu java jvm client configuration
  • ProxyTest »

Published

Sep 10, 2012

Category

java-classes

~268 words

Tags

  • classes 92
  • java 252
  • proxytesttest 1