use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.
the class MasterServletFilter method initFilters.
public void initFilters(List<ServletFilter> filterExtensions) throws ServletException {
List<ServletFilter> filterList = Lists.newArrayList();
for (ServletFilter extension : filterExtensions) {
try {
Loggers.get(MasterServletFilter.class).info(String.format("Initializing servlet filter %s [pattern=%s]", extension, extension.doGetPattern()));
extension.init(config);
filterList.add(extension);
} catch (Exception e) {
throw new IllegalStateException("Fail to initialize servlet filter: " + extension + ". Message: " + e.getMessage(), e);
}
}
filters = filterList.toArray(new ServletFilter[filterList.size()]);
}
use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.
the class MasterServletFilterTest method should_init_and_destroy_filters.
@Test
public void should_init_and_destroy_filters() throws Exception {
ServletFilter filter = mock(ServletFilter.class);
FilterConfig config = mock(FilterConfig.class);
MasterServletFilter master = new MasterServletFilter();
master.init(config, singletonList(filter));
assertThat(master.getFilters()).containsOnly(filter);
verify(filter).init(config);
master.destroy();
verify(filter).destroy();
}
use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.
the class MasterServletFilterTest method should_propagate_initialization_failure.
@Test
public void should_propagate_initialization_failure() throws Exception {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("foo");
ServletFilter filter = mock(ServletFilter.class);
doThrow(new IllegalStateException("foo")).when(filter).init(any(FilterConfig.class));
FilterConfig config = mock(FilterConfig.class);
MasterServletFilter filters = new MasterServletFilter();
filters.init(config, singletonList(filter));
}
use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.
the class RegisterServletFiltersTest method should_not_fail_if_master_filter_is_not_up.
@Test
public void should_not_fail_if_master_filter_is_not_up() throws ServletException {
MasterServletFilter.INSTANCE = null;
new RegisterServletFilters(new ServletFilter[2]).start();
}
use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.
the class RegisterServletFiltersTest method should_register_filters_if_master_filter_is_up.
@Test
public void should_register_filters_if_master_filter_is_up() throws ServletException {
MasterServletFilter.INSTANCE = mock(MasterServletFilter.class);
new RegisterServletFilters(new ServletFilter[2]).start();
verify(MasterServletFilter.INSTANCE).initFilters(anyListOf(ServletFilter.class));
}
Aggregations