use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class EmptyBodyRequestTest method setUp.
@Before
public void setUp() throws Exception {
server = new MockServer();
client = new OkHttpClient();
tokenHolderType = new TypeReference<TokenHolder>() {
};
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldAddMultipleParts.
@Test
public void shouldAddMultipleParts() throws Exception {
String boundary = UUID.randomUUID().toString();
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder(boundary);
MultipartRequest<TokenHolder> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", new ObjectMapper(), tokenHolderType, bodyBuilder);
File fileValue = new File(MULTIPART_SAMPLE);
request.addPart("keyName", "keyValue");
request.addPart("jsonFile", fileValue, "text/json");
server.jsonResponse(AUTH_TOKENS, 200);
request.execute();
RecordedRequest recordedRequest = server.takeRequest();
RecordedMultipartRequest recordedMultipartRequest = new RecordedMultipartRequest(recordedRequest);
assertThat(recordedMultipartRequest.getPartsCount(), is(2));
assertThat(recordedMultipartRequest.getBoundary(), is(boundary));
KeyValuePart formParam = recordedMultipartRequest.getKeyValuePart("keyName");
assertThat(formParam, is(notNullValue()));
assertThat(formParam.getValue(), is("keyValue"));
FilePart jsonFile = recordedMultipartRequest.getFilePart("jsonFile");
assertThat(jsonFile, is(notNullValue()));
String utf8Contents = new String(Files.readAllBytes(fileValue.toPath()));
assertThat(jsonFile.getContentType(), is("text/json"));
assertThat(jsonFile.getFilename(), is("multipart_sample.json"));
assertThat(jsonFile.getValue(), is(utf8Contents));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldParseJSONErrorResponseWithErrorDescription.
@Test
public void shouldParseJSONErrorResponseWithErrorDescription() throws Exception {
MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
request.addPart("non_empty", "body");
server.jsonResponse(AUTH_ERROR_WITH_ERROR_DESCRIPTION, 400);
Exception exception = null;
try {
request.execute();
server.takeRequest();
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(APIException.class)));
assertThat(exception.getCause(), is(nullValue()));
assertThat(exception.getMessage(), is("Request failed with status code 400: the connection was not found"));
APIException authException = (APIException) exception;
assertThat(authException.getDescription(), is("the connection was not found"));
assertThat(authException.getError(), is("invalid_request"));
assertThat(authException.getStatusCode(), is(400));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldCreatePOSTRequest.
@Test
public void shouldCreatePOSTRequest() throws Exception {
MultipartRequest<TokenHolder> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", tokenHolderType);
assertThat(request, is(notNullValue()));
request.addPart("non_empty", "body");
server.jsonResponse(AUTH_TOKENS, 200);
TokenHolder execute = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getMethod(), is("POST"));
assertThat(execute, is(notNullValue()));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method setUp.
@Before
public void setUp() throws Exception {
server = new MockServer();
client = new OkHttpClient();
tokenHolderType = new TypeReference<TokenHolder>() {
};
listType = new TypeReference<List>() {
};
voidType = new TypeReference<Void>() {
};
}
Aggregations