Example usage for org.apache.commons.httpclient HostConfiguration equals

List of usage examples for org.apache.commons.httpclient HostConfiguration equals

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HostConfiguration equals.

Prototype

public boolean equals(Object paramObject) 

Source Link

Usage

From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java

public void testConnectionReuseWithoutParams() throws Exception {
    CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(null);

    HostConfiguration h1 = new HostConfiguration();
    h1.setHost(address, server1.getLocalPort());

    HttpConnection c1 = manager.getConnection(h1);

    // new connection
    assertTrue(!c1.isOpen());//from  w  w w.j  a v  a 2s . co m

    c1.open();
    c1.releaseConnection();

    HostConfiguration h2 = new HostConfiguration();
    h2.setHost(address, server1.getLocalPort());

    HttpConnection c2 = manager.getConnection(h2);

    // connection should have been released
    // so c2 is c1
    assertTrue(h2.equals(h1));
    assertTrue(c2 == c1);
    assertTrue(c2.isOpen());

    HttpConnection c3 = manager.getConnection(h2);

    // connection c2 was not released so new connection
    // c2 != c3
    assertTrue(!c3.isOpen());
    assertTrue(c3 != c2);
    assertTrue(c3 != c1);

    c2.releaseConnection();
    c3.releaseConnection();

    Server server2 = new Server();

    // it's a new port
    HostConfiguration h4 = new HostConfiguration();
    h4.setHost(address, server2.getLocalPort());

    HttpConnection c4 = manager.getConnection(h4);

    assertTrue(!c4.isOpen());
    assertTrue(c4 != c1);
    assertTrue(c4 != c2);
    assertTrue(c4 != c3);

    server2.close();
}

From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java

public void testConnectionReuseWithParams() throws Exception {
    CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(PARAMS);

    HostConfiguration h1 = new HostConfiguration();
    h1.setHost(address, server1.getLocalPort());
    h1.getParams().setParameter("A", "foo");
    h1.getParams().setParameter("B", "bar");
    h1.getParams().setParameter("C", "fff");

    HttpConnection c1 = manager.getConnection(h1);

    assertTrue(!c1.isOpen());/*  w ww  .  ja  v  a2  s .  co  m*/
    c1.open();
    c1.releaseConnection();

    HostConfiguration h2 = new HostConfiguration();
    h2.setHost(address, server1.getLocalPort());
    h2.getParams().setParameter("A", "foo");
    h2.getParams().setParameter("B", "bar");
    // still should be reused since C is not checked param
    h2.getParams().setParameter("C", "ggg");

    HttpConnection c2 = manager.getConnection(h2);

    // connection should have been released
    // so c2 is c1
    assertTrue(h2.equals(h1));
    assertTrue(c2.isOpen());
    assertTrue(c2 == c1);

    HttpConnection c3 = manager.getConnection(h2);

    // new connection becuase it wasn't released
    assertTrue(c3 != c1);
    assertTrue(c3 != c2);
    assertTrue(!c3.isOpen());

    c2.releaseConnection();
    c3.releaseConnection();

    // this one does not have params
    HostConfiguration h4 = new HostConfiguration();
    h4.setHost(address, server1.getLocalPort());

    HttpConnection c4 = manager.getConnection(h4);

    // new connection
    assertTrue(c4 != c1);
    assertTrue(c4 != c2);
    assertTrue(c4 != c3);
    assertTrue(!c4.isOpen());

    c4.open();
    c4.releaseConnection();

    // this one only has B parameter
    HostConfiguration h5 = new HostConfiguration();
    h5.setHost(address, server1.getLocalPort());
    h5.getParams().setParameter("B", "bar");

    HttpConnection c5 = manager.getConnection(h5);

    // also a new connection
    assertTrue(c5 != c1);
    assertTrue(c5 != c2);
    assertTrue(c5 != c3);
    assertTrue(c5 != c4);
    assertTrue(!c5.isOpen());

    c5.open();
    c5.releaseConnection();

    // this one only has different B parameter
    HostConfiguration h6 = new HostConfiguration();
    h6.setHost(address, server1.getLocalPort());
    h6.getParams().setParameter("A", "fooo");
    h6.getParams().setParameter("B", "bar");

    HttpConnection c6 = manager.getConnection(h6);

    assertTrue(c6 != c1);
    assertTrue(c6 != c2);
    assertTrue(c6 != c3);
    assertTrue(c6 != c4);
    assertTrue(c6 != c5);
    assertTrue(!c6.isOpen());

    c6.open();
    c6.releaseConnection();
}

From source file:org.globus.axis.transport.commons.tests.ExtendedHostConfigurationTest.java

public void testEqualsAndHashNoExtra() {

    HostConfiguration h1 = getHostConfiguration(null);
    HostConfiguration h2 = getHostConfiguration(null);

    assertEquals(h1.hashCode(), h2.hashCode());
    assertTrue(h1.equals(h2));
    assertTrue(h2.equals(h1));/*  w  ww  .  j a v a 2 s .com*/

    System.out.println(h1);
}

From source file:org.globus.axis.transport.commons.tests.ExtendedHostConfigurationTest.java

public void testEqualsAndHashSame() {

    HostConfiguration h1 = getHostConfiguration(PARAMS);
    HostConfiguration h2 = getHostConfiguration(PARAMS);

    assertEquals(h1.hashCode(), h2.hashCode());
    assertTrue(h1.equals(h2));
    assertTrue(h2.equals(h1));// w w  w .  ja va 2  s.  c o m

    System.out.println(h1);
}

From source file:org.globus.axis.transport.commons.tests.ExtendedHostConfigurationTest.java

public void testEqualsAndHashDifferent() {

    HostConfiguration h1 = getHostConfiguration(PARAMS, "foo", "B");
    HostConfiguration h2 = getHostConfiguration(PARAMS, "foo", "C");

    assertTrue(h1.hashCode() != h2.hashCode());
    assertTrue(!h1.equals(h2));
    assertTrue(!h2.equals(h1));/*from www.ja  va2 s . co m*/

    System.out.println(h1);
    System.out.println(h2);
}