@Test public void testNewBody() throws Exception { // Make test command String httpPath = "www.parse.com"; JSONObject jsonParameters = new JSONObject() .put("count", 1) .put("limit", 1); String sessionToken = "sessionToken"; String localId = "localId"; ParseRESTCommand command = new ParseRESTCommand.Builder() .httpPath(httpPath) .jsonParameters(jsonParameters) .method(ParseHttpRequest.Method.GET) .sessionToken(sessionToken) .localId(localId) .build(); ParseByteArrayHttpBody body = (ParseByteArrayHttpBody) command.newBody(null); // Verify body content is correct JSONObject json = new JSONObject(new String(ParseIOUtils.toByteArray(body.getContent()))); assertEquals(1, json.getInt("count")); assertEquals(1, json.getInt("limit")); assertEquals(ParseHttpRequest.Method.GET.toString(), json.getString("_method")); // Verify body content-type is correct assertEquals("application/json", body.getContentType()); }
@Test public void testInitializeWithString() throws IOException { String content = "content"; String contentType = "application/json"; ParseByteArrayHttpBody body = new ParseByteArrayHttpBody(content, contentType); assertArrayEquals(content.getBytes(), ParseIOUtils.toByteArray(body.getContent())); assertEquals(contentType, body.getContentType()); assertEquals(7, body.getContentLength()); }
@Test public void testInitializeWithByteArray() throws IOException { byte[] content = {1, 1, 1, 1, 1}; String contentType = "application/json"; ParseByteArrayHttpBody body = new ParseByteArrayHttpBody(content, contentType); assertArrayEquals(content, ParseIOUtils.toByteArray(body.getContent())); assertEquals(contentType, body.getContentType()); assertEquals(5, body.getContentLength()); }