diff options
Diffstat (limited to 'core/src/test/java/fi/iki/elonen/integration/GetAndPostIntegrationTest.java')
-rw-r--r-- | core/src/test/java/fi/iki/elonen/integration/GetAndPostIntegrationTest.java | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/core/src/test/java/fi/iki/elonen/integration/GetAndPostIntegrationTest.java b/core/src/test/java/fi/iki/elonen/integration/GetAndPostIntegrationTest.java index d2f5181..eef2f22 100644 --- a/core/src/test/java/fi/iki/elonen/integration/GetAndPostIntegrationTest.java +++ b/core/src/test/java/fi/iki/elonen/integration/GetAndPostIntegrationTest.java @@ -41,6 +41,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ResponseHandler; import org.apache.http.client.entity.UrlEncodedFormEntity; @@ -51,9 +53,11 @@ import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; import org.junit.Test; import fi.iki.elonen.NanoHTTPD; +import fi.iki.elonen.NanoHTTPD.Response.Status; /** * @author Paul S. Hawke (paul.hawke@gmail.com) On: 5/19/13 at 5:36 PM @@ -81,8 +85,11 @@ public class GetAndPostIntegrationTest extends IntegrationTestBase<GetAndPostInt sb.append(';').append(k).append('=').append(parms.get(k)); } } - - return newFixedLengthResponse(sb.toString()); + if ("/chin".equals(uri)) { + return newFixedLengthResponse(Status.OK, "application/octet-stream", sb.toString()); + } else { + return newFixedLengthResponse(sb.toString()); + } } } @@ -160,7 +167,7 @@ public class GetAndPostIntegrationTest extends IntegrationTestBase<GetAndPostInt public void testPostRequestWithMultipartExtremEncodedParameters() throws Exception { this.testServer.response = "testPostRequestWithMultipartEncodedParameters"; - HttpPost httppost = new HttpPost("http://localhost:8192/"); + HttpPost httppost = new HttpPost("http://localhost:8192/chin"); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, "sfsadfasdf", Charset.forName("UTF-8")); reqEntity.addPart("specialString", new StringBody("拖拉图片到浏览器,可以实现预览功能", "text/plain", Charset.forName("UTF-8"))); reqEntity.addPart("gender", new StringBody("图片名称", Charset.forName("UTF-8")) { @@ -171,11 +178,11 @@ public class GetAndPostIntegrationTest extends IntegrationTestBase<GetAndPostInt } }); httppost.setEntity(reqEntity); + HttpResponse response = this.httpclient.execute(httppost); - ResponseHandler<String> responseHandler = new BasicResponseHandler(); - String responseBody = this.httpclient.execute(httppost, responseHandler); + HttpEntity entity = response.getEntity(); + String responseBody = EntityUtils.toString(entity, "UTF-8"); - // assertEquals("POST:testPostRequestWithMultipartEncodedParameters-params=2;age=120;gender=Male", - // responseBody); + assertEquals("POST:testPostRequestWithMultipartEncodedParameters-params=2;gender=图片名称;specialString=拖拉图片到浏览器,可以实现预览功能", responseBody); } } |