Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #12 from sanjoa/encoding-fix

Encoding fix
  • Loading branch information...
commit 881c34de3f12fa2c07a75158272bff3792863ce7 2 parents 72c26ea + 9f3ae70
Pelle Pelster authored
View
26 .gitignore
@@ -1,11 +1,15 @@
-apache-tomcat
-work
-jenkins_home
-nbactions.xml
-release.properties
-target
-*~
-
-
-*.iml
-/.idea
+apache-tomcat
+work
+jenkins_home
+nbactions.xml
+release.properties
+target
+*~
+
+
+*.iml
+/.idea
+.settings
+.project
+.classpath
+pom.xml.releaseBackup
View
6 pom.xml
@@ -58,6 +58,12 @@
<version>1.8</version>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
View
26 src/main/java/de/pellepelster/jenkins/walldisplay/WallDisplayViewAction.java
@@ -1,11 +1,10 @@
package de.pellepelster.jenkins.walldisplay;
-import hudson.FilePath;
import hudson.model.Action;
import hudson.model.Hudson;
-import java.io.File;
-import java.net.URLEncoder;
+
import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
/**
* Action providing the link to the actual walldisplay page
@@ -14,32 +13,39 @@
*/
public class WallDisplayViewAction implements Action {
+ private static final String ENCODING = "UTF-8";
private String viewName;
public WallDisplayViewAction(String viewName) {
this.viewName = viewName;
}
- @Override
public String getIconFileName() {
return "/plugin/jenkinswalldisplay/images/icon.png";
}
- @Override
public String getDisplayName() {
return "Wall Display";
}
- @Override
public String getUrlName() {
String encodedUrl = null;
+ String encodedViewName = null;
+ String rootUrl = getRootUrl();
try {
- encodedUrl = URLEncoder.encode(Hudson.getInstance().getRootUrl(), "UTF-8");
+ encodedUrl = URLEncoder.encode(rootUrl, ENCODING);
+ encodedViewName = URLEncoder.encode(viewName, ENCODING);
} catch (UnsupportedEncodingException e) {
- encodedUrl = Hudson.getInstance().getRootUrl();
+ encodedUrl = rootUrl;
+ encodedViewName = viewName;
}
-
- return String.format("%s/plugin/jenkinswalldisplay/walldisplay.html?viewName=%s&jenkinsUrl=%s", Hudson.getInstance().getRootUrl(), viewName, encodedUrl);
+ return String
+ .format("%s/plugin/jenkinswalldisplay/walldisplay.html?viewName=%s&jenkinsUrl=%s",
+ rootUrl, encodedViewName, encodedUrl);
+ }
+
+ protected String getRootUrl() {
+ return Hudson.getInstance().getRootUrl();
}
}
View
68 src/test/java/de/pellepelster/jenkins/walldisplay/WallDisplayViewActionTest.java
@@ -0,0 +1,68 @@
+package de.pellepelster.jenkins.walldisplay;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+
+import org.junit.Test;
+import org.jvnet.hudson.test.HudsonTestCase;
+
+/**
+ * Unit test for WallDisplayViewAction which verifies that the wall-display
+ * URL's are encoded correctly.
+ *
+ * @author Joakim Sandstroem
+ */
+public class WallDisplayViewActionTest extends HudsonTestCase {
+
+ private String rootUrl;
+ private String encodedRootUrl;
+
+ /**
+ * Instantiates a new WallDisplayViewAction with a stubbed root URL
+ *
+ * @param viewName
+ * view name during test
+ * @return a new WallDisplayViewAction instance
+ * @throws IOException
+ */
+ public WallDisplayViewAction newAction(String viewName) throws IOException {
+ WallDisplayViewAction action = spy(new WallDisplayViewAction(viewName));
+ rootUrl = getURL().toExternalForm();
+ encodedRootUrl = URLEncoder.encode(rootUrl, "UTF-8");
+ doReturn(rootUrl).when(action).getRootUrl();
+ return action;
+ }
+
+ /**
+ * Verifies that the wall-display link for the 'All' view name is correct.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testGetUrlNameAllView() throws IOException {
+ WallDisplayViewAction action = newAction("All");
+ assertEquals(
+ rootUrl
+ + "/plugin/jenkinswalldisplay/walldisplay.html?viewName=All&jenkinsUrl="
+ + encodedRootUrl, action.getUrlName());
+ }
+
+ /**
+ * Verifies that the wall-display link for a view with special characters is
+ * encoded correctly.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testGetUrlNameEncodedView() throws IOException {
+ WallDisplayViewAction action = newAction("+Dashboard");
+ assertEquals(
+ rootUrl
+ + "/plugin/jenkinswalldisplay/walldisplay.html?viewName=%2BDashboard&jenkinsUrl="
+ + encodedRootUrl, action.getUrlName());
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.