From 19f7bc37df2874ccf6349028c970204bbeac1373 Mon Sep 17 00:00:00 2001 From: alpar Date: Tue, 19 Feb 2013 21:01:40 +0100 Subject: [PATCH] open is browser fails in case the protocol is not provided in sonar configuration --- .../ide/intellij/actions/SonarNavigator.java | 8 +++---- .../intellij/actions/SonarNavigatorTest.java | 12 +++++++--- .../ide/intellij/utils/SonarUtilsTest.java | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/test/java/org/sonar/ide/intellij/utils/SonarUtilsTest.java diff --git a/src/main/java/org/sonar/ide/intellij/actions/SonarNavigator.java b/src/main/java/org/sonar/ide/intellij/actions/SonarNavigator.java index dd03c9e..d51a43f 100644 --- a/src/main/java/org/sonar/ide/intellij/actions/SonarNavigator.java +++ b/src/main/java/org/sonar/ide/intellij/actions/SonarNavigator.java @@ -2,11 +2,12 @@ import com.intellij.ide.BrowserUtil; import org.sonar.ide.intellij.component.SonarModuleComponent; +import org.sonar.ide.intellij.utils.SonarUtils; public class SonarNavigator { - protected static final String RESOURCE_PATH = "dashboard/index/"; + protected static final String RESOURCE_PATH = "/dashboard/index/"; public void navigateToDashboard(SonarModuleComponent sonarModuleComponent, String resourceId) { @@ -17,9 +18,6 @@ public void navigateToDashboard(SonarModuleComponent sonarModuleComponent, Strin } protected static String generateUrl(String host, String resourceId) { - if (!host.endsWith("/")) { - host += "/"; - } - return host + RESOURCE_PATH + resourceId; + return SonarUtils.fixHostName(host) + RESOURCE_PATH + resourceId; } } \ No newline at end of file diff --git a/src/test/java/org/sonar/ide/intellij/actions/SonarNavigatorTest.java b/src/test/java/org/sonar/ide/intellij/actions/SonarNavigatorTest.java index 6fd1714..683cc58 100644 --- a/src/test/java/org/sonar/ide/intellij/actions/SonarNavigatorTest.java +++ b/src/test/java/org/sonar/ide/intellij/actions/SonarNavigatorTest.java @@ -2,7 +2,6 @@ import junit.framework.Assert; import org.junit.Test; -import org.sonar.ide.intellij.actions.SonarNavigator; public class SonarNavigatorTest { @@ -10,14 +9,21 @@ public class SonarNavigatorTest { public void testUrlGeneratorWithoutSlash() { String url = SonarNavigator.generateUrl("localhost", "123"); - Assert.assertEquals("localhost/" + SonarNavigator.RESOURCE_PATH + "123", url); + Assert.assertEquals("http://localhost" + SonarNavigator.RESOURCE_PATH + "123", url); } @Test public void testUrlGeneratorWithSlash() { String url = SonarNavigator.generateUrl("localhost/", "123"); - Assert.assertEquals("localhost/" + SonarNavigator.RESOURCE_PATH + "123", url); + Assert.assertEquals("http://localhost" + SonarNavigator.RESOURCE_PATH + "123", url); } + @Test + public void testUrlGeneratorWithProtocol() throws Exception { + String url = SonarNavigator.generateUrl("http://localhost/", "123"); + + Assert.assertEquals("http://localhost" + SonarNavigator.RESOURCE_PATH + "123", url); + + } } diff --git a/src/test/java/org/sonar/ide/intellij/utils/SonarUtilsTest.java b/src/test/java/org/sonar/ide/intellij/utils/SonarUtilsTest.java new file mode 100644 index 0000000..e1bfc38 --- /dev/null +++ b/src/test/java/org/sonar/ide/intellij/utils/SonarUtilsTest.java @@ -0,0 +1,24 @@ +package org.sonar.ide.intellij.utils; + + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class SonarUtilsTest { + + @Test + public void testProtocolIsAdded() throws Exception { + assertEquals("http://localhost:8080", SonarUtils.fixHostName("localhost:8080")); + } + + @Test + public void testExtraEndSlashIsRemoved() throws Exception { + assertEquals("http://localhost:8080", SonarUtils.fixHostName("http://localhost:8080/")); + } + + @Test + public void testProtocolIsPreserved() throws Exception { + assertEquals("abc://localhost:8080", SonarUtils.fixHostName("abc://localhost:8080/")); + } +}