mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 18:51:10 +01:00
added some uri util methods
This commit is contained in:
@@ -260,4 +260,42 @@ public class HttpUtil
|
|||||||
{
|
{
|
||||||
return uri.substring(request.getContextPath().length());
|
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
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -104,13 +120,30 @@ public class HttpUtilTest
|
|||||||
assertEquals("/test/path", HttpUtil.getStrippedURI(request));
|
assertEquals("/test/path", HttpUtil.getStrippedURI(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void getCompleteUrlTest()
|
public void getUriWithoutEndSeperatorTest()
|
||||||
{
|
{
|
||||||
ScmConfiguration config = new ScmConfiguration();
|
assertEquals("/test", HttpUtil.getUriWithoutEndSeperator("/test/"));
|
||||||
config.setBaseUrl("http://www.scm-manager.org/scm");
|
assertEquals("/test/two", HttpUtil.getUriWithoutEndSeperator("/test/two/"));
|
||||||
|
assertEquals("/test/two/three",
|
||||||
|
HttpUtil.getUriWithoutEndSeperator("/test/two/three"));
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@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