Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more test cases for simple and rxjava2 #114

Merged
merged 13 commits into from
Apr 29, 2017
Prev Previous commit
Next Next commit
Add Post String Header Test
  • Loading branch information
amitshekhariitbhu committed Apr 21, 2017
commit 892d220ae8442370df14df18bb52e154c9dbc43a
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,41 @@ public void onError(ANError anError) {
assertEquals(404, errorCodeRef.get().intValue());
}

public void testHeaderPost() throws InterruptedException {

server.enqueue(new MockResponse().setBody("data"));

final AtomicReference<String> responseRef = new AtomicReference<>();
final AtomicReference<String> headerRef = new AtomicReference<>();
final AtomicReference<Boolean> responseBodySuccess = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);

AndroidNetworking.post(server.url("/").toString())
.addHeaders("headerKey", "headerValue")
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.setExecutor(Executors.newSingleThreadExecutor())
.build()
.getAsOkHttpResponseAndString(new OkHttpResponseAndStringRequestListener() {
@Override
public void onResponse(Response okHttpResponse, String response) {
responseRef.set(response);
responseBodySuccess.set(okHttpResponse.isSuccessful());
headerRef.set(okHttpResponse.request().header("headerKey"));
latch.countDown();
}

@Override
public void onError(ANError anError) {
assertTrue(false);
}
});

assertTrue(latch.await(2, SECONDS));

assertTrue(responseBodySuccess.get());
assertEquals("data", responseRef.get());
assertEquals("headerValue", headerRef.get());
}

}