summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/ivy.xml2
-rw-r--r--server/src/com/vaadin/server/VaadinPortletService.java14
-rw-r--r--server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java58
-rw-r--r--shared/build.xml5
-rw-r--r--shared/ivy.xml2
-rw-r--r--shared/src/com/vaadin/shared/util/SharedUtil.java9
-rw-r--r--shared/tests/src/com/vaadin/shared/util/SharedUtilTests.java43
7 files changed, 121 insertions, 12 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"));
+ }
+}
diff --git a/shared/build.xml b/shared/build.xml
index 73a0a8df7f..966d250d66 100644
--- a/shared/build.xml
+++ b/shared/build.xml
@@ -15,7 +15,7 @@
<property name="src.filtered" location="${result.dir}/filtered-src" />
<property name="src" location="${src.filtered}" />
<path id="classpath.compile.custom" />
-
+ <path id="classpath.test.custom" />
<target name="jar">
<property name="shared.osgi.import" value="org.json;version=&quot;0.0.20080701&quot;, com.google.gwt.thirdparty.guava.common.annotations;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.base;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.base.internal;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.cache;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.collect;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.eventbus;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.io;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.net;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.primitives;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.guava.common.util.concurrent;version=&quot;10.0.1.rebased&quot;, com.google.gwt.thirdparty.streamhtmlparser;version=&quot;0.1.5.r10-rebased&quot;, com.google.gwt.thirdparty.streamhtmlparser.impl;version=&quot;0.1.5.r10-rebased&quot;, com.google.gwt.thirdparty.streamhtmlparser.util;version=&quot;0.1.5.r10-rebased&quot;, org.w3c.flute.parser;version=&quot;1.3.0.gg2&quot;, org.w3c.flute.parser.selectors;version=&quot;1.3.0.gg2&quot;, org.w3c.flute.util;version=&quot;1.3.0.gg2&quot;" />
@@ -57,8 +57,7 @@
</target>
<target name="test" depends="checkstyle">
- <!--<antcall target="common.test.run" /> -->
- <echo>WHAT? No tests for ${module.name}!</echo>
+ <antcall target="common.test.run" />
</target>
</project>
diff --git a/shared/ivy.xml b/shared/ivy.xml
index 3b044e9ab4..b4b5878294 100644
--- a/shared/ivy.xml
+++ b/shared/ivy.xml
@@ -22,6 +22,8 @@
<dependencies>
<dependency org="com.vaadin" name="vaadin-shared-deps"
rev="1.0.2" conf="build,ide,test->default" />
+ <dependency org="junit" name="junit" rev="4.11"
+ conf="test,ide -> default" />
</dependencies>
</ivy-module>
diff --git a/shared/src/com/vaadin/shared/util/SharedUtil.java b/shared/src/com/vaadin/shared/util/SharedUtil.java
index 80efe68d83..449685705f 100644
--- a/shared/src/com/vaadin/shared/util/SharedUtil.java
+++ b/shared/src/com/vaadin/shared/util/SharedUtil.java
@@ -44,4 +44,13 @@ public class SharedUtil implements Serializable {
return o1.equals(o2);
}
+ /**
+ * Trims trailing slashes (if any) from a string.
+ * @param value The string value to be trimmed. Cannot be null.
+ * @return String value without trailing slashes.
+ */
+ public static String trimTrailingSlashes(String value) {
+ return value.replaceAll("/*$", "");
+ }
+
}
diff --git a/shared/tests/src/com/vaadin/shared/util/SharedUtilTests.java b/shared/tests/src/com/vaadin/shared/util/SharedUtilTests.java
new file mode 100644
index 0000000000..b593032bd6
--- /dev/null
+++ b/shared/tests/src/com/vaadin/shared/util/SharedUtilTests.java
@@ -0,0 +1,43 @@
+package com.vaadin.shared.util;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class SharedUtilTests {
+
+ private SharedUtil sut;
+
+ @Before
+ public void setup() {
+ sut = new SharedUtil();
+ }
+
+ @Test
+ public void trailingSlashIsTrimmed() {
+ assertThat(sut.trimTrailingSlashes("/path/"), is("/path"));
+ }
+
+ @Test
+ public void noTrailingSlashForTrimming() {
+ assertThat(sut.trimTrailingSlashes("/path"), is("/path"));
+ }
+
+ @Test
+ public void trailingSlashesAreTrimmed() {
+ assertThat(sut.trimTrailingSlashes("/path///"), is("/path"));
+ }
+
+ @Test
+ public void emptyStringIsHandled() {
+ assertThat(sut.trimTrailingSlashes(""), is(""));
+ }
+
+ @Test
+ public void rootSlashIsTrimmed() {
+ assertThat(sut.trimTrailingSlashes("/"), is(""));
+ }
+
+}