Skip to content

Commit

Permalink
Merge pull request #26 from ggili/master
Browse files Browse the repository at this point in the history
Bugfix for issue #23 : Not providing the http:// protocol
  • Loading branch information
gshakhn committed Feb 20, 2013
2 parents 62e19b3 + 19f7bc3 commit da7f688
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

import junit.framework.Assert;
import org.junit.Test;
import org.sonar.ide.intellij.actions.SonarNavigator;

public class SonarNavigatorTest {

@Test
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);

}
}
24 changes: 24 additions & 0 deletions src/test/java/org/sonar/ide/intellij/utils/SonarUtilsTest.java
Original file line number Diff line number Diff line change
@@ -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/"));
}
}

0 comments on commit da7f688

Please sign in to comment.