use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.
the class TestResponse method doTestEncodeRedirectURL.
private void doTestEncodeRedirectURL(String location, String expected) {
Request req = new TesterRequest(true);
req.setRequestedSessionId("1234");
req.setRequestedSessionURL(true);
Response resp = new Response();
resp.setRequest(req);
String result = resp.encodeRedirectURL(location);
Assert.assertEquals(expected, result);
}
use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.
the class TestResponse method testBug53062n.
@Test
public void testBug53062n() throws Exception {
Request req = new TesterRequest();
Response resp = new Response();
resp.setRequest(req);
String result = resp.toAbsolute("./.#/../../");
Assert.assertEquals("http://localhost:8080/level1/level2/#/../../", result);
}
use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.
the class TestResponse method testBug53469a.
@Test
public void testBug53469a() throws Exception {
Request req = new TesterRequest();
Response resp = new Response();
resp.setRequest(req);
String result = resp.encodeURL("../bar.html");
Assert.assertEquals("../bar.html", result);
}
use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.
the class TestResponse method testBug53062e.
@Test(expected = IllegalArgumentException.class)
public void testBug53062e() throws Exception {
Request req = new TesterRequest();
Response resp = new Response();
resp.setRequest(req);
resp.toAbsolute("../../..");
}
use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.
the class TestResponsePerformance method testToAbsolutePerformance.
@Test
public void testToAbsolutePerformance() throws Exception {
Request req = new TesterRequest();
Response resp = new Response();
resp.setRequest(req);
// Warm up
doHomebrew(resp);
doUri();
// Note: Java 9 on my OSX laptop consistently shows doUri() is faster
// than doHomebrew(). Worth a closer look for Tomcat 10 on the
// assumption it will require java 9
// To allow for timing differences between runs, a "best of n" approach
// is taken for this test
final int bestOf = 5;
final int winTarget = (bestOf + 1) / 2;
int homebrewWin = 0;
int count = 0;
while (count < bestOf && homebrewWin < winTarget) {
long homebrew = doHomebrew(resp);
long uri = doUri();
log.info("Current 'home-brew': " + homebrew + "ms, Using URI: " + uri + "ms");
if (homebrew < uri) {
homebrewWin++;
}
count++;
}
Assert.assertTrue(homebrewWin == winTarget);
}
Aggregations