-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce #createRequest(URI, JSONObject, UsernamePasswordCredentials)
Goal is to create a simpler contract for alternative clients to implement.
- Loading branch information
Showing
4 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/org/jenkinsci/plugins/stashNotifier/BuildStatusUriFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.jenkinsci.plugins.stashNotifier; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.net.URI; | ||
|
||
public class BuildStatusUriFactory { | ||
private BuildStatusUriFactory() { | ||
} | ||
|
||
public static URI create(String baseUri, String commit) { | ||
String tidyBase = StringUtils.removeEnd(baseUri.toString(), "/"); | ||
String uri = String.join("/", tidyBase, "rest/build-status/1.0/commits", commit); | ||
return URI.create(uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/java/org/jenkinsci/plugins/stashNotifier/BuildStatusUriFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.jenkinsci.plugins.stashNotifier; | ||
|
||
import org.junit.Test; | ||
|
||
import java.net.URI; | ||
|
||
import static org.hamcrest.core.IsEqual.equalTo; | ||
import static org.junit.Assert.*; | ||
|
||
public class BuildStatusUriFactoryTest { | ||
|
||
@Test | ||
public void shouldHandleTrailingSlash() { | ||
String baseUri = "http://localhost:12345/"; | ||
URI expected = URI.create("http://localhost:12345/rest/build-status/1.0/commits/25a4b3c9b494fc7ac65b80e3b0ecce63f235f20d"); | ||
URI actual = BuildStatusUriFactory.create(baseUri, "25a4b3c9b494fc7ac65b80e3b0ecce63f235f20d"); | ||
assertThat(actual, equalTo(expected)); | ||
} | ||
|
||
@Test | ||
public void shouldHandleNoTrailingSlash() { | ||
String baseUri = "http://localhost:12345"; | ||
URI expected = URI.create("http://localhost:12345/rest/build-status/1.0/commits/25a4b3c9b494fc7ac65b80e3b0ecce63f235f20d"); | ||
URI actual = BuildStatusUriFactory.create(baseUri, "25a4b3c9b494fc7ac65b80e3b0ecce63f235f20d"); | ||
assertThat(actual, equalTo(expected)); | ||
} | ||
|
||
@Test | ||
public void shouldHandleBasePathTrailingSlash() { | ||
String baseUri = "http://localhost:12345/some-path/"; | ||
URI expected = URI.create("http://localhost:12345/some-path/rest/build-status/1.0/commits/25a4b3c9b494fc7ac65b80e3b0ecce63f235f20d"); | ||
URI actual = BuildStatusUriFactory.create(baseUri, "25a4b3c9b494fc7ac65b80e3b0ecce63f235f20d"); | ||
assertThat(actual, equalTo(expected)); | ||
} | ||
|
||
@Test | ||
public void shouldHandleBasePathNoTrailingSlash() { | ||
String baseUri = "http://localhost:12345/some-path"; | ||
URI expected = URI.create("http://localhost:12345/some-path/rest/build-status/1.0/commits/25a4b3c9b494fc7ac65b80e3b0ecce63f235f20d"); | ||
URI actual = BuildStatusUriFactory.create(baseUri, "25a4b3c9b494fc7ac65b80e3b0ecce63f235f20d"); | ||
assertThat(actual, equalTo(expected)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters