use of com.androidnetworking.error.ANError in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2MultipartJSONApiTest method testJSONArraySingleMultipartRequest404.
public void testJSONArraySingleMultipartRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
Rx2AndroidNetworking.upload(server.url("/").toString()).addMultipartParameter("key", "value").build().getJSONArraySingle().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<JSONArray>() {
@Override
public void onSubscribe(@NonNull Disposable disposable) {
isSubscribedRef.set(true);
}
@Override
public void onSuccess(@NonNull JSONArray jsonArray) {
assertTrue(false);
}
@Override
public void onError(@NonNull Throwable e) {
ANError anError = (ANError) e;
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
use of com.androidnetworking.error.ANError in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2MultipartStringApiTest method testStringMultipartRequest404.
public void testStringMultipartRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
Rx2AndroidNetworking.upload(server.url("/").toString()).addMultipartParameter("key", "value").build().getStringObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
isSubscribedRef.set(true);
}
@Override
public void onNext(String response) {
assertTrue(false);
}
@Override
public void onError(Throwable e) {
ANError anError = (ANError) e;
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
@Override
public void onComplete() {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
use of com.androidnetworking.error.ANError in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2PostObjectApiTest method testObjectSinglePostRequest404.
public void testObjectSinglePostRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
Rx2AndroidNetworking.post(server.url("/").toString()).addBodyParameter("fistName", "Amit").addBodyParameter("lastName", "Shekhar").build().getObjectSingle(User.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<User>() {
@Override
public void onSubscribe(@NonNull Disposable disposable) {
isSubscribedRef.set(true);
}
@Override
public void onSuccess(@NonNull User user) {
assertTrue(false);
}
@Override
public void onError(@NonNull Throwable e) {
ANError anError = (ANError) e;
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
use of com.androidnetworking.error.ANError in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2PostObjectApiTest method testObjectListSinglePostRequest404.
public void testObjectListSinglePostRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
Rx2AndroidNetworking.post(server.url("/").toString()).addBodyParameter("fistName", "Amit").addBodyParameter("lastName", "Shekhar").build().getObjectListSingle(User.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<List<User>>() {
@Override
public void onSubscribe(@NonNull Disposable disposable) {
isSubscribedRef.set(true);
}
@Override
public void onSuccess(@NonNull List<User> users) {
assertTrue(false);
}
@Override
public void onError(@NonNull Throwable e) {
ANError anError = (ANError) e;
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
use of com.androidnetworking.error.ANError in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2PostObjectApiTest method testObjectListPostRequest404.
public void testObjectListPostRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
Rx2AndroidNetworking.post(server.url("/").toString()).addBodyParameter("fistName", "Amit").addBodyParameter("lastName", "Shekhar").build().getObjectListObservable(User.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<List<User>>() {
@Override
public void onSubscribe(Disposable d) {
isSubscribedRef.set(true);
}
@Override
public void onNext(List<User> userList) {
assertTrue(false);
}
@Override
public void onError(Throwable e) {
ANError anError = (ANError) e;
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
@Override
public void onComplete() {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
Aggregations