aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-02-19 18:28:21 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-02-19 18:42:42 +0100
commit435f1f3d84e6cccc93e23bcfc5ffddcc11c58052 (patch)
tree4719a89c4d23462892a6c5ebc61bfe0be303e7a6 /sonar-plugin-api
parentaf889ca2b58207363b2d48044df6895dd7252d7a (diff)
downloadsonarqube-435f1f3d84e6cccc93e23bcfc5ffddcc11c58052.tar.gz
sonarqube-435f1f3d84e6cccc93e23bcfc5ffddcc11c58052.zip
SONAR-3612 Custom servlet filters are not loaded after database upgrade
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java60
2 files changed, 60 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java
index a7a486dc9ef..a7aa641167e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.web;
-import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.sonar.api.ServerExtension;
@@ -29,7 +28,6 @@ import javax.servlet.Filter;
/**
* @since 3.1
*/
-@Beta
public abstract class ServletFilter implements ServerExtension, Filter {
/**
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java
index 398cbb6d247..f5e0f999c3e 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java
@@ -19,16 +19,30 @@
*/
package org.sonar.api.web;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import java.io.IOException;
import static org.fest.assertions.Assertions.assertThat;
public class ServletFilterTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
public void matchAll() {
ServletFilter.UrlPattern pattern = ServletFilter.UrlPattern.create("/*");
assertThat(pattern.matches("/")).isTrue();
assertThat(pattern.matches("/foo/ooo")).isTrue();
+ assertThat(pattern.toString()).isEqualTo("/*");
}
@Test
@@ -58,4 +72,50 @@ public class ServletFilterTest {
assertThat(pattern.matches("/foo/")).isFalse();
assertThat(pattern.matches("/bar")).isFalse();
}
+
+ @Test
+ public void url_pattern_cant_be_empty() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Empty url");
+ ServletFilter.UrlPattern.create("");
+ }
+
+ @Test
+ public void filter_should_return_url_pattern() {
+ ServletFilter filter = new FakeFilter();
+ assertThat(filter.doGetPattern().getUrl()).isEqualTo("/fake");
+ }
+
+ @Test
+ public void filter_should_apply_to_all_urls_by_default() {
+ ServletFilter filter = new DefaultFilter();
+ assertThat(filter.doGetPattern().getUrl()).isEqualTo("/*");
+ }
+
+ static class FakeFilter extends ServletFilter {
+ @Override
+ public UrlPattern doGetPattern() {
+ return UrlPattern.create("/fake");
+ }
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ }
+
+ public void destroy() {
+ }
+ }
+
+ static class DefaultFilter extends ServletFilter {
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ }
+
+ public void destroy() {
+ }
+ }
}