org.apache.tomcat.unittest.TesterResponse Java Examples

The following examples show how to use org.apache.tomcat.unittest.TesterResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRemoteIpFilter.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private MockFilterChain testRemoteIpFilter(FilterDef filterDef, Request request)
        throws LifecycleException, IOException, ServletException {
    Tomcat tomcat = getTomcatInstance();
    Context root = tomcat.addContext("", TEMP_DIR);

    RemoteIpFilter remoteIpFilter = new RemoteIpFilter();
    filterDef.setFilterClass(RemoteIpFilter.class.getName());
    filterDef.setFilter(remoteIpFilter);
    filterDef.setFilterName(RemoteIpFilter.class.getName());
    root.addFilterDef(filterDef);

    FilterMap filterMap = new FilterMap();
    filterMap.setFilterName(RemoteIpFilter.class.getName());
    filterMap.addURLPatternDecoded("*");
    root.addFilterMap(filterMap);

    getTomcatInstance().start();

    MockFilterChain filterChain = new MockFilterChain();

    // TEST
    TesterResponse response = new TesterResponse();
    response.setRequest(request);
    remoteIpFilter.doFilter(request, response, filterChain);
    return filterChain;
}
 
Example #2
Source File: TestRemoteIpFilter.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private MockFilterChain testRemoteIpFilter(FilterDef filterDef, Request request)
        throws LifecycleException, IOException, ServletException {
    Tomcat tomcat = getTomcatInstance();
    Context root = tomcat.addContext("", TEMP_DIR);

    RemoteIpFilter remoteIpFilter = new RemoteIpFilter();
    filterDef.setFilterClass(RemoteIpFilter.class.getName());
    filterDef.setFilter(remoteIpFilter);
    filterDef.setFilterName(RemoteIpFilter.class.getName());
    root.addFilterDef(filterDef);

    FilterMap filterMap = new FilterMap();
    filterMap.setFilterName(RemoteIpFilter.class.getName());
    filterMap.addURLPattern("*");
    root.addFilterMap(filterMap);

    getTomcatInstance().start();

    MockFilterChain filterChain = new MockFilterChain();

    // TEST
    TesterResponse response = new TesterResponse();
    response.setRequest(request);
    remoteIpFilter.doFilter(request, response, filterChain);
    return filterChain;
}
 
Example #3
Source File: TestRemoteIpFilter.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private MockFilterChain testRemoteIpFilter(FilterDef filterDef, Request request)
        throws LifecycleException, IOException, ServletException {
    Tomcat tomcat = getTomcatInstance();
    Context root = tomcat.addContext("", TEMP_DIR);

    RemoteIpFilter remoteIpFilter = new RemoteIpFilter();
    filterDef.setFilterClass(RemoteIpFilter.class.getName());
    filterDef.setFilter(remoteIpFilter);
    filterDef.setFilterName(RemoteIpFilter.class.getName());
    root.addFilterDef(filterDef);

    FilterMap filterMap = new FilterMap();
    filterMap.setFilterName(RemoteIpFilter.class.getName());
    filterMap.addURLPattern("*");
    root.addFilterMap(filterMap);

    getTomcatInstance().start();

    MockFilterChain filterChain = new MockFilterChain();

    // TEST
    TesterResponse response = new TesterResponse();
    response.setRequest(request);
    remoteIpFilter.doFilter(request, response, filterChain);
    return filterChain;
}
 
Example #4
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithAll() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "host");
    Set<String> expected = new HashSet<>();
    expected.add("*");
    doTestAddVaryFieldName(response, "*", expected);
}
 
Example #5
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddAllWithAll() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "*");
    Set<String> expected = new HashSet<>();
    expected.add("*");
    doTestAddVaryFieldName(response, "*", expected);
}
 
Example #6
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddAllWithNone() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    Set<String> expected = new HashSet<>();
    expected.add("*");
    doTestAddVaryFieldName(response, "*", expected);
}
 
Example #7
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithValidSingleHeader() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "foo, bar");
    Set<String> expected = new HashSet<>();
    expected.add("bar");
    expected.add("foo");
    expected.add("too");
    doTestAddVaryFieldName(response, "too", expected);
}
 
Example #8
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithValidSingleHeaderIncludingAll() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "foo, *");
    Set<String> expected = new HashSet<>();
    expected.add("*");
    doTestAddVaryFieldName(response, "too", expected);
}
 
Example #9
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithValidSingleHeaderAlreadyPresent() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "foo, bar");
    Set<String> expected = new HashSet<>();
    expected.add("bar");
    expected.add("foo");
    doTestAddVaryFieldName(response, "foo", expected);
}
 
Example #10
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithValidHeaders() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "foo");
    response.addHeader("vary", "bar");
    Set<String> expected = new HashSet<>();
    expected.add("bar");
    expected.add("foo");
    expected.add("too");
    doTestAddVaryFieldName(response, "too", expected);
}
 
Example #11
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithValidHeadersIncludingAll() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "foo");
    response.addHeader("vary", "*");
    Set<String> expected = new HashSet<>();
    expected.add("*");
    doTestAddVaryFieldName(response, "too", expected);
}
 
Example #12
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithValidHeadersAlreadyPresent() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "foo");
    response.addHeader("vary", "bar");
    Set<String> expected = new HashSet<>();
    expected.add("bar");
    expected.add("foo");
    doTestAddVaryFieldName(response, "foo", expected);
}
 
Example #13
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithPartiallyValidSingleHeader() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "{{{, bar");
    Set<String> expected = new HashSet<>();
    expected.add("bar");
    expected.add("too");
    doTestAddVaryFieldName(response, "too", expected);
}
 
Example #14
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithPartiallyValidSingleHeaderIncludingAll() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "{{{, *");
    Set<String> expected = new HashSet<>();
    expected.add("*");
    doTestAddVaryFieldName(response, "too", expected);
}
 
Example #15
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAddValidWithPartiallyValidSingleHeaderAlreadyPresent() {
    TesterResponse response = new TesterResponse();
    response.getCoyoteResponse();
    response.addHeader("vary", "{{{, bar");
    Set<String> expected = new HashSet<>();
    expected.add("bar");
    doTestAddVaryFieldName(response, "bar", expected);
}
 
Example #16
Source File: TestResponseUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private void doTestAddVaryFieldName(TesterResponse response, String fieldName,
        Set<String> expected) {
    ResponseUtil.addVaryFieldName(response, fieldName);
    // There will now only be one Vary header
    String resultHeader = response.getHeader("vary");
    Set<String> result = new HashSet<>();
    // Deliberately do not use Vary.parseVary as it will skip invalid values.
    for (String value : resultHeader.split(",")) {
        result.add(value.trim());
    }
    Assert.assertEquals(expected, result);
}