Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpFilterInterceptor Add Test-cases #74

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public final void doFilter(ServletRequest request, ServletResponse response,
* @param request The ServletRequest object containing the client's request
* @return The real IP address of the client
*/
private String getClientIp(ServletRequest request) {
protected String getClientIp(ServletRequest request) {
String remoteAddr = request.getRemoteAddr();
String xForwardedFor = ((HttpServletRequest) request).getHeader("X-Forwarded-For");
if (xForwardedFor != null) {
Expand All @@ -118,7 +118,7 @@ private String getClientIp(ServletRequest request) {
return remoteAddr;
}

private List<HttpFilter> getMatchingFilters(String path) {
protected List<HttpFilter> getMatchingFilters(String path) {
return pathSpecToFilterMap.keySet().stream().filter(key -> key.matches(path))
.map(k-> pathSpecToFilterMap.get(k)).flatMap(List::stream)
.map(filter -> filter.getInstance()).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class HttpFilterInterceptorTest {

private HttpFilterInterceptor interceptor;
String pathSpec = "/test/*";

@Before
public void setUp() {
Expand All @@ -27,13 +28,13 @@ public void setUp() {

@Test
public void registerFiltersAddsFiltersToMap() {
String pathSpec = "/test/*";
List<HttpFilter> filters = new ArrayList<>();
filters.add(new AccessLogHttpFilter());
assertEquals(1, filters.size());
List<HttpFilterParams> httpFilterParamsList = new ArrayList<>();
httpFilterParamsList.add(HttpFilterParams.builder().pathSpec(pathSpec).filter(new AccessLogHttpFilter()).build());
interceptor.registerFilters(httpFilterParamsList);
assertEquals(1, interceptor.getMatchingFilters("/test/path").size());
}

@Test
Expand Down
Loading