aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-04-03 09:57:03 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-04-17 15:14:59 +0200
commite0df5f6bcb786d58fb60d86b563582a0198145fd (patch)
tree8ef7289826deba39fbf5c54d0b53f091ae013563
parentfc072f94584c18f8312a2622475d7ce3e1eaa2d4 (diff)
downloadsonarqube-e0df5f6bcb786d58fb60d86b563582a0198145fd.tar.gz
sonarqube-e0df5f6bcb786d58fb60d86b563582a0198145fd.zip
SONAR-6366 add ServletContext to Pico container
ServletContext will be used in an incoming commit to retrieve the Ruby runtime from Rack in ServerTester, added a dummy ServletContext implementation that supports attributes
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java7
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/PlatformServletContextListener.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java36
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/tester/AttributeHolderServletContext.java297
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/tester/AttributeHolderServletContextTest.java367
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java5
6 files changed, 702 insertions, 20 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index bbc3cc6b083..8523ec887b7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -19,12 +19,13 @@
*/
package org.sonar.server.platform;
-import org.sonar.api.utils.log.Loggers;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.platform.Server;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.persistence.DatabaseVersion;
import javax.annotation.CheckForNull;
+import javax.servlet.ServletContext;
import java.util.Collection;
import java.util.Properties;
@@ -66,8 +67,8 @@ public class Platform {
return null;
}
- public void init(Properties properties) {
- serverComponents = new ServerComponents(this, properties);
+ public void init(Properties properties, ServletContext servletContext) {
+ serverComponents = new ServerComponents(this, properties, servletContext);
if (!dbConnected) {
startLevel1Container();
startLevel2Container();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/PlatformServletContextListener.java b/server/sonar-server/src/main/java/org/sonar/server/platform/PlatformServletContextListener.java
index 4e4a220bf13..acd73c96f0a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/PlatformServletContextListener.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/PlatformServletContextListener.java
@@ -24,7 +24,6 @@ import com.google.common.base.Throwables;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-
import java.util.Enumeration;
import java.util.Properties;
@@ -34,13 +33,13 @@ public final class PlatformServletContextListener implements ServletContextListe
public void contextInitialized(ServletContextEvent event) {
try {
Properties props = new Properties();
- ServletContext context = event.getServletContext();
- Enumeration<String> paramKeys = context.getInitParameterNames();
+ ServletContext servletContext = event.getServletContext();
+ Enumeration<String> paramKeys = servletContext.getInitParameterNames();
while (paramKeys.hasMoreElements()) {
String key = paramKeys.nextElement();
- props.put(key, context.getInitParameter(key));
+ props.put(key, servletContext.getInitParameter(key));
}
- Platform.getInstance().init(props);
+ Platform.getInstance().init(props, servletContext);
Platform.getInstance().doStart();
} catch (Throwable t) {
// Tomcat 7 "limitations":
@@ -64,4 +63,5 @@ public final class PlatformServletContextListener implements ServletContextListe
public void contextDestroyed(ServletContextEvent event) {
Platform.getInstance().doStop();
}
+
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
index fefb9f9d378..72e911b8dd4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
@@ -204,6 +204,7 @@ import org.sonar.server.view.index.ViewIndexer;
import org.sonar.server.ws.ListingWs;
import org.sonar.server.ws.WebServiceEngine;
+import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -211,19 +212,24 @@ import java.util.Properties;
class ServerComponents {
- private final Object[] rootComponents;
- private List level4AddedComponents = Lists.newArrayList();
+ private final Platform platform;
+ private final Properties properties;
+ @Nullable
+ private final Object[] extraRootComponents;
+ private final List<Object> level4AddedComponents = Lists.newArrayList();
- ServerComponents(Platform platform, Properties properties, Object... rootComponents) {
- this.rootComponents = Lists.newArrayList(properties, platform, rootComponents)
- .toArray(new Object[rootComponents.length + 2]);
+ ServerComponents(Platform platform, Properties properties, Object... extraRootComponents) {
+ this.platform = platform;
+ this.properties = properties;
+ this.extraRootComponents = extraRootComponents;
}
/**
* All the stuff required to connect to database
*/
- Collection level1Components() {
- List components = Lists.newArrayList(rootComponents);
+ Collection<?> level1Components() {
+ List<Object> components = Lists.newArrayList(platform, properties);
+ addExtraRootComponents(components);
components.addAll(Arrays.asList(
ServerSettings.class,
ServerImpl.class,
@@ -297,12 +303,22 @@ class ServerComponents {
return components;
}
+ private void addExtraRootComponents(List<Object> components) {
+ if (this.extraRootComponents != null) {
+ for (Object extraRootComponent : this.extraRootComponents) {
+ if (extraRootComponent != null) {
+ components.add(extraRootComponent);
+ }
+ }
+ }
+ }
+
/**
* The stuff required to display the db upgrade form in webapp.
* Needs to be connected to db.
*/
- Collection level2Components() {
- return Lists.newArrayList(
+ Collection<Object> level2Components() {
+ return Lists.<Object>newArrayList(
DefaultServerUpgradeStatus.class,
DatabaseMigrator.class,
@@ -326,7 +342,7 @@ class ServerComponents {
* The core components that complete the initialization of database
* when its schema is up-to-date.
*/
- Collection level3Components() {
+ Collection<Object> level3Components() {
return Lists.newArrayList(
PersistentSettings.class,
DefaultDatabaseConnector.class,
diff --git a/server/sonar-server/src/test/java/org/sonar/server/tester/AttributeHolderServletContext.java b/server/sonar-server/src/test/java/org/sonar/server/tester/AttributeHolderServletContext.java
new file mode 100644
index 00000000000..8a06aa5f0f3
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/tester/AttributeHolderServletContext.java
@@ -0,0 +1,297 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.tester;
+
+import com.google.common.collect.Maps;
+
+import javax.servlet.*;
+import javax.servlet.descriptor.JspConfigDescriptor;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+
+/**
+ * A dummy implementation of {@link ServletContext} which only implements the attribute related methods. All other
+ * methods thrown a {@link UnsupportedOperationException} when called.
+ */
+class AttributeHolderServletContext implements ServletContext {
+ @Override
+ public String getContextPath() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ServletContext getContext(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getMajorVersion() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getMinorVersion() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getEffectiveMajorVersion() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getEffectiveMinorVersion() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getMimeType(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Set<String> getResourcePaths(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public URL getResource(String s) throws MalformedURLException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public InputStream getResourceAsStream(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public RequestDispatcher getRequestDispatcher(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public RequestDispatcher getNamedDispatcher(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Servlet getServlet(String s) throws ServletException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Enumeration<Servlet> getServlets() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Enumeration<String> getServletNames() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void log(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void log(Exception e, String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void log(String s, Throwable throwable) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getRealPath(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getServerInfo() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getInitParameter(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Enumeration<String> getInitParameterNames() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean setInitParameter(String s, String s1) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object getAttribute(String s) {
+ return this.attributes.get(s);
+ }
+
+ @Override
+ public Enumeration<String> getAttributeNames() {
+ return Collections.enumeration(this.attributes.keySet());
+ }
+
+ private final Map<String, Object> attributes = Maps.newHashMap();
+
+ @Override
+ public void setAttribute(String s, Object o) {
+ attributes.put(s, o);
+ }
+
+ @Override
+ public void removeAttribute(String s) {
+ attributes.remove(s);
+ }
+
+ @Override
+ public String getServletContextName() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ServletRegistration.Dynamic addServlet(String s, String s1) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ServletRegistration.Dynamic addServlet(String s, Servlet servlet) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ServletRegistration.Dynamic addServlet(String s, Class<? extends Servlet> aClass) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends Servlet> T createServlet(Class<T> aClass) throws ServletException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ServletRegistration getServletRegistration(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Map<String, ? extends ServletRegistration> getServletRegistrations() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public FilterRegistration.Dynamic addFilter(String s, String s1) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public FilterRegistration.Dynamic addFilter(String s, Filter filter) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public FilterRegistration.Dynamic addFilter(String s, Class<? extends Filter> aClass) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends Filter> T createFilter(Class<T> aClass) throws ServletException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public FilterRegistration getFilterRegistration(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SessionCookieConfig getSessionCookieConfig() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setSessionTrackingModes(Set<SessionTrackingMode> set) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addListener(String s) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends EventListener> void addListener(T t) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addListener(Class<? extends EventListener> aClass) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends EventListener> T createListener(Class<T> aClass) throws ServletException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public JspConfigDescriptor getJspConfigDescriptor() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ClassLoader getClassLoader() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void declareRoles(String... strings) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getVirtualServerName() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/tester/AttributeHolderServletContextTest.java b/server/sonar-server/src/test/java/org/sonar/server/tester/AttributeHolderServletContextTest.java
new file mode 100644
index 00000000000..ac3d7df6921
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/tester/AttributeHolderServletContextTest.java
@@ -0,0 +1,367 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.tester;
+
+import com.google.common.collect.ImmutableSet;
+import org.junit.Test;
+
+import javax.servlet.*;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.EventListener;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AttributeHolderServletContextTest {
+ public static final String SOME_STRING = "SOME_STRING";
+ public static final Exception SOME_EXCEPTION = new Exception();
+ public static final String SOME_OTHER_STRING = "SOME OTHER STRING";
+ AttributeHolderServletContext servletContext = new AttributeHolderServletContext();
+ public static final ImmutableSet<SessionTrackingMode> SOME_SET_OF_SESSION_TRACKING_MODE = ImmutableSet.of();
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getContextPath_is_not_supported() {
+ servletContext.getContextPath();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getContext_is_not_supported() {
+ servletContext.getContext(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getMajorVersion_is_not_supported() {
+ servletContext.getMajorVersion();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getMinorVersion_is_not_supported() {
+ servletContext.getMinorVersion();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getEffectiveMajorVersion_is_not_supported() {
+ servletContext.getEffectiveMajorVersion();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getEffectiveMinorVersion_is_not_supported() {
+ servletContext.getEffectiveMinorVersion();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getMimeType_is_not_supported() {
+ servletContext.getMimeType(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getResourcePaths_is_not_supported() {
+ servletContext.getResourcePaths(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getResource_is_not_supported() throws Exception {
+ servletContext.getResource(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getResourceAsStream_is_not_supported() {
+ servletContext.getResourceAsStream(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getRequestDispatcher_is_not_supported() {
+ servletContext.getRequestDispatcher(SOME_STRING);
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getNamedDispatcher_is_not_supported() {
+ servletContext.getNamedDispatcher(SOME_STRING);
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getServlet_is_not_supported() throws ServletException {
+ servletContext.getServlet(SOME_STRING);
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getServlets_is_not_supported() {
+ servletContext.getServlets();
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getServletNames_is_not_supported() {
+ servletContext.getServletNames();
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void log_is_not_supported() {
+ servletContext.log(SOME_STRING);
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void log1_is_not_supported() {
+ servletContext.log(SOME_EXCEPTION, SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void log2_is_not_supported() {
+ servletContext.log(SOME_STRING, SOME_EXCEPTION);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getRealPath_is_not_supported() {
+ servletContext.getRealPath(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getServerInfo_is_not_supported() {
+ servletContext.getServerInfo();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getInitParameter_is_not_supported() {
+ servletContext.getInitParameter(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getInitParameterNames_is_not_supported() {
+ servletContext.getInitParameterNames();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void setInitParameter_is_not_supported() {
+ servletContext.setInitParameter(SOME_STRING, SOME_STRING);
+
+ }
+
+ @Test
+ public void getAttribute_returns_null_when_attributes_are_empty() {
+ assertThat(servletContext.getAttribute(SOME_STRING)).isNull();
+ }
+
+ @Test
+ public void getAttribute_returns_attribute() {
+ servletContext.setAttribute(SOME_STRING, SOME_OTHER_STRING);
+
+ assertThat(servletContext.getAttribute(SOME_STRING)).isEqualTo(SOME_OTHER_STRING);
+ }
+
+ @Test
+ public void getAttributeNames_returns_empty_enumeration_if_attributes_are_empty() {
+ Enumeration<String> attributeNames = servletContext.getAttributeNames();
+ assertThat(attributeNames.hasMoreElements()).isFalse();
+ }
+
+ @Test
+ public void getAttributeNames_returns_names_of_attributes() {
+ servletContext.setAttribute(SOME_STRING, new Object());
+ servletContext.setAttribute(SOME_OTHER_STRING, new Object());
+
+ assertThat(Collections.list(servletContext.getAttributeNames())).containsOnly(SOME_STRING, SOME_OTHER_STRING);
+ }
+
+ @Test
+ public void removeAttribute_removes_specified_attribute() {
+ servletContext.setAttribute(SOME_STRING, new Object());
+ servletContext.setAttribute(SOME_OTHER_STRING, new Object());
+
+ servletContext.removeAttribute(SOME_OTHER_STRING);
+
+ assertThat(servletContext.getAttribute(SOME_OTHER_STRING)).isNull();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getServletContextName_is_not_supported() {
+ servletContext.getServletContextName();
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addServlet_by_class_is_not_supported() {
+ servletContext.addServlet(SOME_STRING, Servlet.class);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addServlet_by_instance_is_not_supported() {
+ servletContext.addServlet(SOME_STRING, new Servlet() {
+ @Override
+ public void init(ServletConfig servletConfig) throws ServletException {
+
+ }
+
+ @Override
+ public ServletConfig getServletConfig() {
+ return null;
+ }
+
+ @Override
+ public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
+
+ }
+
+ @Override
+ public String getServletInfo() {
+ return null;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+ });
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addServlet_by_string_is_not_supported() {
+ servletContext.addServlet(SOME_STRING, SOME_OTHER_STRING);
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void createServlet_is_not_supported() throws ServletException {
+ servletContext.createServlet(Servlet.class);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getServletRegistration_is_not_supported() {
+ servletContext.getServletRegistration(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getServletRegistrations_is_not_supported() {
+ servletContext.getServletRegistrations();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addFilter_by_class_is_not_supported() {
+ servletContext.addFilter(SOME_STRING, Filter.class);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addFilter_by_instance_is_not_supported() {
+ servletContext.addFilter(SOME_STRING, new Filter() {
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+ });
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addFilter2_by_string_is_not_supported() {
+ servletContext.addFilter(SOME_STRING, SOME_OTHER_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void createFilter_is_not_supported() throws ServletException {
+ servletContext.createFilter(Filter.class);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getFilterRegistration_is_not_supported() {
+ servletContext.getFilterRegistration(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getFilterRegistrations_is_not_supported() {
+ servletContext.getFilterRegistrations();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getSessionCookieConfig_is_not_supported() {
+ servletContext.getSessionCookieConfig();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void setSessionTrackingModes_is_not_supported() {
+ servletContext.setSessionTrackingModes(SOME_SET_OF_SESSION_TRACKING_MODE);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getDefaultSessionTrackingModes_is_not_supported() {
+ servletContext.getDefaultSessionTrackingModes();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getEffectiveSessionTrackingModes_is_not_supported() {
+ servletContext.getEffectiveSessionTrackingModes();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addListener_by_class_is_not_supported() {
+ servletContext.addListener(EventListener.class);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addListener_by_string_is_not_supported() {
+ servletContext.addListener(SOME_STRING);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void addListener_by_instance_is_not_supported() {
+ servletContext.addListener(new EventListener() {
+ });
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void createListener_is_not_supported() throws ServletException {
+ servletContext.createListener(EventListener.class);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getJspConfigDescriptor_is_not_supported() {
+ servletContext.getJspConfigDescriptor();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getClassLoader_is_not_supported() {
+ servletContext.getClassLoader();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void declareRoles_is_not_supported() {
+ servletContext.declareRoles();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getVirtualServerName_is_not_supported() {
+ servletContext.getVirtualServerName();
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java b/server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
index 93891e4b178..38d2dce668a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
@@ -37,7 +37,7 @@ import org.sonar.server.ws.WsTester;
import org.sonar.test.TestUtils;
import javax.annotation.Nullable;
-
+import javax.servlet.ServletContext;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@@ -63,6 +63,7 @@ public class ServerTester extends ExternalResource {
private final File homeDir = TestUtils.newTempDir("tmp-sq-");
private final List components = Lists.newArrayList(WsTester.class);
private final Properties initialProps = new Properties();
+ private final ServletContext servletContext = new AttributeHolderServletContext();
/**
* Called only when JUnit @Rule or @ClassRule is used.
@@ -97,7 +98,7 @@ public class ServerTester extends ExternalResource {
}
}
platform = new Platform();
- platform.init(properties);
+ platform.init(properties, servletContext);
platform.addComponents(components);
platform.doStart();
} catch (Exception e) {