summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2014-03-13 13:27:23 +0200
committerSauli Tähkäpää <sauli@vaadin.com>2014-03-26 12:54:16 +0200
commit437f4e9c2478750e53ef3c6bff03bdd25e547432 (patch)
treee876846447df2ca05d9eb08e6043e49dbcbe88c0 /server/tests
parent1f4ca4cb82e0144053b8a8d5266535da6af0f21f (diff)
downloadvaadin-framework-437f4e9c2478750e53ef3c6bff03bdd25e547432.tar.gz
vaadin-framework-437f4e9c2478750e53ef3c6bff03bdd25e547432.zip
Improved portlet configuration resolution. (#7814)
Refactored static path resolution in VaadinPortletService. Refactored theme name resolution in VaadinPortletService. Refactored widgetset name resolution in VaadinPortletService. Change-Id: I44c5ffaa7530383843205aadd8da7642899a04c9
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/server/VaadinPortletRequestTests.java52
-rw-r--r--server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java151
2 files changed, 194 insertions, 9 deletions
diff --git a/server/tests/src/com/vaadin/server/VaadinPortletRequestTests.java b/server/tests/src/com/vaadin/server/VaadinPortletRequestTests.java
new file mode 100644
index 0000000000..6e40c57718
--- /dev/null
+++ b/server/tests/src/com/vaadin/server/VaadinPortletRequestTests.java
@@ -0,0 +1,52 @@
+package com.vaadin.server;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class VaadinPortletRequestTests {
+
+ private PortletRequest request;
+ private VaadinPortletRequest sut;
+ private VaadinPortletService service;
+ private PortletPreferences preferences;
+
+ @Before
+ public void setup() {
+ request = mock(PortletRequest.class);
+ service = mock(VaadinPortletService.class);
+
+ sut = new VaadinPortletRequest(request, service);
+
+ preferences = mock(PortletPreferences.class);
+ when(request.getPreferences()).thenReturn(preferences);
+ }
+
+ @Test
+ public void portletPreferenceIsFetched() {
+ when(preferences.getValue(eq("foo"), anyString())).thenReturn("bar");
+
+ String value = sut.getPortletPreference("foo");
+
+ assertThat(value, is("bar"));
+ }
+
+ @Test
+ public void defaultValueForPortletPreferenceIsNull() {
+ when(preferences.getValue(anyString(), isNull(String.class))).thenReturn(null);
+
+ String value = sut.getPortletPreference("foo");
+
+ assertNull(value);
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java b/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java
index c54a6dddce..62befdc516 100644
--- a/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java
+++ b/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java
@@ -27,32 +27,165 @@ public class VaadinPortletServiceTests {
private VaadinPortletService sut;
private VaadinPortletRequest request;
+ private DeploymentConfiguration conf;
@Before
public void setup() throws ServiceException {
VaadinPortlet portlet = mock(VaadinPortlet.class);
- DeploymentConfiguration conf = mock(DeploymentConfiguration.class);
+ conf = mock(DeploymentConfiguration.class);
sut = new VaadinPortletService(portlet, conf);
request = mock(VaadinPortletRequest.class);
}
- private void mockRequestToReturnLocation(String location) {
- when(request.getPortalProperty(
- Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH))
+ private void mockFileLocationProperty(String location) {
+ mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH,
+ location);
+ }
+
+ private void mockPortalProperty(String name, String value) {
+ when(request.getPortalProperty(name)).thenReturn(value);
+ }
+
+ private void mockFileLocationPreference(String location) {
+ when(
+ request.getPortletPreference(Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH))
.thenReturn(location);
}
+ private void mockLocationDeploymentConfiguration(String location) {
+ when(
+ conf.getApplicationOrSystemProperty(
+ Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH, null))
+ .thenReturn(location);
+ }
+
+ private String getStaticFileLocation() {
+ return sut.getStaticFileLocation(request);
+ }
+
+ private String getTheme() {
+ return sut.getConfiguredTheme(request);
+ }
+
+ private void mockThemeProperty(String theme) {
+ mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME, theme);
+ }
+
+ private void mockWidgetsetProperty(String widgetset) {
+ mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_WIDGETSET,
+ widgetset);
+ }
+
+ private void mockWidgetsetConfiguration(String widgetset) {
+ when(
+ conf.getApplicationOrSystemProperty(
+ Constants.PARAMETER_WIDGETSET, null)).thenReturn(
+ widgetset);
+ }
+
+ @Test
+ public void preferencesOverrideDeploymentConfiguration() {
+ mockFileLocationPreference("prefs");
+ mockLocationDeploymentConfiguration("conf");
+
+ String location = getStaticFileLocation();
+
+ assertThat(location, is("prefs"));
+ }
+
+ @Test
+ public void deploymentConfigurationOverridesProperties() {
+ mockFileLocationPreference(null);
+ mockLocationDeploymentConfiguration("conf");
+ mockFileLocationProperty("props");
+
+ String location = getStaticFileLocation();
+
+ assertThat(location, is("conf"));
+ }
+
@Test
- public void trailingSlashesAreTrimmedFromStaticFileLocation()
- throws ServiceException {
+ public void defaultFileLocationIsSet() {
+ mockFileLocationPreference(null);
+ mockLocationDeploymentConfiguration(null);
+ mockFileLocationProperty(null);
+
+ String location = getStaticFileLocation();
- mockRequestToReturnLocation("/content////");
+ assertThat(location, is("/html"));
+ }
+
+ @Test
+ public void trailingSlashesAreTrimmedFromStaticFileLocation() {
+ mockFileLocationPreference("/content////");
- String staticFileLocation = sut
- .getStaticFileLocation(request);
+ String staticFileLocation = getStaticFileLocation();
assertThat(staticFileLocation, is("/content"));
}
+
+ @Test
+ public void themeCanBeOverridden() {
+ mockThemeProperty("foobar");
+
+ String theme = getTheme();
+
+ assertThat(theme, is("foobar"));
+ }
+
+ @Test
+ public void defaultThemeIsSet() {
+ mockThemeProperty(null);
+
+ String theme = getTheme();
+
+ assertThat(theme, is(Constants.DEFAULT_THEME_NAME));
+ }
+
+ private String getWidgetset() {
+ return sut.getConfiguredWidgetset(request);
+ }
+
+ @Test
+ public void defaultWidgetsetIsSet() {
+ mockWidgetsetProperty(null);
+ mockWidgetsetConfiguration(null);
+
+ String widgetset = getWidgetset();
+
+ assertThat(widgetset, is(Constants.DEFAULT_WIDGETSET));
+ }
+
+ @Test
+ public void configurationWidgetsetOverridesProperty() {
+ mockWidgetsetProperty("foo");
+ mockWidgetsetConfiguration("bar");
+
+ String widgetset = getWidgetset();
+
+ assertThat(widgetset, is("bar"));
+ }
+
+ @Test
+ public void oldDefaultWidgetsetIsMappedToDefaultWidgetset() {
+ mockWidgetsetConfiguration(null);
+ mockWidgetsetProperty("com.vaadin.portal.gwt.PortalDefaultWidgetSet");
+
+ String widgetset = getWidgetset();
+
+ assertThat(widgetset, is(Constants.DEFAULT_WIDGETSET));
+ }
+
+ @Test
+ public void oldDefaultWidgetSetIsNotMappedToDefaultWidgetset() {
+ mockWidgetsetConfiguration("com.vaadin.portal.gwt.PortalDefaultWidgetSet");
+ mockWidgetsetProperty(null);
+
+ String widgetset = getWidgetset();
+
+ assertThat(widgetset,
+ is("com.vaadin.portal.gwt.PortalDefaultWidgetSet"));
+ }
}