diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2014-03-13 08:52:37 +0200 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-03-13 09:11:31 +0200 |
commit | 49973354b22e8aba9cc71f83571020b0414c54e0 (patch) | |
tree | ab10e93151f12830b5f12382cfc03651c907f3fc /server | |
parent | 94d33ad7c732f620c9e98502b896a65852479b7d (diff) | |
download | vaadin-framework-49973354b22e8aba9cc71f83571020b0414c54e0.tar.gz vaadin-framework-49973354b22e8aba9cc71f83571020b0414c54e0.zip |
Fixed trailing slash trimming in VaadinPortletService.
Change-Id: Ia9f6230219adfb1fcb29b88ad819e3209770e1fc
Diffstat (limited to 'server')
-rw-r--r-- | server/ivy.xml | 2 | ||||
-rw-r--r-- | server/src/com/vaadin/server/VaadinPortletService.java | 14 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java | 58 |
3 files changed, 65 insertions, 9 deletions
diff --git a/server/ivy.xml b/server/ivy.xml index ba859b08ee..2967d25f32 100644 --- a/server/ivy.xml +++ b/server/ivy.xml @@ -60,6 +60,8 @@ <!-- Test frameworks & related --> <dependency org="junit" name="junit" rev="4.11" conf="test,ide -> default" /> + <dependency org="org.mockito" name="mockito-all" rev="1.9.5" + conf="test,ide->default" /> <dependency org="org.easymock" name="easymock" rev="3.0" conf="test,ide-> default" transitive="true" /> <dependency org="org.hsqldb" name="hsqldb" rev="2.2.6" diff --git a/server/src/com/vaadin/server/VaadinPortletService.java b/server/src/com/vaadin/server/VaadinPortletService.java index 194c9c88a9..42cf479c56 100644 --- a/server/src/com/vaadin/server/VaadinPortletService.java +++ b/server/src/com/vaadin/server/VaadinPortletService.java @@ -16,6 +16,8 @@ package com.vaadin.server; +import static com.vaadin.shared.util.SharedUtil.trimTrailingSlashes; + import java.io.File; import java.io.InputStream; import java.net.URL; @@ -80,9 +82,8 @@ public class VaadinPortletService extends VaadinService { } private static String getPortalProperty(VaadinRequest request, - String portalParameterVaadinWidgetset) { - return ((VaadinPortletRequest) request) - .getPortalProperty(portalParameterVaadinWidgetset); + String propertyName) { + return ((VaadinPortletRequest) request).getPortalProperty(propertyName); } @Override @@ -139,12 +140,7 @@ public class VaadinPortletService extends VaadinService { String staticFileLocation = getPortalProperty(request, Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH); if (staticFileLocation != null) { - // remove trailing slash if any - while (staticFileLocation.endsWith(".")) { - staticFileLocation = staticFileLocation.substring(0, - staticFileLocation.length() - 1); - } - return staticFileLocation; + return trimTrailingSlashes(staticFileLocation); } else { // default for Liferay return "/html"; diff --git a/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java b/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java new file mode 100644 index 0000000000..c54a6dddce --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java @@ -0,0 +1,58 @@ +/* + * 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 static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; + +public class VaadinPortletServiceTests { + + private VaadinPortletService sut; + private VaadinPortletRequest request; + + @Before + public void setup() throws ServiceException { + VaadinPortlet portlet = mock(VaadinPortlet.class); + DeploymentConfiguration 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)) + .thenReturn(location); + } + + @Test + public void trailingSlashesAreTrimmedFromStaticFileLocation() + throws ServiceException { + + mockRequestToReturnLocation("/content////"); + + String staticFileLocation = sut + .getStaticFileLocation(request); + + assertThat(staticFileLocation, is("/content")); + } +} |