use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method getRequestWithNoReturn.
@Test
public void getRequestWithNoReturn() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<Void> cbResult = new CallbackResult<>();
createService(Service3.class).getNothing(new Callback<Response<Void>>() {
@Override
public void onSuccess(Response<Void> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "getRequestWithNoReturn");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<Void> response = cbResult.response;
Assertions.assertNotNull(response);
Void value = response.getValue();
assertNull(value);
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service19PutWithNoContentTypeAndByteArrayBodyWithNullBody.
@Test
public void service19PutWithNoContentTypeAndByteArrayBodyWithNullBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithNoContentTypeAndByteArrayBody(null, 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, "service19PutWithNoContentTypeAndByteArrayBodyWithNullBody");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
HttpBinJSON json = response.getValue();
Assertions.assertNotNull(json);
assertEquals("", json.data());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method bytesUploadTest.
@Test
public void bytesUploadTest() throws Exception {
byte[] reqContent = "The quick brown fox jumps over the lazy dog".getBytes();
final HttpClient httpClient = createHttpClient();
// Scenario: Log the body so that body buffering/replay behavior is exercised.
//
// Order in which policies applied will be the order in which they added to builder
//
final HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient).policies(new PortPolicy(getWireMockPort(), true), new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))).build();
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
RestProxy.create(BytesUploadService.class, httpPipeline, SERIALIZER).put(reqContent, reqContent.length, 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, "bytesUploadTest");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
assertEquals("The quick brown fox jumps over the lazy dog", response.getValue().data());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service19PutWithBodyParamApplicationOctetStreamContentTypeAndByteArrayBodyWithNonEmptyBody.
@Test
public void service19PutWithBodyParamApplicationOctetStreamContentTypeAndByteArrayBodyWithNonEmptyBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithBodyParamApplicationOctetStreamContentTypeAndByteArrayBody(new byte[] { 0, 1, 2, 3, 4 }, 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, "service19PutWithBodyParamApplicationOctetStreamContentTypeAndByteArrayBodyWithEmptyBody");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
HttpBinJSON json = response.getValue();
Assertions.assertNotNull(json);
assertEquals(new String(new byte[] { 0, 1, 2, 3, 4 }), json.data());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method getRequestWithAnythingWithPathParamWithSpace.
@Test
public void getRequestWithAnythingWithPathParamWithSpace() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service5.class).getAnythingWithPathParam("with path param", 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, "getRequestWithAnythingWithPathParamWithSpace");
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/with path param", json.url());
}
}
Aggregations