use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method postWithExceptionTest.
@Test
public void postWithExceptionTest() {
// given
HttpClientProxy sut = newClientProxy();
PostRequest request = new PostRequest().setConnectTimeout(15000).setEntity(boolean.class).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1.0:18081/greet");
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request, 150000));
// then
Asserts.assertThat(e).isEqualsType(UnknownHostException.class);
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method clientWasNotActiveAtExecute.
@Test
public void clientWasNotActiveAtExecute() {
// given
HttpClientProxy sut = HttpClientProxy.builder().build();
PostRequest request = new PostRequest().setConnectTimeout(15000).setEntity(String.class).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet");
// when
Throwable e = Asserts.assertThrows(() -> sut.execute(request, new RequestCallback<ResponseEntity>() {
public void onException(Exception e) {
}
public void onResponse(ResponseEntity response) {
}
}));
// then
Asserts.assertThat(e).isEqualsType(ClientNotActiveException.class);
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method postTest.
protected static void postTest(HttpClientProxy client) throws Exception {
HelloRequest body = new HelloRequest();
body.setWho("dzung");
RequestEntity entity = RequestEntity.body(body);
PostRequest request = new PostRequest().setURL("http://localhost:8081/").setEntity(entity).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request, 1000);
System.out.println(response);
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method maxCapacity.
@Test
public void maxCapacity() {
// given
HttpClientProxy sut = HttpClientProxy.builder().autoStart(true).requestQueueCapacity(1).threadPoolSize(1).build();
PostRequest request = new PostRequest().setConnectTimeout(15000).setEntity(String.class).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet");
// when
AtomicReference<Throwable> ref = new AtomicReference<>();
Thread[] threads = new Thread[4];
for (int i = 0; i < threads.length; ++i) {
threads[i] = new Thread(() -> {
while (ref.get() == null) {
try {
sut.call(request, 150000);
} catch (Exception e) {
ref.set(e);
}
}
});
}
for (Thread thread : threads) {
thread.start();
}
while (ref.get() == null) {
EzyThreads.sleep(3);
}
// then
Asserts.assertThat(ref.get()).isEqualsType(RequestQueueFullException.class);
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method postJsonTest.
@Test
public void postJsonTest() throws Exception {
// given
HttpClientProxy sut = newClientProxy();
PostRequest request = new PostRequest().setConnectTimeout(15000).setEntity(new TestRequest("Monkey")).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet").setURL(new URL("http://127.0.0.1:18081/greet")).setURL(URI.create("http://127.0.0.1:18081/greet"));
// when
TestResponse actual = sut.call(request, 15000);
// then
TestResponse expectation = new TestResponse("Greet Monkey!");
Asserts.assertEquals(expectation, actual);
sut.close();
sut.stop();
}
Aggregations