summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAnthony Lee <anthonylee@google.com>2014-01-31 14:04:42 -0800
committerYu Ping Hu <yph@google.com>2014-03-19 23:06:01 +0000
commita5fd5a343a8698978a88c7d8907de19a07fce2ab (patch)
tree2a46f5ee802d62055ba5af36f9580d9b346faac1 /tests
parenta7c199d07e7bac7a430f901267ce3b556ac2fcd4 (diff)
downloadandroid_packages_apps_Exchange-a5fd5a343a8698978a88c7d8907de19a07fce2ab.tar.gz
android_packages_apps_Exchange-a5fd5a343a8698978a88c7d8907de19a07fce2ab.tar.bz2
android_packages_apps_Exchange-a5fd5a343a8698978a88c7d8907de19a07fce2ab.zip
Introduce the ability to dump the wbxml from EAS responses.
Similar to CurlLogger that dumps the base64 represention of the EAS request, WbxmlResponseLogger will dump the base64 representation of responses from the server so that we can easily view the XML payload. Unit tests included. Change-Id: I96e2c2d508ac27002125ee83d307ff7cd75400c7 (cherry picked from commit 17403f2cc87358e7b768cb982921d28694a7932d)
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/exchange/utility/WbxmlResponseLoggerTests.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/src/com/android/exchange/utility/WbxmlResponseLoggerTests.java b/tests/src/com/android/exchange/utility/WbxmlResponseLoggerTests.java
new file mode 100644
index 00000000..29d493b8
--- /dev/null
+++ b/tests/src/com/android/exchange/utility/WbxmlResponseLoggerTests.java
@@ -0,0 +1,83 @@
+/* Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.exchange.utility;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.apache.http.message.BasicHeader;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+/**
+ * Test for {@link WbxmlResponseLogger}.
+ * You can run this entire test case with:
+ * runtest -c com.android.exchange.utility.WbxmlResponseLoggerTests exchange
+ */
+@SmallTest
+public class WbxmlResponseLoggerTests extends TestCase {
+ private static final byte testArray[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x11,};
+
+ public void testShouldLogResponseTooBig() {
+ final long contentSize = WbxmlResponseLogger.MAX_LENGTH + 1;
+ assertEquals(false, WbxmlResponseLogger.shouldLogResponse(contentSize));
+ }
+
+ public void testShouldLogResponseSmallEnough() {
+ final long contentSize = WbxmlResponseLogger.MAX_LENGTH - 1;
+ assertEquals(true, WbxmlResponseLogger.shouldLogResponse(contentSize));
+ }
+
+ public void testProcessContentEncoding() {
+ final String encoding = "US-ASCII";
+ final BasicHeader header = new BasicHeader("content-encoding", encoding);
+ final String outputEncoding = WbxmlResponseLogger.processContentEncoding(header);
+ assertEquals(true, encoding.equals(outputEncoding));
+ }
+
+ public void testProcessContentEncodingNullHeader() {
+ final String encoding = "UTF-8";
+ final String outputEncoding = WbxmlResponseLogger.processContentEncoding(null);
+ assertEquals(true, encoding.equals(outputEncoding));
+ }
+
+ public void testProcessContentEncodingNullValue() {
+ final String encoding = "UTF-8";
+ final BasicHeader header = new BasicHeader("content-encoding", null);
+ final String outputEncoding = WbxmlResponseLogger.processContentEncoding(header);
+ assertEquals(true, encoding.equals(outputEncoding));
+ }
+
+ public void testGetContentAsByteArraySingleBatch() throws IOException {
+ final ByteArrayInputStream bis = new ByteArrayInputStream(testArray);
+ final byte outputBytes[] = WbxmlResponseLogger.getContentAsByteArray(bis,
+ testArray.length);
+ assertEquals(true, Arrays.equals(testArray, outputBytes));
+ }
+
+ public void testGetContentAsByteArrayMultipleBatches() throws IOException {
+ final ByteArrayInputStream bis = new ByteArrayInputStream(testArray);
+ // If we cut the batch size to be half the length of testArray, we force
+ // 2 batches of processing.
+ final byte outputBytes[] = WbxmlResponseLogger.getContentAsByteArray(bis,
+ testArray.length / 2);
+ assertEquals(true, Arrays.equals(testArray, outputBytes));
+ }
+}