diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-06-04 16:17:23 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-05 09:15:40 +0000 |
commit | 132eee59b8914fdbf9c42a9314e3db95f2f51520 (patch) | |
tree | fc794c3956d497afe1bd88368f4da5c8e82f9b79 /server/tests | |
parent | e63edcc6cb4a3dd5253999319831b93a764eabb4 (diff) | |
download | vaadin-framework-132eee59b8914fdbf9c42a9314e3db95f2f51520.tar.gz vaadin-framework-132eee59b8914fdbf9c42a9314e3db95f2f51520.zip |
Add @VaadinServletConfiguration (#11970)
Change-Id: Ic902028826adae8132bfa18b6cde7d80a2e876c4
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/src/com/vaadin/server/MockServletConfig.java | 15 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/server/VaadinServletConfigurationTest.java | 98 |
2 files changed, 110 insertions, 3 deletions
diff --git a/server/tests/src/com/vaadin/server/MockServletConfig.java b/server/tests/src/com/vaadin/server/MockServletConfig.java index b1e046c812..cd1201c249 100644 --- a/server/tests/src/com/vaadin/server/MockServletConfig.java +++ b/server/tests/src/com/vaadin/server/MockServletConfig.java @@ -19,8 +19,8 @@ */ package com.vaadin.server; -import java.util.Collections; import java.util.Enumeration; +import java.util.Properties; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -33,6 +33,15 @@ import javax.servlet.ServletContext; public class MockServletConfig implements ServletConfig { private ServletContext context = new MockServletContext(); + private final Properties initParameters; + + public MockServletConfig() { + this(new Properties()); + } + + public MockServletConfig(Properties initParameters) { + this.initParameters = initParameters; + } /* * (non-Javadoc) @@ -61,7 +70,7 @@ public class MockServletConfig implements ServletConfig { */ @Override public String getInitParameter(String name) { - return null; + return initParameters.getProperty(name); } /* @@ -71,7 +80,7 @@ public class MockServletConfig implements ServletConfig { */ @Override public Enumeration getInitParameterNames() { - return Collections.enumeration(Collections.EMPTY_LIST); + return initParameters.propertyNames(); } } diff --git a/server/tests/src/com/vaadin/server/VaadinServletConfigurationTest.java b/server/tests/src/com/vaadin/server/VaadinServletConfigurationTest.java new file mode 100644 index 0000000000..80cb1d7b0c --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinServletConfigurationTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * + */ +package com.vaadin.server; + +import java.util.Properties; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; + +import junit.framework.Assert; + +import org.easymock.EasyMock; +import org.junit.Test; + +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.server.DeploymentConfiguration.LegacyProperyToStringMode; +import com.vaadin.server.VaadinServletConfigurationTest.MockUI; +import com.vaadin.ui.UI; + +public class VaadinServletConfigurationTest { + public static class MockUI extends UI { + @Override + protected void init(VaadinRequest request) { + // Do nothing + } + } + + @Test + public void testValuesFromAnnotation() throws ServletException { + TestServlet servlet = new TestServlet(); + servlet.init(new MockServletConfig()); + DeploymentConfiguration configuration = servlet.getService() + .getDeploymentConfiguration(); + + Assert.assertEquals(true, configuration.isProductionMode()); + Assert.assertEquals(LegacyProperyToStringMode.DISABLED, + configuration.getLegacyPropertyToStringMode()); + Assert.assertEquals(true, configuration.isCloseIdleSessions()); + Assert.assertEquals(1234, configuration.getHeartbeatInterval()); + Assert.assertEquals(4321, configuration.getResourceCacheTime()); + + Class<? extends UI> uiClass = new DefaultUIProvider() + .getUIClass(new UIClassSelectionEvent(new VaadinServletRequest( + EasyMock.createMock(HttpServletRequest.class), servlet + .getService()))); + Assert.assertEquals(MockUI.class, uiClass); + } + + @Test + public void testValuesOverriddenForServlet() throws ServletException { + Properties servletInitParams = new Properties(); + servletInitParams.setProperty("productionMode", "false"); + servletInitParams.setProperty("heartbeatInterval", "1111"); + + TestServlet servlet = new TestServlet(); + servlet.init(new MockServletConfig(servletInitParams)); + DeploymentConfiguration configuration = servlet.getService() + .getDeploymentConfiguration(); + + // Values from servlet init params take precedence + Assert.assertEquals(1111, configuration.getHeartbeatInterval()); + Assert.assertEquals(false, configuration.isProductionMode()); + + // Other params are as defined in the annotation + Assert.assertEquals(LegacyProperyToStringMode.DISABLED, + configuration.getLegacyPropertyToStringMode()); + Assert.assertEquals(true, configuration.isCloseIdleSessions()); + Assert.assertEquals(4321, configuration.getResourceCacheTime()); + + Class<? extends UI> uiClass = new DefaultUIProvider() + .getUIClass(new UIClassSelectionEvent(new VaadinServletRequest( + EasyMock.createMock(HttpServletRequest.class), servlet + .getService()))); + Assert.assertEquals(MockUI.class, uiClass); + } +} + +@VaadinServletConfiguration(productionMode = true, ui = MockUI.class, closeIdleSessions = true, heartbeatInterval = 1234, resourceCacheTime = 4321) +class TestServlet extends VaadinServlet { + +} |