From 22eeadcf39067835dbd2ec2a30ecec4c205a5be1 Mon Sep 17 00:00:00 2001 From: Subhas Dandapani Date: Tue, 12 Feb 2013 17:16:45 +0300 Subject: [PATCH] Subhas/Faris | Set HTTP Socket and Connection timeout Conflicts: RapidFTR-Android/src/test/java/com/rapidftr/utils/http/FluentRequestTest.java --- .../com/rapidftr/utils/http/FluentRequest.java | 1 + .../com/rapidftr/utils/http/FluentRequestTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/RapidFTR-Android/src/main/java/com/rapidftr/utils/http/FluentRequest.java b/RapidFTR-Android/src/main/java/com/rapidftr/utils/http/FluentRequest.java index 80f86c3f..5f597477 100644 --- a/RapidFTR-Android/src/main/java/com/rapidftr/utils/http/FluentRequest.java +++ b/RapidFTR-Android/src/main/java/com/rapidftr/utils/http/FluentRequest.java @@ -100,6 +100,7 @@ public FluentRequest context(Context context) { this.context = context; host(getBaseUrl(context)); config(HttpConnectionParams.CONNECTION_TIMEOUT, getConnectionTimeout(context)); + config(HttpConnectionParams.SO_TIMEOUT, getConnectionTimeout(context)); return this; } diff --git a/RapidFTR-Android/src/test/java/com/rapidftr/utils/http/FluentRequestTest.java b/RapidFTR-Android/src/test/java/com/rapidftr/utils/http/FluentRequestTest.java index 86d20333..71995450 100644 --- a/RapidFTR-Android/src/test/java/com/rapidftr/utils/http/FluentRequestTest.java +++ b/RapidFTR-Android/src/test/java/com/rapidftr/utils/http/FluentRequestTest.java @@ -10,6 +10,7 @@ import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.ByteArrayBody; import org.apache.http.entity.mime.content.ContentBody; +import org.apache.http.params.HttpConnectionParams; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.json.JSONException; import org.junit.Before; @@ -108,6 +109,19 @@ public void testBaseUrlFromContext() throws IOException { assertThat(http.path("/test").context(context).get(), equalTo(response)); } + @Test + public void testTimeoutFromContext() { + Context context = mock(Context.class); + FluentRequest http = spy(http()); + + doReturn("example.com").when(http).getBaseUrl(context); + doReturn(1234).when(http).getConnectionTimeout(context); + + http.context(context); + verify(http).config(HttpConnectionParams.CONNECTION_TIMEOUT, 1234); + verify(http).config(HttpConnectionParams.SO_TIMEOUT, 1234); + } + @Test public void testGetShouldCallExecute() throws IOException { FluentRequest http = spy(http().host("test"));