Skip to content

Commit

Permalink
fix doc bug, added 204 test, fixed 204 issue with ananomous inner class
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonfagerberg-toast committed Oct 12, 2021
1 parent 5e5cd0d commit 378e3ff
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/com/auth0/client/mgmt/JobsEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
import com.auth0.net.Request;
import com.auth0.utils.Asserts;
import com.fasterxml.jackson.core.type.TypeReference;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import okhttp3.ResponseBody;

/**
* Class that provides an implementation of the Jobs methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Jobs
Expand Down Expand Up @@ -73,8 +76,17 @@ public Request<List<JobErrorDetails>> getErrorDetails(String jobId) {
.build()
.toString();

CustomRequest<List<JobErrorDetails>> request = new CustomRequest<>(client, url, "GET", new TypeReference<List<JobErrorDetails>>() {
});
TypeReference<List<JobErrorDetails>> jobErrorDetailsListType = new TypeReference<List<JobErrorDetails>>() {
};
CustomRequest<List<JobErrorDetails>> request = new CustomRequest<List<JobErrorDetails>>(client, url, "GET", jobErrorDetailsListType) {
@Override
protected List<JobErrorDetails> readResponseBody(ResponseBody body) throws IOException {
if (body.contentLength() == 0) {
return Collections.emptyList();
}
return super.readResponseBody(body);
}
};
request.addHeader("Authorization", "Bearer " + apiToken);
return request;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/auth0/net/CustomRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ protected RequestBody createRequestBody() throws IOException {

@Override
protected T readResponseBody(ResponseBody body) throws IOException {
if (body.contentLength() == 0) {
return null;
}
String payload = body.string();
return mapper.readValue(payload, tType);
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/auth0/client/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ public void jsonResponse(String path, int statusCode) throws IOException {
server.enqueue(response);
}

public void noContentResponse() {
MockResponse response = new MockResponse()
.setResponseCode(204)
.addHeader("Content-Type", "application/json")
.setBody("");
server.enqueue(response);
}

public void rateLimitReachedResponse(long limit, long remaining, long reset) {
MockResponse response = new MockResponse().setResponseCode(429);
if (limit != -1) {
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/auth0/client/mgmt/JobsEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ public void shouldGetJobErrorDetails() throws Exception {
assertThat(response.get(0).getErrors(), hasSize(1));
}

@Test
public void shouldGetJobErrorDetails_noErrors() throws Exception {
Request<List<JobErrorDetails>> request = api.jobs().getErrorDetails("1");
assertThat(request, is(notNullValue()));

server.noContentResponse();
List<JobErrorDetails> response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();

assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/jobs/1/errors"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));

assertThat(response, is(notNullValue()));
assertThat(response, is(empty()));
}

@Test
public void shouldThrowOnRequestUsersExportWithNullConnectionId() {
exception.expect(IllegalArgumentException.class);
Expand Down

0 comments on commit 378e3ff

Please sign in to comment.