Search in sources :

Example 16 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestRequest method localeParsePerformance.

@Test
@Ignore("Used to check performance of different parsing approaches")
public void localeParsePerformance() throws Exception {
    TesterRequest req = new TesterRequest();
    req.addHeader("accept-encoding", "en-gb,en");
    long start = System.nanoTime();
    // Takes about 0.3s on a quad core 2.7Ghz 2013 MacBook
    for (int i = 0; i < 10000000; i++) {
        req.parseLocales();
        req.localesParsed = false;
        req.locales.clear();
    }
    long time = System.nanoTime() - start;
    System.out.println(time);
}
Also used : TesterRequest(org.apache.tomcat.unittest.TesterRequest) Ignore(org.junit.Ignore) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 17 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponse method doTestEncodeURL.

private void doTestEncodeURL(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.encodeURL(location);
    Assert.assertEquals(expected, result);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) TesterRequest(org.apache.tomcat.unittest.TesterRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest)

Example 18 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponse method testBug53062o.

@Test
public void testBug53062o() throws Exception {
    Request req = new TesterRequest();
    Response resp = new Response();
    resp.setRequest(req);
    String result = resp.toAbsolute("./..#/../../");
    Assert.assertEquals("http://localhost:8080/level1/#/../../", result);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) TesterRequest(org.apache.tomcat.unittest.TesterRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 19 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponse method testBug53062h.

@Test
public void testBug53062h() throws Exception {
    Request req = new TesterRequest();
    Response resp = new Response();
    resp.setRequest(req);
    String result = resp.toAbsolute("bar.html?x=/../../");
    Assert.assertEquals("http://localhost:8080/level1/level2/bar.html?x=/../../", result);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) TesterRequest(org.apache.tomcat.unittest.TesterRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 20 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponse method testBug53062b.

@Test
public void testBug53062b() 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);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) TesterRequest(org.apache.tomcat.unittest.TesterRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

TesterRequest (org.apache.tomcat.unittest.TesterRequest)26 Test (org.junit.Test)24 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)20 Locale (java.util.Locale)2 TesterContext (org.apache.tomcat.unittest.TesterContext)2 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ServletSecurityElement (javax.servlet.ServletSecurityElement)1 ServletSecurity (javax.servlet.annotation.ServletSecurity)1 Context (org.apache.catalina.Context)1 Request (org.apache.catalina.connector.Request)1 Response (org.apache.catalina.connector.Response)1 LoggingBaseTest (org.apache.catalina.startup.LoggingBaseTest)1 TesterMapRealm (org.apache.catalina.startup.TesterMapRealm)1 TesterResponse (org.apache.tomcat.unittest.TesterResponse)1 TesterServletContext (org.apache.tomcat.unittest.TesterServletContext)1 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)1