use of com.azure.android.core.http.HttpHeaders in project azure-sdk-for-android by Azure.
the class RestProxyTests method getRequestWithHeaderParametersAndAnythingReturn.
@Test
public void getRequestWithHeaderParametersAndAnythingReturn() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service7.class).getAnything("A", 15, new Callback<Response<HttpBinJSON>>() {
@Override
public void onSuccess(Response<HttpBinJSON> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "getRequestWithHeaderParametersAndAnythingReturn");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
Assertions.assertNotNull(response);
HttpBinJSON json = response.getValue();
assertNotNull(json);
assertMatchWithHttpOrHttps("localhost/anything", json.url());
assertNotNull(json.headers());
final HttpHeaders headers = new HttpHeaders(json.headers());
assertEquals("A", headers.getValue("A"));
assertArrayEquals(new String[] { "A" }, headers.getValues("A"));
assertEquals("15", headers.getValue("B"));
assertArrayEquals(new String[] { "15" }, headers.getValues("B"));
}
}
use of com.azure.android.core.http.HttpHeaders in project azure-sdk-for-android by Azure.
the class RestProxyTests method headersRequest.
@Test
public void headersRequest() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service13.class).get(new Callback<Response<HttpBinJSON>>() {
@Override
public void onSuccess(Response<HttpBinJSON> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "headersRequest");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
Assertions.assertNotNull(response);
Assertions.assertNotNull(response.getValue());
HttpBinJSON json = response.getValue();
assertNotNull(json);
assertMatchWithHttpOrHttps("localhost/anything", json.url());
assertNotNull(json.headers());
final HttpHeaders headers = new HttpHeaders(json.headers());
assertEquals("MyHeaderValue", headers.getValue("MyHeader"));
assertArrayEquals(new String[] { "MyHeaderValue" }, headers.getValues("MyHeader"));
assertEquals("My,Header,Value", headers.getValue("MyOtherHeader"));
assertArrayEquals(new String[] { "My", "Header", "Value" }, headers.getValues("MyOtherHeader"));
}
}
use of com.azure.android.core.http.HttpHeaders in project azure-sdk-for-android by Azure.
the class RestProxyTests method service20GetResponseBody.
@Test
public void service20GetResponseBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service20.class).putBody("body string", new Callback<Response<HttpBinJSON>>() {
@Override
public void onSuccess(Response<HttpBinJSON> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "service20GetResponseBody");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
assertNotNull(response);
assertEquals(200, response.getStatusCode());
final HttpBinJSON body = response.getValue();
assertNotNull(body);
assertMatchWithHttpOrHttps("localhost/put", body.url());
assertEquals("body string", body.data());
final HttpHeaders headers = response.getHeaders();
assertNotNull(headers);
}
}
use of com.azure.android.core.http.HttpHeaders in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method knownError.
@Test
public void knownError() throws Throwable {
Class<KnownErrorMethods> clazz = KnownErrorMethods.class;
Method getError409Method = clazz.getDeclaredMethod("getError409", Callback.class);
HttpResponseMapper mapper = new HttpResponseMapper(getError409Method, extractCallbackType(getError409Method), logger);
ErrorData409 errorData409 = new ErrorData409(677, "retry after 10 sec");
JacksonSerder jacksonSerder = new JacksonSerder();
String wireErrorData409 = jacksonSerder.serialize(errorData409, SerdeEncoding.JSON);
MockHttpResponse httpResponse = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 409, new HttpHeaders(), wireErrorData409.getBytes());
Retry409Exception ex = null;
try {
mapper.map(httpResponse, jacksonSerder);
} catch (Retry409Exception e) {
ex = e;
}
assertNotNull(ex);
assertNotNull(ex.getValue());
ErrorData409 receivedErrorData409 = ex.getValue();
assertEquals(errorData409.getCode(), receivedErrorData409.getCode());
assertEquals(errorData409.getMessage(), receivedErrorData409.getMessage());
}
use of com.azure.android.core.http.HttpHeaders in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method unixTimeEncodedContent.
@Test
public void unixTimeEncodedContent() throws Throwable {
Class<UnixTimeEncodedContentMethods> clazz = UnixTimeEncodedContentMethods.class;
Method unixTimeMethod = clazz.getDeclaredMethod("unixTime", Callback.class);
HttpResponseMapper mapperUnixTime = new HttpResponseMapper(unixTimeMethod, extractCallbackType(unixTimeMethod), logger);
JacksonSerder jacksonSerder = new JacksonSerder();
OffsetDateTime offsetDateTime = OffsetDateTime.parse("1980-01-01T10:00:00Z");
UnixTime unixTime = new UnixTime(offsetDateTime);
String wireUnixTimeJsonNumber = unixTime.toString();
MockHttpResponse httpResponseUnixTime = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireUnixTimeJsonNumber.getBytes());
Response<OffsetDateTime> restResponseUnixTime = (Response<OffsetDateTime>) mapperUnixTime.map(httpResponseUnixTime, jacksonSerder);
OffsetDateTime dateTimeReceived = restResponseUnixTime.getValue();
assertNotNull(dateTimeReceived);
assertEquals(0, dateTimeReceived.compareTo(offsetDateTime));
}
Aggregations