]> source.dussan.org Git - vaadin-framework.git/commitdiff
Dedicated methods for init params in DeploymentConfiguration (#12087).
authorDenis Anisimov <denis@vaadin.com>
Sun, 21 Sep 2014 10:43:28 +0000 (13:43 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 30 Sep 2014 12:39:21 +0000 (12:39 +0000)
Change-Id: I3610814509f38ed4c8789de52cc53e7b19a4c4a2

server/src/com/vaadin/server/AbstractDeploymentConfiguration.java [new file with mode: 0644]
server/src/com/vaadin/server/DefaultDeploymentConfiguration.java
server/src/com/vaadin/server/DefaultUIProvider.java
server/src/com/vaadin/server/DeploymentConfiguration.java
server/src/com/vaadin/server/ServletPortletHelper.java
server/src/com/vaadin/server/VaadinPortletService.java
server/src/com/vaadin/server/VaadinService.java
server/src/com/vaadin/server/VaadinServletService.java
server/tests/src/com/vaadin/server/AbstractDeploymentConfigurationTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java
server/tests/src/com/vaadin/tests/util/MockDeploymentConfiguration.java

diff --git a/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java b/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java
new file mode 100644 (file)
index 0000000..43d4570
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2000-2014 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;
+
+/**
+ * An abstract base class for DeploymentConfiguration implementations. This
+ * class provides default implementation for common config properties.
+ * 
+ * @author Vaadin Ltd
+ */
+public abstract class AbstractDeploymentConfiguration implements
+        DeploymentConfiguration {
+
+    @Override
+    public String getUIClassName() {
+        return getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER, null);
+    }
+
+    @Override
+    public String getUIProviderClassName() {
+        return getApplicationOrSystemProperty(
+                Constants.SERVLET_PARAMETER_UI_PROVIDER, null);
+    }
+
+    @Override
+    public String getWidgetset(String defaultValue) {
+        return getApplicationOrSystemProperty(Constants.PARAMETER_WIDGETSET,
+                defaultValue);
+    }
+
+    @Override
+    public String getResourcesPath() {
+        return getApplicationOrSystemProperty(
+                Constants.PARAMETER_VAADIN_RESOURCES, null);
+    }
+
+    @Override
+    public String getClassLoaderName() {
+        return getApplicationOrSystemProperty("ClassLoader", null);
+    }
+}
index fd14c3cd3f8a90d710bb57677f42cf1ec8b069e6..22d5210eaa223f642b63f32127a1902372badf65 100644 (file)
@@ -29,7 +29,8 @@ import com.vaadin.shared.communication.PushMode;
  * @author Vaadin Ltd
  * @since 7.0.0
  */
-public class DefaultDeploymentConfiguration implements DeploymentConfiguration {
+public class DefaultDeploymentConfiguration extends
+        AbstractDeploymentConfiguration {
     /**
      * Default value for {@link #getResourceCacheTime()} = {@value} .
      */
index 2a1a59dbe66eb9aee277440c8f266473a9969ad0..38525fc020dd969d9714ca4eefb9178ee8073600 100644 (file)
@@ -24,15 +24,9 @@ public class DefaultUIProvider extends UIProvider {
     public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
         VaadinRequest request = event.getRequest();
 
-        Object uiClassNameObj = request
-                .getService()
-                .getDeploymentConfiguration()
-                .getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER,
-                        null);
-
-        if (uiClassNameObj instanceof String) {
-            String uiClassName = uiClassNameObj.toString();
-
+        String uiClassName = request.getService().getDeploymentConfiguration()
+                .getUIClassName();
+        if (uiClassName != null) {
             ClassLoader classLoader = request.getService().getClassLoader();
             try {
                 Class<? extends UI> uiClass = Class.forName(uiClassName, true,
index fcfeecc31fdab6bede92755d631b8ea0a47a5fa8..3124729773e2eed3d202fbbefdf37b53712648b6 100644 (file)
@@ -162,6 +162,38 @@ public interface DeploymentConfiguration extends Serializable {
     public String getApplicationOrSystemProperty(String propertyName,
             String defaultValue);
 
+    /**
+     * Gets UI class configuration option value.
+     * 
+     * @return UI class name
+     */
+    public String getUIClassName();
+
+    /**
+     * Gets UI provider class configuration option value.
+     * 
+     * @return UI class name
+     */
+    public String getUIProviderClassName();
+
+    /**
+     * Gets Widgetset configuration option value. {@code defaultValue} is
+     * returned if widgetset parameter is not configured.
+     * 
+     * @return UI class name
+     */
+    public String getWidgetset(String defaultValue);
+
+    /**
+     * Gets resources path configuration option value.
+     */
+    public String getResourcesPath();
+
+    /**
+     * Gets class loader configuration option value.
+     */
+    public String getClassLoaderName();
+
     /**
      * Returns to legacy Property.toString() mode used. See
      * {@link AbstractProperty#isLegacyToStringEnabled()} for more information.
index 2ec747ba3a6b93938ab65ad879727fa2a0c455f0..197d9fe4161d8b0d21ea1d5f5b41abdcc5cc79c4 100644 (file)
@@ -130,8 +130,7 @@ public class ServletPortletHelper implements Serializable {
     public static void initDefaultUIProvider(VaadinSession session,
             VaadinService vaadinService) throws ServiceException {
         String uiProperty = vaadinService.getDeploymentConfiguration()
-                .getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER,
-                        null);
+                .getUIClassName();
 
         // Add provider for UI parameter first to give it lower priority
         // (providers are FILO)
@@ -141,8 +140,7 @@ public class ServletPortletHelper implements Serializable {
         }
 
         String uiProviderProperty = vaadinService.getDeploymentConfiguration()
-                .getApplicationOrSystemProperty(
-                        Constants.SERVLET_PARAMETER_UI_PROVIDER, null);
+                .getUIProviderClassName();
         // Then add custom UI provider if defined
         if (uiProviderProperty != null) {
             UIProvider uiProvider = getUIProvider(uiProviderProperty,
index c6d9b8e46afaba21dd11850aa2b5fc11961f7cde..cff024672c00bb45e591175d85e4fd07c704b3f4 100644 (file)
@@ -124,9 +124,7 @@ public class VaadinPortletService extends VaadinService {
     @Override
     public String getConfiguredWidgetset(VaadinRequest request) {
 
-        String widgetset = getDeploymentConfiguration()
-                .getApplicationOrSystemProperty(
-                        VaadinPortlet.PARAMETER_WIDGETSET, null);
+        String widgetset = getDeploymentConfiguration().getWidgetset(null);
 
         if (widgetset == null) {
             widgetset = getParameter(request,
index 8fd6da8dee21349f7c9879024ae65859c04dd678..008ba9c1c87c975f8704455b6d3c447f7f3b2b5e 100644 (file)
@@ -155,7 +155,7 @@ public abstract class VaadinService implements Serializable {
         this.deploymentConfiguration = deploymentConfiguration;
 
         final String classLoaderName = getDeploymentConfiguration()
-                .getApplicationOrSystemProperty("ClassLoader", null);
+                .getClassLoaderName();
         if (classLoaderName != null) {
             try {
                 final Class<?> classLoaderClass = getClass().getClassLoader()
index a4ff3943c9491ecd3629a391fdba3a36a60e5dc6..8946ac4faeccfb528b9332eca6e9223dd269bee7 100644 (file)
@@ -118,9 +118,7 @@ public class VaadinServletService extends VaadinService {
         VaadinServletRequest servletRequest = (VaadinServletRequest) request;
         String staticFileLocation;
         // if property is defined in configurations, use that
-        staticFileLocation = getDeploymentConfiguration()
-                .getApplicationOrSystemProperty(
-                        VaadinServlet.PARAMETER_VAADIN_RESOURCES, null);
+        staticFileLocation = getDeploymentConfiguration().getResourcesPath();
         if (staticFileLocation != null) {
             return staticFileLocation;
         }
@@ -159,8 +157,7 @@ public class VaadinServletService extends VaadinService {
 
     @Override
     public String getConfiguredWidgetset(VaadinRequest request) {
-        return getDeploymentConfiguration().getApplicationOrSystemProperty(
-                VaadinServlet.PARAMETER_WIDGETSET,
+        return getDeploymentConfiguration().getWidgetset(
                 VaadinServlet.DEFAULT_WIDGETSET);
     }
 
diff --git a/server/tests/src/com/vaadin/server/AbstractDeploymentConfigurationTest.java b/server/tests/src/com/vaadin/server/AbstractDeploymentConfigurationTest.java
new file mode 100644 (file)
index 0000000..7370bd3
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2000-2014 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 java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.shared.communication.PushMode;
+
+/**
+ * Test for {@link AbstractDeploymentConfiguration}
+ * 
+ * @author Vaadin Ltd
+ */
+public class AbstractDeploymentConfigurationTest {
+
+    @Test
+    public void getUIClass_returnsUIParameterPropertyValue() {
+        String ui = UUID.randomUUID().toString();
+        DeploymentConfiguration config = getConfig(VaadinSession.UI_PARAMETER,
+                ui);
+        Assert.assertEquals("Unexpected UI class configuration option value",
+                ui, config.getUIClassName());
+    }
+
+    @Test
+    public void getUIProviderClass_returnsUIProviderPropertyValue() {
+        String uiProvider = UUID.randomUUID().toString();
+        DeploymentConfiguration config = getConfig(
+                Constants.SERVLET_PARAMETER_UI_PROVIDER, uiProvider);
+        Assert.assertEquals(
+                "Unexpected UI providerclass configuration option value",
+                uiProvider, config.getUIProviderClassName());
+    }
+
+    @Test
+    public void getWidgetset_returnsWidgetsetProviderPropertyValue() {
+        String widgetset = UUID.randomUUID().toString();
+        DeploymentConfiguration config = getConfig(
+                Constants.PARAMETER_WIDGETSET, widgetset);
+        Assert.assertEquals("Unexpected widgetset configuration option value",
+                widgetset, config.getWidgetset(null));
+    }
+
+    @Test
+    public void getWidgetset_noWidgetsetPropertyValue_returnsProvidedDefaultValue() {
+        DeploymentConfiguration config = getConfig(null, null);
+        String widgetset = UUID.randomUUID().toString();
+        Assert.assertEquals("Unexpected widgetset configuration option value",
+                widgetset, config.getWidgetset(widgetset));
+    }
+
+    @Test
+    public void getResourcesPath_returnsResourcesPathPropertyValue() {
+        String resources = UUID.randomUUID().toString();
+        DeploymentConfiguration config = getConfig(
+                Constants.PARAMETER_VAADIN_RESOURCES, resources);
+        Assert.assertEquals(
+                "Unexpected resources path configuration option value",
+                resources, config.getResourcesPath());
+    }
+
+    @Test
+    public void getClassLoader_returnsClassloaderPropertyValue() {
+        String classLoader = UUID.randomUUID().toString();
+        DeploymentConfiguration config = getConfig("ClassLoader", classLoader);
+        Assert.assertEquals(
+                "Unexpected classLoader configuration option value",
+                classLoader, config.getClassLoaderName());
+    }
+
+    private DeploymentConfiguration getConfig(String property, String value) {
+        Properties props = new Properties();
+        if (property != null) {
+            props.put(property, value);
+        }
+        return new DeploymentConfigImpl(props);
+    }
+
+    private static class DeploymentConfigImpl extends
+            AbstractDeploymentConfiguration {
+
+        private Properties properties;
+
+        DeploymentConfigImpl(Properties props) {
+            properties = props;
+        }
+
+        @Override
+        public boolean isProductionMode() {
+            return false;
+        }
+
+        @Override
+        public boolean isXsrfProtectionEnabled() {
+            return false;
+        }
+
+        @Override
+        public boolean isSyncIdCheckEnabled() {
+            return false;
+        }
+
+        @Override
+        public int getResourceCacheTime() {
+            return 0;
+        }
+
+        @Override
+        public int getHeartbeatInterval() {
+            return 0;
+        }
+
+        @Override
+        public boolean isCloseIdleSessions() {
+            return false;
+        }
+
+        @Override
+        public PushMode getPushMode() {
+            return null;
+        }
+
+        @Override
+        public Properties getInitParameters() {
+            return null;
+        }
+
+        @Override
+        public String getApplicationOrSystemProperty(String propertyName,
+                String defaultValue) {
+            return properties.getProperty(propertyName, defaultValue);
+        }
+
+        @Override
+        public LegacyProperyToStringMode getLegacyPropertyToStringMode() {
+            return null;
+        }
+
+    }
+}
index f7a69c2edb22518e50ab505642026aea2fb59fcd..0e094bfabb0d2257722d3f498657f38825797a07 100644 (file)
@@ -86,10 +86,7 @@ public class VaadinPortletServiceTests {
     }
 
     private void mockWidgetsetConfiguration(String widgetset) {
-        when(
-                conf.getApplicationOrSystemProperty(
-                        Constants.PARAMETER_WIDGETSET, null)).thenReturn(
-                widgetset);
+        when(conf.getWidgetset(null)).thenReturn(widgetset);
     }
 
     @Test
index fe7f9ba03ebb9d2afdee26006093fb795b04feea..8eceaea53f9b33955d5bc44364c3e99825cb569d 100644 (file)
@@ -4,10 +4,11 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
-import com.vaadin.server.DeploymentConfiguration;
+import com.vaadin.server.AbstractDeploymentConfiguration;
 import com.vaadin.shared.communication.PushMode;
 
-public class MockDeploymentConfiguration implements DeploymentConfiguration {
+public class MockDeploymentConfiguration extends
+        AbstractDeploymentConfiguration {
 
     private boolean productionMode = false;
     private boolean xsrfProtectionEnabled = true;