use of com.rx2androidnetworking.model.User in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2GetObjectApiTest method testObjectListGetRequest404.
public void testObjectListGetRequest404() 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.get(server.url("/").toString()).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());
}
use of com.rx2androidnetworking.model.User in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2GetObjectApiTest method testObjectListSingleGetRequest.
public void testObjectListSingleGetRequest() throws InterruptedException {
server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
final AtomicReference<String> firstNameRef = new AtomicReference<>();
final AtomicReference<String> lastNameRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
Rx2AndroidNetworking.get(server.url("/").toString()).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) {
firstNameRef.set(users.get(0).firstName);
lastNameRef.set(users.get(0).lastName);
latch.countDown();
}
@Override
public void onError(@NonNull Throwable throwable) {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertEquals("Amit", firstNameRef.get());
assertEquals("Shekhar", lastNameRef.get());
}
use of com.rx2androidnetworking.model.User in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2GetObjectApiTest method testObjectSingleGetRequest.
public void testObjectSingleGetRequest() throws InterruptedException {
server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
final AtomicReference<String> firstNameRef = new AtomicReference<>();
final AtomicReference<String> lastNameRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
Rx2AndroidNetworking.get(server.url("/").toString()).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) {
firstNameRef.set(user.firstName);
lastNameRef.set(user.lastName);
latch.countDown();
}
@Override
public void onError(@NonNull Throwable throwable) {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertEquals("Amit", firstNameRef.get());
assertEquals("Shekhar", lastNameRef.get());
}
use of com.rx2androidnetworking.model.User in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2PostObjectApiTest method testObjectPostRequest.
public void testObjectPostRequest() throws InterruptedException {
server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
final AtomicReference<String> firstNameRef = new AtomicReference<>();
final AtomicReference<String> lastNameRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final AtomicReference<Boolean> isCompletedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(2);
Rx2AndroidNetworking.post(server.url("/").toString()).addBodyParameter("fistName", "Amit").addBodyParameter("lastName", "Shekhar").build().getObjectObservable(User.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<User>() {
@Override
public void onSubscribe(Disposable d) {
isSubscribedRef.set(true);
}
@Override
public void onNext(User user) {
firstNameRef.set(user.firstName);
lastNameRef.set(user.lastName);
latch.countDown();
}
@Override
public void onError(Throwable e) {
assertTrue(false);
}
@Override
public void onComplete() {
isCompletedRef.set(true);
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertTrue(isCompletedRef.get());
assertEquals("Amit", firstNameRef.get());
assertEquals("Shekhar", lastNameRef.get());
}
use of com.rx2androidnetworking.model.User in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2PostObjectApiTest method testObjectListPostRequest.
public void testObjectListPostRequest() throws InterruptedException {
server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
final AtomicReference<String> firstNameRef = new AtomicReference<>();
final AtomicReference<String> lastNameRef = new AtomicReference<>();
final AtomicReference<Boolean> isSubscribedRef = new AtomicReference<>();
final AtomicReference<Boolean> isCompletedRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(2);
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) {
firstNameRef.set(userList.get(0).firstName);
lastNameRef.set(userList.get(0).lastName);
latch.countDown();
}
@Override
public void onError(Throwable e) {
assertTrue(false);
}
@Override
public void onComplete() {
isCompletedRef.set(true);
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(isSubscribedRef.get());
assertTrue(isCompletedRef.get());
assertEquals("Amit", firstNameRef.get());
assertEquals("Shekhar", lastNameRef.get());
}
Aggregations