You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ay...@apache.org on 2014/07/08 10:54:58 UTC
git commit: CAMEL-7584: add and clean up the test
Repository: camel
Updated Branches:
refs/heads/master dff50b33b -> 67105c8e9
CAMEL-7584: add and clean up the test
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/67105c8e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/67105c8e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/67105c8e
Branch: refs/heads/master
Commit: 67105c8e9e6189ba5d10cd7be1df0df8d4b2ba13
Parents: dff50b3
Author: Akitoshi Yoshida <ay...@apache.org>
Authored: Tue Jul 8 10:54:25 2014 +0200
Committer: Akitoshi Yoshida <ay...@apache.org>
Committed: Tue Jul 8 10:54:39 2014 +0200
----------------------------------------------------------------------
.../support/RecordableInputStreamTest.java | 9 +-
.../camel/support/RecordableReaderTest.java | 104 +++++++++++++++++++
2 files changed, 108 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/67105c8e/camel-core/src/test/java/org/apache/camel/support/RecordableInputStreamTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/support/RecordableInputStreamTest.java b/camel-core/src/test/java/org/apache/camel/support/RecordableInputStreamTest.java
index 9599dc1..12c7761 100644
--- a/camel-core/src/test/java/org/apache/camel/support/RecordableInputStreamTest.java
+++ b/camel-core/src/test/java/org/apache/camel/support/RecordableInputStreamTest.java
@@ -19,13 +19,12 @@ package org.apache.camel.support;
import java.io.ByteArrayInputStream;
-import org.junit.Assert;
-import org.junit.Test;
+import junit.framework.TestCase;
/**
*
*/
-public class RecordableInputStreamTest extends Assert {
+public class RecordableInputStreamTest extends TestCase {
private static final byte[] DATA;
static {
@@ -35,7 +34,7 @@ public class RecordableInputStreamTest extends Assert {
DATA[i] = (byte) (i % radix + 0x20);
}
}
- @Test
+
public void testReadAndGetTextsBufferPurge() throws Exception {
RecordableInputStream ris = new RecordableInputStream(new ByteArrayInputStream(DATA), "utf-8");
assertEquals(0, ris.size());
@@ -64,7 +63,7 @@ public class RecordableInputStreamTest extends Assert {
ris.close();
}
- @Test
+
public void testReadAndGetTextsAutoStopRecord() throws Exception {
RecordableInputStream ris = new RecordableInputStream(new ByteArrayInputStream(DATA), "utf-8");
assertEquals(0, ris.size());
http://git-wip-us.apache.org/repos/asf/camel/blob/67105c8e/camel-core/src/test/java/org/apache/camel/support/RecordableReaderTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/support/RecordableReaderTest.java b/camel-core/src/test/java/org/apache/camel/support/RecordableReaderTest.java
new file mode 100644
index 0000000..edfba9a
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/support/RecordableReaderTest.java
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.support;
+
+import java.io.ByteArrayInputStream;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class RecordableReaderTest extends TestCase {
+ private static final byte[] DATA;
+
+ static {
+ DATA = new byte[512];
+ final int radix = 0x7f - 0x20;
+ for (int i = 0; i < 512; i++) {
+ DATA[i] = (byte) (i % radix + 0x20);
+ }
+ }
+
+ public void testReadAndGetTextsBufferPurge() throws Exception {
+ RecordableInputStream ris = new RecordableInputStream(new ByteArrayInputStream(DATA), "utf-8");
+ assertEquals(0, ris.size());
+ byte[] buf = new byte[64];
+
+ // 8 * 64 = 512
+ for (int i = 0; i < 8; i++) {
+ // read in 64 bytes
+ int n = ris.read(buf, 0, buf.length);
+ assertEquals(64, n);
+ assertEquals(64, ris.size());
+
+ int offset = i * 64;
+ // consume the first 32 bytes
+ String text = ris.getText(32);
+ assertEquals(new String(DATA, offset, 32, "utf-8"), text);
+ assertEquals(32, ris.size());
+
+ // consume the other 32 bytes
+ text = ris.getText(32);
+ assertEquals(new String(DATA, offset + 32, 32, "utf-8"), text);
+ assertEquals(0, ris.size());
+
+ ris.record();
+ }
+
+ ris.close();
+ }
+
+ public void testReadAndGetTextsAutoStopRecord() throws Exception {
+ RecordableInputStream ris = new RecordableInputStream(new ByteArrayInputStream(DATA), "utf-8");
+ assertEquals(0, ris.size());
+ byte[] buf = new byte[64];
+
+ // read 64 bytes
+ int n = ris.read(buf, 0, buf.length);
+ assertEquals(64, n);
+ assertEquals(64, ris.size());
+
+ // consume the 64 bytes
+ String text = ris.getText(64);
+
+ assertEquals(new String(DATA, 0, 64, "utf-8"), text);
+ assertEquals(0, ris.size());
+
+ // read the next 64 bytes
+ n = ris.read(buf, 0, buf.length);
+ assertEquals(64, n);
+ assertEquals(0, ris.size());
+
+ // turn back on the recording and read the next 64 bytes
+ ris.record();
+ n = ris.read(buf, 0, buf.length);
+ assertEquals(64, n);
+ assertEquals(64, ris.size());
+
+ // consume the 64 bytes
+ text = ris.getText(64);
+
+ // 64 * 2 = 128
+ assertEquals(new String(DATA, 128, 64, "utf-8"), text);
+ assertEquals(0, ris.size());
+
+ ris.close();
+ }
+
+}