HttpRoute route = new HttpRoute(TARGET1, null, proxies, true,
TunnelType.PLAIN, LayerType.PLAIN);
assertEquals("A: hop count", 1, route.getHopCount());
assertEquals("A: hop 0", TARGET1, route.getHopTarget(0));
try {
HttpHost beyond = route.getHopTarget(1);
fail("A: hop 1 is " + beyond);
} catch (IllegalArgumentException iax) {
// expected
}
try {
HttpHost before = route.getHopTarget(-1);
fail("A: hop -1 is " + before);
} catch (IllegalArgumentException iax) {
// expected
}
proxies = new HttpHost[]{ PROXY3 };
route = new HttpRoute(TARGET1, LOCAL62, proxies, false,
TunnelType.TUNNELLED, LayerType.PLAIN);
assertEquals("B: hop count", 2, route.getHopCount());
assertEquals("B: hop 0", PROXY3, route.getHopTarget(0));
assertEquals("B: hop 1", TARGET1, route.getHopTarget(1));
try {
HttpHost beyond = route.getHopTarget(2);
fail("B: hop 2 is " + beyond);
} catch (IllegalArgumentException iax) {
// expected
}
try {
HttpHost before = route.getHopTarget(-2);
fail("B: hop -2 is " + before);
} catch (IllegalArgumentException iax) {
// expected
}
proxies = new HttpHost[]{ PROXY3, PROXY1, PROXY2 };
route = new HttpRoute(TARGET1, LOCAL42, proxies, false,
TunnelType.PLAIN, LayerType.LAYERED);
assertEquals("C: hop count", 4, route.getHopCount());
assertEquals("C: hop 0", PROXY3 , route.getHopTarget(0));
assertEquals("C: hop 1", PROXY1 , route.getHopTarget(1));
assertEquals("C: hop 2", PROXY2 , route.getHopTarget(2));
assertEquals("C: hop 3", TARGET1, route.getHopTarget(3));
try {
HttpHost beyond = route.getHopTarget(4);
fail("C: hop 4 is " + beyond);
} catch (IllegalArgumentException iax) {
// expected
}
try {
HttpHost before = route.getHopTarget(Integer.MIN_VALUE);
fail("C: hop -<min> is " + before);
} catch (IllegalArgumentException iax) {
// expected
}
}