use of com.android.volley.NetworkResponse in project FastDev4Android by jiangqqlmj.
the class JsonRequestCharsetTest method defaultCharsetJsonObject.
@Test
public void defaultCharsetJsonObject() throws Exception {
// UTF-8 is default charset for JSON
byte[] data = jsonObjectString().getBytes(Charset.forName("UTF-8"));
NetworkResponse network = new NetworkResponse(data);
JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);
assertNotNull(objectResponse);
assertTrue(objectResponse.isSuccess());
assertEquals(TEXT_VALUE, objectResponse.result.getString(TEXT_NAME));
assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
use of com.android.volley.NetworkResponse in project FastDev4Android by jiangqqlmj.
the class JsonRequestCharsetTest method specifiedCharsetJsonObject.
@Test
public void specifiedCharsetJsonObject() throws Exception {
byte[] data = jsonObjectString().getBytes(Charset.forName("ISO-8859-1"));
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=iso-8859-1");
NetworkResponse network = new NetworkResponse(data, headers);
JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);
assertNotNull(objectResponse);
assertTrue(objectResponse.isSuccess());
//don't check the text in Czech, ISO-8859-1 doesn't support some Czech characters
assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
use of com.android.volley.NetworkResponse in project FastDev4Android by jiangqqlmj.
the class JsonRequestCharsetTest method specifiedCharsetJsonArray.
@Test
public void specifiedCharsetJsonArray() throws Exception {
byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=iso-8859-2");
NetworkResponse network = new NetworkResponse(data, headers);
JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);
assertNotNull(arrayResponse);
assertTrue(arrayResponse.isSuccess());
assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
// don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
use of com.android.volley.NetworkResponse in project FastDev4Android by jiangqqlmj.
the class HttpHeaderParserTest method setUp.
@Before
public void setUp() throws Exception {
headers = new HashMap<String, String>();
response = new NetworkResponse(0, null, headers, false);
}
use of com.android.volley.NetworkResponse in project android-volley by mcxiaoke.
the class BasicNetworkTest method headersAndPostParams.
@Test
public void headersAndPostParams() throws Exception {
MockHttpStack mockHttpStack = new MockHttpStack();
BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 200, "OK");
fakeResponse.setEntity(new StringEntity("foobar"));
mockHttpStack.setResponseToReturn(fakeResponse);
BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
Request<String> request = new Request<String>(Request.Method.GET, "http://foo", null) {
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
return null;
}
@Override
protected void deliverResponse(String response) {
}
@Override
public Map<String, String> getHeaders() {
Map<String, String> result = new HashMap<String, String>();
result.put("requestheader", "foo");
return result;
}
@Override
public Map<String, String> getParams() {
Map<String, String> result = new HashMap<String, String>();
result.put("requestpost", "foo");
return result;
}
};
httpNetwork.performRequest(request);
assertEquals("foo", mockHttpStack.getLastHeaders().get("requestheader"));
assertEquals("requestpost=foo&", new String(mockHttpStack.getLastPostBody()));
}
Aggregations