use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service19PutWithBodyParamApplicationOctetStreamContentTypeAndStringBodyWithEmptyBody.
@Test
public void service19PutWithBodyParamApplicationOctetStreamContentTypeAndStringBodyWithEmptyBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithBodyParamApplicationOctetStreamContentTypeAndStringBody("", 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, "service19PutWithBodyParamApplicationOctetStreamContentTypeAndStringBodyWithEmptyBody");
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 getRequestWithNullQueryParameter.
@Test
public void getRequestWithNullQueryParameter() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service6.class).getAnything(null, 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, "getRequestWithNullQueryParameter");
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?b=15", json.url());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service19PutWithNoContentTypeAndStringBodyWithEmptyBody.
@Test
public void service19PutWithNoContentTypeAndStringBodyWithEmptyBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithNoContentTypeAndStringBody("", 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, "service19PutWithNoContentTypeAndStringBodyWithEmptyBody");
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 service19PutWithBodyParamApplicationJsonContentTypeAndByteArrayBodyWithNonEmptyBody.
@Test
public void service19PutWithBodyParamApplicationJsonContentTypeAndByteArrayBodyWithNonEmptyBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithBodyParamApplicationJsonContentTypeAndByteArrayBody(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, "service19PutWithBodyParamApplicationJsonContentTypeAndByteArrayBodyWithNonEmptyBody");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
HttpBinJSON json = response.getValue();
Assertions.assertNotNull(json);
assertEquals("\"AAECAwQ=\"", json.data());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method simpleDownloadResponseTest.
@Test
public void simpleDownloadResponseTest() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<InputStream> cbResult = new CallbackResult<>();
createService(DownloadService.class).getBytesStream(new Callback<Response<InputStream>>() {
@Override
public void onSuccess(Response<InputStream> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "simpleDownloadResponseTest");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<InputStream> response = cbResult.response;
assertNotNull(response);
assertEquals(200, response.getStatusCode());
InputStream stream = response.getValue();
assertNotNull(stream);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
int nRead;
byte[] data = new byte[1024];
while ((nRead = stream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
} catch (IOException e) {
fail(e);
} finally {
try {
stream.close();
} catch (IOException e) {
fail(e);
}
}
byte[] byteArray = buffer.toByteArray();
assertEquals(30720, byteArray.length);
}
}
Aggregations