mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-04 16:19:50 +02:00
added some uri util methods
This commit is contained in:
@@ -260,4 +260,42 @@ public class HttpUtil
|
||||
{
|
||||
return uri.substring(request.getContextPath().length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given uri without ending separator.
|
||||
*
|
||||
*
|
||||
* @param uri - to strip ending separator
|
||||
*
|
||||
* @return the given uri without a ending separator
|
||||
* @since 1.7
|
||||
*/
|
||||
public static String getUriWithoutEndSeperator(String uri)
|
||||
{
|
||||
if (uri.endsWith(SEPARATOR_PATH))
|
||||
{
|
||||
uri = uri.substring(0, uri.length() - 1);
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given uri without leading separator.
|
||||
*
|
||||
*
|
||||
* @param uri - to strip leading separator
|
||||
*
|
||||
* @return the given uri without leading separator
|
||||
* @since 1.7
|
||||
*/
|
||||
public static String getUriWithoutStartSeperator(String uri)
|
||||
{
|
||||
if (uri.startsWith(SEPARATOR_PATH))
|
||||
{
|
||||
uri = uri.substring(1);
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,22 @@ import javax.servlet.http.HttpServletRequest;
|
||||
public class HttpUtilTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void getCompleteUrlTest()
|
||||
{
|
||||
ScmConfiguration config = new ScmConfiguration();
|
||||
|
||||
config.setBaseUrl("http://www.scm-manager.org/scm");
|
||||
assertEquals("http://www.scm-manager.org/scm/test/path",
|
||||
HttpUtil.getCompleteUrl(config, "test/path"));
|
||||
assertEquals("http://www.scm-manager.org/scm/test/path",
|
||||
HttpUtil.getCompleteUrl(config, "/test/path"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -103,14 +119,31 @@ public class HttpUtilTest
|
||||
HttpUtil.getStrippedURI(request, "/scm/test/path"));
|
||||
assertEquals("/test/path", HttpUtil.getStrippedURI(request));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void getCompleteUrlTest()
|
||||
public void getUriWithoutEndSeperatorTest()
|
||||
{
|
||||
ScmConfiguration config = new ScmConfiguration();
|
||||
config.setBaseUrl("http://www.scm-manager.org/scm");
|
||||
|
||||
assertEquals("http://www.scm-manager.org/scm/test/path", HttpUtil.getCompleteUrl(config, "test/path"));
|
||||
assertEquals("http://www.scm-manager.org/scm/test/path", HttpUtil.getCompleteUrl(config, "/test/path"));
|
||||
assertEquals("/test", HttpUtil.getUriWithoutEndSeperator("/test/"));
|
||||
assertEquals("/test/two", HttpUtil.getUriWithoutEndSeperator("/test/two/"));
|
||||
assertEquals("/test/two/three",
|
||||
HttpUtil.getUriWithoutEndSeperator("/test/two/three"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void getUriWithoutStartSeperator()
|
||||
{
|
||||
assertEquals("test/", HttpUtil.getUriWithoutStartSeperator("/test/"));
|
||||
assertEquals("test/two/",
|
||||
HttpUtil.getUriWithoutStartSeperator("/test/two/"));
|
||||
assertEquals("test/two/three",
|
||||
HttpUtil.getUriWithoutStartSeperator("test/two/three"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user