Repository: camel
Updated Branches:
  refs/heads/master e0956524d -> 55b0c10db


CAMEL-8941 test: restlet producer should handle binary streams regardless of 
content type


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/948d036c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/948d036c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/948d036c

Branch: refs/heads/master
Commit: 948d036c5e6e2ee04121fb22ca52f692b68929b8
Parents: 5d2fec5
Author: Anton Koscejev <anton.kosce...@zoomint.com>
Authored: Fri Jul 10 17:02:31 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sun Jul 12 09:31:18 2015 +0200

----------------------------------------------------------------------
 .../RestletProducerBinaryStreamTest.java        | 74 ++++++++++++++++++++
 1 file changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/948d036c/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerBinaryStreamTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerBinaryStreamTest.java
 
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerBinaryStreamTest.java
new file mode 100644
index 0000000..a8e8bc3
--- /dev/null
+++ 
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerBinaryStreamTest.java
@@ -0,0 +1,74 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.component.restlet;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+import static org.apache.camel.Exchange.CONTENT_TYPE;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.restlet.data.MediaType.APPLICATION_OCTET_STREAM;
+import static org.restlet.data.MediaType.AUDIO_MPEG;
+
+/**
+ * @version
+ */
+public class RestletProducerBinaryStreamTest extends RestletTestSupport {
+
+    @Test
+    public void shouldHandleBinaryOctetStream() throws Exception {
+        Exchange response = template.request("restlet:http://localhost:"; + 
portNum + "/application/octet-stream", null);
+
+        assertThat(response.getOut().getHeader(CONTENT_TYPE, String.class), 
equalTo("application/octet-stream"));
+        assertThat(response.getOut().getBody(byte[].class), 
equalTo(getAllBytes()));
+    }
+
+    @Test
+    public void shouldHandleBinaryAudioMpeg() throws Exception {
+        Exchange response = template.request("restlet:http://localhost:"; + 
portNum + "/audio/mpeg", null);
+
+        assertThat(response.getOut().getHeader(CONTENT_TYPE, String.class), 
equalTo("audio/mpeg"));
+        assertThat(response.getOut().getBody(byte[].class), 
equalTo(getAllBytes()));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("restlet:http://localhost:"; + portNum + 
"/application/octet-stream")
+                        .setHeader(CONTENT_TYPE, 
constant(APPLICATION_OCTET_STREAM))
+                        .setBody(constant(new 
ByteArrayInputStream(getAllBytes())));
+
+                from("restlet:http://localhost:"; + portNum + "/audio/mpeg")
+                        .setHeader(CONTENT_TYPE, constant(AUDIO_MPEG))
+                        .setBody(constant(new 
ByteArrayInputStream(getAllBytes())));
+            }
+        };
+    }
+
+    private static byte[] getAllBytes() {
+        byte[] data = new byte[256];
+        for (int i = 0; i < 256; i++) {
+            data[i] = (byte) (Byte.MIN_VALUE + i);
+        }
+        return data;
+    }
+}

Reply via email to