Skip to content

Commit

Permalink
Merge branch 'main' into fix-getting-shared-items
Browse files Browse the repository at this point in the history
  • Loading branch information
antusus authored Feb 23, 2024
2 parents 97ece0a + eaea019 commit c3edcf0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/box/sdk/BoxAPIRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class BoxAPIRequest {
private final BoxAPIConnection api;
private final List<RequestHeader> headers;
private final String method;
private final URL url;
private URL url;
private BackoffCounter backoffCounter;
private int connectTimeout;
private int readTimeout;
Expand Down Expand Up @@ -291,6 +291,14 @@ public URL getUrl() {
return this.url;
}

/**
* Sets the URL to the request.
*
*/
public void setUrl(URL url) {
this.url = url;
}

/**
* Gets the http method from the request.
*
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/com/box/sdk/BoxAPIRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,27 @@ public void interceptorCanModifyRequest() {
verify(1, getRequestedFor(urlEqualTo("/")));
}

@Test
public void interceptorCanModifyRequestURL() {
String initialPath = "/";
String modifiedPath = "/2";

stubFor(get(urlEqualTo(initialPath))
.willReturn(aResponse().withStatus(404)));
stubFor(get(urlEqualTo(modifiedPath))
.willReturn(aResponse().withStatus(200).withBody("{\"foo\":\"bar\"}")));

BoxAPIConnection api = createConnectionWith(boxMockUrl().toString());
api.setRequestInterceptor(request -> {
request.setUrl(boxMockUrl(modifiedPath));
return null;
});

new BoxAPIRequest(api, boxMockUrl(), "GET").send();
verify(1, getRequestedFor(urlEqualTo(modifiedPath)));
verify(0, getRequestedFor(urlEqualTo(initialPath)));
}

@Test
public void addsAuthenticationHeaderByDefault() {
stubFor(get(urlEqualTo("/"))
Expand Down Expand Up @@ -334,4 +355,12 @@ private URL boxMockUrl() {
throw new RuntimeException(e);
}
}

private URL boxMockUrl(String path) {
try {
return new URL(format("https://localhost:%d%s", wireMockRule.httpsPort(), path));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit c3edcf0

Please sign in to comment.