Showing
2 changed files
with
20 additions
and
16 deletions
| @@ -6,17 +6,18 @@ import java.net.URISyntaxException; | @@ -6,17 +6,18 @@ import java.net.URISyntaxException; | ||
| 6 | public class URIUtils { | 6 | public class URIUtils { | 
| 7 | // -------------------------- STATIC METHODS -------------------------- | 7 | // -------------------------- STATIC METHODS -------------------------- | 
| 8 | 8 | ||
| 9 | - public static URI buildURI(URI base, String path) | ||
| 10 | - { | ||
| 11 | - return buildURI(base, path, null); | ||
| 12 | - } | 9 | + public static URI buildURI(URI base, String path) | 
| 10 | + { | ||
| 11 | + return buildURI(base, path, null); | ||
| 12 | + } | ||
| 13 | 13 | ||
| 14 | - public static URI buildURI(URI base, String path, String query) | ||
| 15 | - { | ||
| 16 | - try { | ||
| 17 | - return new URI(base.getScheme(), base.getHost(), base.getPath().replaceAll("/+$", "") + path, query, null); | ||
| 18 | - } catch (URISyntaxException e) { | ||
| 19 | - throw new RuntimeException(e); | 14 | + public static URI buildURI(URI base, String path, String query) | 
| 15 | + { | ||
| 16 | + try { | ||
| 17 | + return new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath().replaceAll("/+$", "") + path, query, | ||
| 18 | + base.getFragment()); | ||
| 19 | + } catch (URISyntaxException e) { | ||
| 20 | + throw new RuntimeException(e); | ||
| 21 | + } | ||
| 20 | } | 22 | } | 
| 21 | - } | ||
| 22 | } | 23 | } | 
| @@ -17,16 +17,19 @@ public class URIUtilsTest { | @@ -17,16 +17,19 @@ public class URIUtilsTest { | ||
| 17 | public void buildURI() throws URISyntaxException | 17 | public void buildURI() throws URISyntaxException | 
| 18 | { | 18 | { | 
| 19 | // Given | 19 | // Given | 
| 20 | - final URI base = new URI("http://localhost:8080/youtrack/"); | 20 | + final URI baseA = new URI("http://localhost:8080/youtrack/"); | 
| 21 | + final URI baseB = new URI("http://localhost/youtrack/"); | ||
| 21 | final String pathA = "/rest/admin/bundle/QA note types"; | 22 | final String pathA = "/rest/admin/bundle/QA note types"; | 
| 22 | final String queryA = "q=" + Filter.stateFilter(StateValues.NotWontFix).maxResults(20); | 23 | final String queryA = "q=" + Filter.stateFilter(StateValues.NotWontFix).maxResults(20); | 
| 23 | 24 | ||
| 24 | // When | 25 | // When | 
| 25 | - final URI uriA = URIUtils.buildURI(base, pathA); | ||
| 26 | - final URI uriB = URIUtils.buildURI(base, pathA, queryA); | 26 | + final URI uriA = URIUtils.buildURI(baseA, pathA); | 
| 27 | + final URI uriB = URIUtils.buildURI(baseA, pathA, queryA); | ||
| 28 | + final URI uriC = URIUtils.buildURI(baseB, pathA, queryA); | ||
| 27 | 29 | ||
| 28 | // Then | 30 | // Then | 
| 29 | - assertEquals("http://localhost/youtrack/rest/admin/bundle/QA%20note%20types", uriA.toString()); | ||
| 30 | - assertEquals("http://localhost/youtrack/rest/admin/bundle/QA%20note%20types?q=state:-%7BWon't%20fix%7D&max=20", uriB.toString()); | 31 | + assertEquals("http://localhost:8080/youtrack/rest/admin/bundle/QA%20note%20types", uriA.toString()); | 
| 32 | + assertEquals("http://localhost:8080/youtrack/rest/admin/bundle/QA%20note%20types?q=state:-%7BWon't%20fix%7D&max=20", uriB.toString()); | ||
| 33 | + assertEquals("http://localhost/youtrack/rest/admin/bundle/QA%20note%20types?q=state:-%7BWon't%20fix%7D&max=20", uriC.toString()); | ||
| 31 | } | 34 | } | 
| 32 | } | 35 | } | 
Please
register
or
login
to post a comment