Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for issue #23 : Not providing the http:// protocol #26

Merged
merged 1 commit into from
Feb 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/"));
}
}