From e1bcb6b042d5d8286332522db79ba4627372cc6e Mon Sep 17 00:00:00 2001 From: Bernard Labno Date: Wed, 21 Nov 2012 12:08:03 +0000 Subject: [PATCH] URIUtils ignores port --- src/main/java/pl/com/it_crowd/youtrack/api/URIUtils.java | 23 ++++++++++++----------- src/test/java/pl/com/it_crowd/youtrack/api/rest/URIUtilsTest.java | 13 ++++++++----- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/URIUtils.java b/src/main/java/pl/com/it_crowd/youtrack/api/URIUtils.java index 378b67c..ffadeef 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/URIUtils.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/URIUtils.java @@ -6,17 +6,18 @@ import java.net.URISyntaxException; public class URIUtils { // -------------------------- STATIC METHODS -------------------------- - public static URI buildURI(URI base, String path) - { - return buildURI(base, path, null); - } + public static URI buildURI(URI base, String path) + { + return buildURI(base, path, null); + } - public static URI buildURI(URI base, String path, String query) - { - try { - return new URI(base.getScheme(), base.getHost(), base.getPath().replaceAll("/+$", "") + path, query, null); - } catch (URISyntaxException e) { - throw new RuntimeException(e); + public static URI buildURI(URI base, String path, String query) + { + try { + return new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath().replaceAll("/+$", "") + path, query, + base.getFragment()); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } } - } } diff --git a/src/test/java/pl/com/it_crowd/youtrack/api/rest/URIUtilsTest.java b/src/test/java/pl/com/it_crowd/youtrack/api/rest/URIUtilsTest.java index bfc6730..f126e47 100644 --- a/src/test/java/pl/com/it_crowd/youtrack/api/rest/URIUtilsTest.java +++ b/src/test/java/pl/com/it_crowd/youtrack/api/rest/URIUtilsTest.java @@ -17,16 +17,19 @@ public class URIUtilsTest { public void buildURI() throws URISyntaxException { // Given - final URI base = new URI("http://localhost:8080/youtrack/"); + final URI baseA = new URI("http://localhost:8080/youtrack/"); + final URI baseB = new URI("http://localhost/youtrack/"); final String pathA = "/rest/admin/bundle/QA note types"; final String queryA = "q=" + Filter.stateFilter(StateValues.NotWontFix).maxResults(20); // When - final URI uriA = URIUtils.buildURI(base, pathA); - final URI uriB = URIUtils.buildURI(base, pathA, queryA); + final URI uriA = URIUtils.buildURI(baseA, pathA); + final URI uriB = URIUtils.buildURI(baseA, pathA, queryA); + final URI uriC = URIUtils.buildURI(baseB, pathA, queryA); // Then - assertEquals("http://localhost/youtrack/rest/admin/bundle/QA%20note%20types", uriA.toString()); - assertEquals("http://localhost/youtrack/rest/admin/bundle/QA%20note%20types?q=state:-%7BWon't%20fix%7D&max=20", uriB.toString()); + assertEquals("http://localhost:8080/youtrack/rest/admin/bundle/QA%20note%20types", uriA.toString()); + assertEquals("http://localhost:8080/youtrack/rest/admin/bundle/QA%20note%20types?q=state:-%7BWon't%20fix%7D&max=20", uriB.toString()); + assertEquals("http://localhost/youtrack/rest/admin/bundle/QA%20note%20types?q=state:-%7BWon't%20fix%7D&max=20", uriC.toString()); } } -- libgit2 0.24.0