HTTPCLIENT-712: removed deprecated proxy chain constructor, added testcase for null enums

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@606184 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roland Weber 2007-12-21 12:58:07 +00:00
parent 52cb8d3def
commit 789bc843c0
5 changed files with 190 additions and 135 deletions

View File

@ -115,8 +115,10 @@ public final class HttpRoute implements Cloneable {
* <code>null</code> for a direct route * <code>null</code> for a direct route
* @param secure <code>true</code> if the route is (to be) secure, * @param secure <code>true</code> if the route is (to be) secure,
* <code>false</code> otherwise * <code>false</code> otherwise
* @param tunnelled the tunnel type of this route * @param tunnelled the tunnel type of this route, or
* @param layered the layering type of this route * <code>null</code> for PLAIN
* @param layered the layering type of this route, or
* <code>null</code> for PLAIN
*/ */
private HttpRoute(InetAddress local, private HttpRoute(InetAddress local,
HttpHost target, HttpHost[] proxies, HttpHost target, HttpHost[] proxies,
@ -131,6 +133,12 @@ public final class HttpRoute implements Cloneable {
("Proxy required if tunnelled."); ("Proxy required if tunnelled.");
} }
// tunnelled is already checked above, that is in line with the default
if (tunnelled == null)
tunnelled = TunnelType.PLAIN;
if (layered == null)
layered = LayerType.PLAIN;
this.targetHost = target; this.targetHost = target;
this.localAddress = local; this.localAddress = local;
this.proxyChain = proxies; this.proxyChain = proxies;
@ -159,33 +167,6 @@ public final class HttpRoute implements Cloneable {
} }
/**
* Creates a new route with all attributes specified explicitly.
*
* @param target the host to which to route
* @param local the local address to route from, or
* <code>null</code> for the default
* @param proxies the proxy chain to use, or
* <code>null</code> for a direct route
* @param secure <code>true</code> if the route is (to be) secure,
* <code>false</code> otherwise
* @param tunnelled <code>true</code> if the route is (to be) tunnelled
* end-to-end via the proxy chain,
* <code>false</code> otherwise
* @param layered <code>true</code> if the route includes a
* layered protocol,
* <code>false</code> otherwise
*
* @deprecated use enums instead of boolean for 'tunnelled' and 'layered'
*/
public HttpRoute(HttpHost target, InetAddress local, HttpHost[] proxies,
boolean secure, boolean tunnelled, boolean layered) {
this(local, target, toChain(proxies), secure,
tunnelled ? TunnelType.TUNNELLED : TunnelType.PLAIN,
layered ? LayerType.LAYERED : LayerType.PLAIN);
}
/** /**
* Creates a new route with at most one proxy. * Creates a new route with at most one proxy.
* *

View File

@ -35,6 +35,8 @@ import java.net.InetAddress;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.util.CharArrayBuffer; import org.apache.http.util.CharArrayBuffer;
import org.apache.http.conn.HttpRoute.TunnelType;
import org.apache.http.conn.HttpRoute.LayerType;
/** /**
@ -69,10 +71,10 @@ public final class RouteTracker implements Cloneable {
private HttpHost[] proxyChain; private HttpHost[] proxyChain;
/** Whether the the route is tunnelled end-to-end through proxies. */ /** Whether the the route is tunnelled end-to-end through proxies. */
private boolean tunnelled; private TunnelType tunnelled;
/** Whether the route is layered over a tunnel. */ /** Whether the route is layered over a tunnel. */
private boolean layered; private LayerType layered;
/** Whether the route is secure. */ /** Whether the route is secure. */
private boolean secure; private boolean secure;
@ -92,6 +94,8 @@ public final class RouteTracker implements Cloneable {
} }
this.targetHost = target; this.targetHost = target;
this.localAddress = local; this.localAddress = local;
this.tunnelled = TunnelType.PLAIN;
this.layered = LayerType.PLAIN;
} }
@ -155,7 +159,7 @@ public final class RouteTracker implements Cloneable {
if (this.proxyChain == null) { if (this.proxyChain == null) {
throw new IllegalStateException("No tunnel without proxy."); throw new IllegalStateException("No tunnel without proxy.");
} }
this.tunnelled = true; this.tunnelled = TunnelType.TUNNELLED;
this.secure = secure; this.secure = secure;
} }
@ -204,7 +208,7 @@ public final class RouteTracker implements Cloneable {
throw new IllegalStateException throw new IllegalStateException
("No layered protocol unless connected."); ("No layered protocol unless connected.");
} }
this.layered = true; this.layered = LayerType.LAYERED;
this.secure = secure; this.secure = secure;
} }
@ -307,24 +311,51 @@ public final class RouteTracker implements Cloneable {
/** /**
* Checks whether this route is tunnelled through a proxy. * Obtains the tunnel type of this route.
* If there is a proxy chain, only end-to-end tunnels are considered.
* *
* @return <code>true</code> if tunnelled, * @return the tunnelling type
* <code>false</code> otherwise
*/ */
public final boolean isTunnelled() { public final TunnelType getTunnelType() {
return this.tunnelled; return this.tunnelled;
} }
/**
* Checks whether this route is tunnelled through a proxy.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return <code>true</code> if tunnelled end-to-end through at least
* one proxy,
* <code>false</code> otherwise
*/
public final boolean isTunnelled() {
return (this.tunnelled == TunnelType.TUNNELLED);
}
/**
* Obtains the layering type of this route.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return the layering type
*/
public final LayerType getLayerType() {
return this.layered;
}
/** /**
* Checks whether this route includes a layered protocol. * Checks whether this route includes a layered protocol.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
* *
* @return <code>true</code> if layered, * @return <code>true</code> if layered,
* <code>false</code> otherwise * <code>false</code> otherwise
*/ */
public final boolean isLayered() { public final boolean isLayered() {
return this.layered; return (this.layered == LayerType.LAYERED);
} }
@ -421,10 +452,9 @@ public final class RouteTracker implements Cloneable {
hc ^= 0x11111111; hc ^= 0x11111111;
if (this.secure) if (this.secure)
hc ^= 0x22222222; hc ^= 0x22222222;
if (this.tunnelled)
hc ^= 0x44444444; hc ^= this.tunnelled.hashCode();
if (this.layered) hc ^= this.layered.hashCode();
hc ^= 0x88888888;
return hc; return hc;
} }
@ -446,9 +476,9 @@ public final class RouteTracker implements Cloneable {
cab.append('{'); cab.append('{');
if (this.connected) if (this.connected)
cab.append('c'); cab.append('c');
if (this.tunnelled) if (this.tunnelled == TunnelType.TUNNELLED)
cab.append('t'); cab.append('t');
if (this.layered) if (this.layered == LayerType.LAYERED)
cab.append('l'); cab.append('l');
if (this.secure) if (this.secure)
cab.append('s'); cab.append('s');

View File

@ -41,6 +41,8 @@ import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.conn.HttpRoute.TunnelType;
import org.apache.http.conn.HttpRoute.LayerType;
/** /**
@ -106,8 +108,8 @@ public class TestHttpRoute extends TestCase {
// create a route with all arguments and check the details // create a route with all arguments and check the details
HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 }; HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 };
HttpRoute route = new HttpRoute(TARGET1, LOCAL41, chain3, HttpRoute route = new HttpRoute(TARGET1, LOCAL41, chain3, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
assertEquals("wrong target", assertEquals("wrong target",
TARGET1, route.getTargetHost()); TARGET1, route.getTargetHost());
assertEquals("wrong local address", assertEquals("wrong local address",
@ -149,22 +151,30 @@ public class TestHttpRoute extends TestCase {
HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 }; HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 };
HttpRoute routefff = new HttpRoute(TARGET1, LOCAL41, chain3, HttpRoute routefff = new HttpRoute
false, false, false); (TARGET1, LOCAL41, chain3, false,
HttpRoute routefft = new HttpRoute(TARGET1, LOCAL41, chain3, TunnelType.PLAIN, LayerType.PLAIN);
false, false, true); HttpRoute routefft = new HttpRoute
HttpRoute routeftf = new HttpRoute(TARGET1, LOCAL41, chain3, (TARGET1, LOCAL41, chain3, false,
false, true, false); TunnelType.PLAIN, LayerType.LAYERED);
HttpRoute routeftt = new HttpRoute(TARGET1, LOCAL41, chain3, HttpRoute routeftf = new HttpRoute
false, true, true); (TARGET1, LOCAL41, chain3, false,
HttpRoute routetff = new HttpRoute(TARGET1, LOCAL41, chain3, TunnelType.TUNNELLED, LayerType.PLAIN);
true, false, false); HttpRoute routeftt = new HttpRoute
HttpRoute routetft = new HttpRoute(TARGET1, LOCAL41, chain3, (TARGET1, LOCAL41, chain3, false,
true, false, true); TunnelType.TUNNELLED, LayerType.LAYERED);
HttpRoute routettf = new HttpRoute(TARGET1, LOCAL41, chain3, HttpRoute routetff = new HttpRoute
true, true, false); (TARGET1, LOCAL41, chain3, true,
HttpRoute routettt = new HttpRoute(TARGET1, LOCAL41, chain3, TunnelType.PLAIN, LayerType.PLAIN);
true, true, true); HttpRoute routetft = new HttpRoute
(TARGET1, LOCAL41, chain3, true,
TunnelType.PLAIN, LayerType.LAYERED);
HttpRoute routettf = new HttpRoute
(TARGET1, LOCAL41, chain3, true,
TunnelType.TUNNELLED, LayerType.PLAIN);
HttpRoute routettt = new HttpRoute
(TARGET1, LOCAL41, chain3, true,
TunnelType.TUNNELLED, LayerType.LAYERED);
assertFalse("routefff.secure", routefff.isSecure()); assertFalse("routefff.secure", routefff.isSecure());
assertFalse("routefff.tunnel", routefff.isTunnelled()); assertFalse("routefff.tunnel", routefff.isTunnelled());
@ -244,21 +254,21 @@ public class TestHttpRoute extends TestCase {
HttpHost[] chain4 = { PROXY1, PROXY2, null, PROXY3 }; HttpHost[] chain4 = { PROXY1, PROXY2, null, PROXY3 };
// for reference: this one should succeed // for reference: this one should succeed
HttpRoute route = new HttpRoute(TARGET1, null, chain1, HttpRoute route = new HttpRoute(TARGET1, null, chain1, false,
false, true, false); TunnelType.TUNNELLED, LayerType.PLAIN);
assertNotNull(route); assertNotNull(route);
try { try {
route = new HttpRoute(null, null, chain1, route = new HttpRoute(null, null, chain1, false,
false, true, false); TunnelType.TUNNELLED, LayerType.PLAIN);
fail("missing target not detected"); fail("missing target not detected");
} catch (IllegalArgumentException iax) { } catch (IllegalArgumentException iax) {
// expected // expected
} }
try { try {
route = new HttpRoute(TARGET1, null, (HttpHost[]) null, route = new HttpRoute(TARGET1, null, (HttpHost[]) null, false,
false, true, false); TunnelType.TUNNELLED, LayerType.PLAIN);
fail("missing proxy for tunnel not detected"); fail("missing proxy for tunnel not detected");
} catch (IllegalArgumentException iax) { } catch (IllegalArgumentException iax) {
// expected // expected
@ -266,16 +276,16 @@ public class TestHttpRoute extends TestCase {
// for the next two, we don't indicate a tunnel anymore // for the next two, we don't indicate a tunnel anymore
try { try {
route = new HttpRoute(TARGET1, null, chain0, route = new HttpRoute(TARGET1, null, chain0, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
fail("invalid proxy chain (0) not detected"); fail("invalid proxy chain (0) not detected");
} catch (IllegalArgumentException iax) { } catch (IllegalArgumentException iax) {
// expected // expected
} }
try { try {
route = new HttpRoute(TARGET1, null, chain4, route = new HttpRoute(TARGET1, null, chain4, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
fail("invalid proxy chain (4) not detected"); fail("invalid proxy chain (4) not detected");
} catch (IllegalArgumentException iax) { } catch (IllegalArgumentException iax) {
// expected // expected
@ -283,6 +293,22 @@ public class TestHttpRoute extends TestCase {
} }
public void testNullEnums() {
// tests the default values for the enum parameters
// also covers the accessors for the enum attributes
HttpRoute route = new HttpRoute(TARGET1, null, PROXY1, false,
null, null); // here are defaults
assertFalse("default tunnelling", route.isTunnelled());
assertEquals("untunnelled", TunnelType.PLAIN, route.getTunnelType());
assertFalse("default layering", route.isLayered());
assertEquals("unlayered", LayerType.PLAIN, route.getLayerType());
}
public void testEqualsHashcodeClone() throws CloneNotSupportedException { public void testEqualsHashcodeClone() throws CloneNotSupportedException {
HttpHost[] chain0 = { }; HttpHost[] chain0 = { };
HttpHost[] chain1 = { PROXY1 }; HttpHost[] chain1 = { PROXY1 };
@ -290,10 +316,10 @@ public class TestHttpRoute extends TestCase {
HttpHost[] chain4 = { PROXY1, PROXY3, PROXY2 }; HttpHost[] chain4 = { PROXY1, PROXY3, PROXY2 };
// create some identical routes // create some identical routes
HttpRoute route1a = new HttpRoute(TARGET1, LOCAL41, chain3, HttpRoute route1a = new HttpRoute(TARGET1, LOCAL41, chain3, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route1b = new HttpRoute(TARGET1, LOCAL41, chain3, HttpRoute route1b = new HttpRoute(TARGET1, LOCAL41, chain3, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route1c = (HttpRoute) route1a.clone(); HttpRoute route1c = (HttpRoute) route1a.clone();
assertEquals("1a 1a", route1a, route1a); assertEquals("1a 1a", route1a, route1a);
@ -309,28 +335,29 @@ public class TestHttpRoute extends TestCase {
assertEquals("toString 1c", route1a.toString(), route1c.toString()); assertEquals("toString 1c", route1a.toString(), route1c.toString());
// now create some differing routes // now create some differing routes
HttpRoute route2a = new HttpRoute(TARGET2, LOCAL41, chain3, HttpRoute route2a = new HttpRoute(TARGET2, LOCAL41, chain3, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route2b = new HttpRoute(TARGET1, LOCAL42, chain3, HttpRoute route2b = new HttpRoute(TARGET1, LOCAL42, chain3, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route2c = new HttpRoute(TARGET1, LOCAL61, chain3, HttpRoute route2c = new HttpRoute(TARGET1, LOCAL61, chain3, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route2d = new HttpRoute(TARGET1, null, chain3, HttpRoute route2d = new HttpRoute(TARGET1, null, chain3, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route2e = new HttpRoute(TARGET1, LOCAL41, (HttpHost[]) null, HttpRoute route2e = new HttpRoute(TARGET1, LOCAL41, (HttpHost[]) null,
false, false, false); false,
HttpRoute route2f = new HttpRoute(TARGET1, LOCAL41, chain0, TunnelType.PLAIN, LayerType.PLAIN);
false, false, false); HttpRoute route2f = new HttpRoute(TARGET1, LOCAL41, chain0, false,
HttpRoute route2g = new HttpRoute(TARGET1, LOCAL41, chain1, TunnelType.PLAIN, LayerType.PLAIN);
false, false, false); HttpRoute route2g = new HttpRoute(TARGET1, LOCAL41, chain1, false,
HttpRoute route2h = new HttpRoute(TARGET1, LOCAL41, chain4, TunnelType.PLAIN, LayerType.PLAIN);
false, false, false); HttpRoute route2h = new HttpRoute(TARGET1, LOCAL41, chain4, false,
HttpRoute route2i = new HttpRoute(TARGET1, LOCAL41, chain3, TunnelType.PLAIN, LayerType.PLAIN);
true, false, false); HttpRoute route2i = new HttpRoute(TARGET1, LOCAL41, chain3, true,
HttpRoute route2j = new HttpRoute(TARGET1, LOCAL41, chain3, TunnelType.PLAIN, LayerType.PLAIN);
false, true, false); HttpRoute route2j = new HttpRoute(TARGET1, LOCAL41, chain3, false,
HttpRoute route2k = new HttpRoute(TARGET1, LOCAL41, chain3, TunnelType.TUNNELLED, LayerType.PLAIN);
false, false, true); HttpRoute route2k = new HttpRoute(TARGET1, LOCAL41, chain3, false,
TunnelType.PLAIN, LayerType.LAYERED);
// check a special case first: 2f should be the same as 2e // check a special case first: 2f should be the same as 2e
assertEquals("2e 2f", route2e, route2f); assertEquals("2e 2f", route2e, route2f);
@ -441,8 +468,8 @@ public class TestHttpRoute extends TestCase {
public void testHopping() { public void testHopping() {
// test getHopCount() and getHopTarget() with different proxy chains // test getHopCount() and getHopTarget() with different proxy chains
HttpHost[] proxies = null; HttpHost[] proxies = null;
HttpRoute route = new HttpRoute(TARGET1, null, proxies, HttpRoute route = new HttpRoute(TARGET1, null, proxies, true,
true, false, false); TunnelType.PLAIN, LayerType.PLAIN);
assertEquals("A: hop count", 1, route.getHopCount()); assertEquals("A: hop count", 1, route.getHopCount());
assertEquals("A: hop 0", TARGET1, route.getHopTarget(0)); assertEquals("A: hop 0", TARGET1, route.getHopTarget(0));
try { try {
@ -460,8 +487,8 @@ public class TestHttpRoute extends TestCase {
proxies = new HttpHost[]{ PROXY3 }; proxies = new HttpHost[]{ PROXY3 };
route = new HttpRoute(TARGET1, LOCAL62, proxies, route = new HttpRoute(TARGET1, LOCAL62, proxies, false,
false, true, false); TunnelType.TUNNELLED, LayerType.PLAIN);
assertEquals("B: hop count", 2, route.getHopCount()); assertEquals("B: hop count", 2, route.getHopCount());
assertEquals("B: hop 0", PROXY3, route.getHopTarget(0)); assertEquals("B: hop 0", PROXY3, route.getHopTarget(0));
assertEquals("B: hop 1", TARGET1, route.getHopTarget(1)); assertEquals("B: hop 1", TARGET1, route.getHopTarget(1));
@ -480,8 +507,8 @@ public class TestHttpRoute extends TestCase {
proxies = new HttpHost[]{ PROXY3, PROXY1, PROXY2 }; proxies = new HttpHost[]{ PROXY3, PROXY1, PROXY2 };
route = new HttpRoute(TARGET1, LOCAL42, proxies, route = new HttpRoute(TARGET1, LOCAL42, proxies, false,
false, false, true); TunnelType.PLAIN, LayerType.LAYERED);
assertEquals("C: hop count", 4, route.getHopCount()); assertEquals("C: hop count", 4, route.getHopCount());
assertEquals("C: hop 0", PROXY3 , route.getHopTarget(0)); assertEquals("C: hop 0", PROXY3 , route.getHopTarget(0));
assertEquals("C: hop 1", PROXY1 , route.getHopTarget(1)); assertEquals("C: hop 1", PROXY1 , route.getHopTarget(1));
@ -504,8 +531,9 @@ public class TestHttpRoute extends TestCase {
public void testCstr1() { public void testCstr1() {
HttpRoute route = new HttpRoute(TARGET2); HttpRoute route = new HttpRoute(TARGET2);
HttpRoute should = new HttpRoute(TARGET2, null, (HttpHost[]) null, HttpRoute should = new HttpRoute
false, false, false); (TARGET2, null, (HttpHost[]) null, false,
TunnelType.PLAIN, LayerType.PLAIN);
assertEquals("bad convenience route", route, should); assertEquals("bad convenience route", route, should);
} }
@ -513,13 +541,14 @@ public class TestHttpRoute extends TestCase {
public void testCstr3() { public void testCstr3() {
// test convenience constructor with 3 arguments // test convenience constructor with 3 arguments
HttpRoute route = new HttpRoute(TARGET2, LOCAL61, false); HttpRoute route = new HttpRoute(TARGET2, LOCAL61, false);
HttpRoute should = new HttpRoute(TARGET2, LOCAL61, (HttpHost[]) null, HttpRoute should = new HttpRoute
false, false, false); (TARGET2, LOCAL61, (HttpHost[]) null, false,
TunnelType.PLAIN, LayerType.PLAIN);
assertEquals("bad convenience route 3/insecure", route, should); assertEquals("bad convenience route 3/insecure", route, should);
route = new HttpRoute(TARGET2, null, true); route = new HttpRoute(TARGET2, null, true);
should = new HttpRoute(TARGET2, null, (HttpHost[]) null, should = new HttpRoute(TARGET2, null, (HttpHost[]) null, true,
true, false, false); TunnelType.PLAIN, LayerType.PLAIN);
assertEquals("bad convenience route 3/secure", route, should); assertEquals("bad convenience route 3/secure", route, should);
} }
@ -528,12 +557,14 @@ public class TestHttpRoute extends TestCase {
// test convenience constructor with 4 arguments // test convenience constructor with 4 arguments
HttpRoute route = new HttpRoute(TARGET2, null, PROXY2, false); HttpRoute route = new HttpRoute(TARGET2, null, PROXY2, false);
HttpRoute should = new HttpRoute HttpRoute should = new HttpRoute
(TARGET2, null, new HttpHost[]{ PROXY2 }, false, false, false); (TARGET2, null, new HttpHost[]{ PROXY2 }, false,
TunnelType.PLAIN, LayerType.PLAIN);
assertEquals("bad convenience route 4/insecure", route, should); assertEquals("bad convenience route 4/insecure", route, should);
route = new HttpRoute(TARGET2, LOCAL42, PROXY1, true); route = new HttpRoute(TARGET2, LOCAL42, PROXY1, true);
should = new HttpRoute should = new HttpRoute
(TARGET2, LOCAL42, new HttpHost[]{ PROXY1 }, true, true, true); (TARGET2, LOCAL42, new HttpHost[]{ PROXY1 }, true,
TunnelType.TUNNELLED, LayerType.LAYERED);
assertEquals("bad convenience route 4/secure", route, should); assertEquals("bad convenience route 4/secure", route, should);
// this constructor REQUIRES a proxy to be specified // this constructor REQUIRES a proxy to be specified
@ -549,15 +580,19 @@ public class TestHttpRoute extends TestCase {
public void testCstr6() { public void testCstr6() {
// test convenience constructor with 6 arguments // test convenience constructor with 6 arguments
HttpRoute route = new HttpRoute HttpRoute route = new HttpRoute
(TARGET2, null, PROXY2, true, true, false); (TARGET2, null, PROXY2, true,
TunnelType.TUNNELLED, LayerType.PLAIN);
HttpRoute should = new HttpRoute HttpRoute should = new HttpRoute
(TARGET2, null, new HttpHost[]{ PROXY2 }, true, true, false); (TARGET2, null, new HttpHost[]{ PROXY2 }, true,
TunnelType.TUNNELLED, LayerType.PLAIN);
assertEquals("bad convenience route 6/proxied", route, should); assertEquals("bad convenience route 6/proxied", route, should);
route = new HttpRoute route = new HttpRoute
(TARGET2, null, (HttpHost) null, true, false, true); (TARGET2, null, (HttpHost) null, true,
TunnelType.PLAIN, LayerType.LAYERED);
should = new HttpRoute should = new HttpRoute
(TARGET2, null, (HttpHost[]) null, true, false, true); (TARGET2, null, (HttpHost[]) null, true,
TunnelType.PLAIN, LayerType.LAYERED);
assertEquals("bad convenience route 6/direct", route, should); assertEquals("bad convenience route 6/direct", route, should);
// handling of null vs. empty chain is checked in the equals tests // handling of null vs. empty chain is checked in the equals tests
@ -567,12 +602,12 @@ public class TestHttpRoute extends TestCase {
public void testImmutable() throws CloneNotSupportedException { public void testImmutable() throws CloneNotSupportedException {
HttpHost[] proxies = new HttpHost[]{ PROXY1, PROXY2, PROXY3 }; HttpHost[] proxies = new HttpHost[]{ PROXY1, PROXY2, PROXY3 };
HttpRoute route1 = new HttpRoute(TARGET1, null, proxies, HttpRoute route1 = new HttpRoute(TARGET1, null, proxies, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route2 = (HttpRoute) route1.clone(); HttpRoute route2 = (HttpRoute) route1.clone();
HttpRoute route3 = new HttpRoute(TARGET1, null, HttpRoute route3 = new HttpRoute(TARGET1, null,
(HttpHost[]) proxies.clone(), (HttpHost[]) proxies.clone(), false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
// modify the array that was passed to the constructor of route1 // modify the array that was passed to the constructor of route1
proxies[1] = PROXY3; proxies[1] = PROXY3;

View File

@ -38,6 +38,8 @@ import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.conn.HttpRoute.TunnelType;
import org.apache.http.conn.HttpRoute.LayerType;
/** /**
@ -199,14 +201,14 @@ public class TestRouteDirector extends TestCase {
HttpHost[] chainC = { PROXY2, PROXY1 }; HttpHost[] chainC = { PROXY2, PROXY1 };
HttpRouteDirector rowdy = new BasicRouteDirector(); HttpRouteDirector rowdy = new BasicRouteDirector();
HttpRoute route1cA = new HttpRoute(TARGET1, null, chainA, HttpRoute route1cA = new HttpRoute(TARGET1, null, chainA, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route1cB = new HttpRoute(TARGET1, null, chainB, HttpRoute route1cB = new HttpRoute(TARGET1, null, chainB, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route1cC = new HttpRoute(TARGET1, null, chainC, HttpRoute route1cC = new HttpRoute(TARGET1, null, chainC, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
HttpRoute route1cD = new HttpRoute(TARGET1, null, chainC, HttpRoute route1cD = new HttpRoute(TARGET1, null, chainC, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
int step = rowdy.nextStep(route1cA, null); int step = rowdy.nextStep(route1cA, null);
assertEquals("wrong step to route1cA", assertEquals("wrong step to route1cA",

View File

@ -40,6 +40,8 @@ import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.conn.HttpRoute.TunnelType;
import org.apache.http.conn.HttpRoute.LayerType;
/** /**
@ -330,13 +332,15 @@ public class TestRouteTracker extends TestCase {
assertTrue("incomplete route 1", complete); assertTrue("incomplete route 1", complete);
// tunnelled, but neither secure nor layered // tunnelled, but neither secure nor layered
r = new HttpRoute(TARGET1, LOCAL61, PROXY3, false, true, false); r = new HttpRoute(TARGET1, LOCAL61, PROXY3, false,
TunnelType.TUNNELLED, LayerType.PLAIN);
rt = new RouteTracker(r); rt = new RouteTracker(r);
complete = checkVia(rt, r, rd, 3); complete = checkVia(rt, r, rd, 3);
assertTrue("incomplete route 2", complete); assertTrue("incomplete route 2", complete);
// tunnelled, layered, but not secure // tunnelled, layered, but not secure
r = new HttpRoute(TARGET1, LOCAL61, PROXY3, false, true, true); r = new HttpRoute(TARGET1, LOCAL61, PROXY3, false,
TunnelType.TUNNELLED, LayerType.LAYERED);
rt = new RouteTracker(r); rt = new RouteTracker(r);
complete = checkVia(rt, r, rd, 4); complete = checkVia(rt, r, rd, 4);
assertTrue("incomplete route 3", complete); assertTrue("incomplete route 3", complete);
@ -353,29 +357,32 @@ public class TestRouteTracker extends TestCase {
final HttpRouteDirector rd = new BasicRouteDirector(); final HttpRouteDirector rd = new BasicRouteDirector();
HttpHost[] proxies = { PROXY1, PROXY2 }; HttpHost[] proxies = { PROXY1, PROXY2 };
HttpRoute r = new HttpRoute(TARGET2, LOCAL42, proxies, HttpRoute r = new HttpRoute(TARGET2, LOCAL42, proxies, false,
false, false, false); TunnelType.PLAIN, LayerType.PLAIN);
RouteTracker rt = new RouteTracker(r); RouteTracker rt = new RouteTracker(r);
boolean complete = checkVia(rt, r, rd, 3); boolean complete = checkVia(rt, r, rd, 3);
assertTrue("incomplete route 1", complete); assertTrue("incomplete route 1", complete);
// tunnelled, but neither secure nor layered // tunnelled, but neither secure nor layered
proxies = new HttpHost[]{ PROXY3, PROXY2 }; proxies = new HttpHost[]{ PROXY3, PROXY2 };
r = new HttpRoute(TARGET1, null, proxies, false, true, false); r = new HttpRoute(TARGET1, null, proxies, false,
TunnelType.TUNNELLED, LayerType.PLAIN);
rt = new RouteTracker(r); rt = new RouteTracker(r);
complete = checkVia(rt, r, rd, 4); complete = checkVia(rt, r, rd, 4);
assertTrue("incomplete route 2", complete); assertTrue("incomplete route 2", complete);
// tunnelled, layered, but not secure // tunnelled, layered, but not secure
proxies = new HttpHost[]{ PROXY3, PROXY2, PROXY1 }; proxies = new HttpHost[]{ PROXY3, PROXY2, PROXY1 };
r = new HttpRoute(TARGET2, LOCAL61, proxies, false, true, true); r = new HttpRoute(TARGET2, LOCAL61, proxies, false,
TunnelType.TUNNELLED, LayerType.LAYERED);
rt = new RouteTracker(r); rt = new RouteTracker(r);
complete = checkVia(rt, r, rd, 6); complete = checkVia(rt, r, rd, 6);
assertTrue("incomplete route 3", complete); assertTrue("incomplete route 3", complete);
// tunnelled, layered, secure // tunnelled, layered, secure
proxies = new HttpHost[]{ PROXY1, PROXY3 }; proxies = new HttpHost[]{ PROXY1, PROXY3 };
r = new HttpRoute(TARGET1, LOCAL61, proxies, true, true, true); r = new HttpRoute(TARGET1, LOCAL61, proxies, true,
TunnelType.TUNNELLED, LayerType.LAYERED);
rt = new RouteTracker(r); rt = new RouteTracker(r);
complete = checkVia(rt, r, rd, 5); complete = checkVia(rt, r, rd, 5);
assertTrue("incomplete route 4", complete); assertTrue("incomplete route 4", complete);