svn commit: r691155 - in /activemq/camel/trunk/components/camel-mina/src: main/java/org/apache/camel/component/mina/ test/java/org/apache/camel/component/mina/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r691155 - in /activemq/camel/trunk/components/camel-mina/src: main/java/org/apache/camel/component/mina/ test/java/org/apache/camel/component/mina/

ningjiang
Author: ningjiang
Date: Tue Sep  2 01:45:39 2008
New Revision: 691155

URL: http://svn.apache.org/viewvc?rev=691155&view=rev
Log:
CAMEL-400 Added some unit tests also get the commented CAMEL-381 test work

Modified:
    activemq/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
    activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaConverterTest.java
    activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java

Modified: activemq/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java?rev=691155&r1=691154&r2=691155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java (original)
+++ activemq/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java Tue Sep  2 01:45:39 2008
@@ -67,6 +67,11 @@
             openConnection();
         }
 
+        // set the exchange encoding property
+        if (endpoint.getCharsetName() != null) {
+            exchange.setProperty(Exchange.CHARSET_NAME, endpoint.getCharsetName());
+        }
+
         Object body = MinaPayloadHelper.getIn(endpoint, exchange);
         if (body == null) {
             LOG.warn("No payload to send for exchange: " + exchange);

Modified: activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaConverterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaConverterTest.java?rev=691155&r1=691154&r2=691155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaConverterTest.java (original)
+++ activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaConverterTest.java Tue Sep  2 01:45:39 2008
@@ -18,8 +18,12 @@
 package org.apache.camel.component.mina;
 
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 
 import junit.framework.TestCase;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
 import org.apache.mina.common.ByteBuffer;
 
 /**
@@ -38,12 +42,14 @@
         }
     }
 
-    public void testToString() {
-        String in = "Hello World";
-        ByteBuffer bb = ByteBuffer.wrap(in.getBytes());
+    public void testToString() throws UnsupportedEncodingException {
+        String in = "Hello World \u4f60\u597d";
+        ByteBuffer bb = ByteBuffer.wrap(in.getBytes("UTF-8"));
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
 
-        String out = MinaConverter.toString(bb, null);
-        assertEquals("Hello World", out);
+        String out = MinaConverter.toString(bb, exchange);
+        assertEquals("Hello World \u4f60\u597d", out);
     }
 
     public void testToInputStream() throws Exception {

Modified: activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java?rev=691155&r1=691154&r2=691155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java (original)
+++ activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java Tue Sep  2 01:45:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.mina;
 
+import java.nio.charset.Charset;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -43,13 +45,14 @@
         MockEndpoint endpoint = getMockEndpoint("mock:result");
 
         // include a UTF-8 char in the text \u0E08 is a Thai elephant
-        byte[] body = "Hello Thai Elephant \u0E08".getBytes();
+        byte[] body = "Hello Thai Elephant \u0E08".getBytes("UTF-8");
 
         endpoint.expectedMessageCount(1);
         endpoint.expectedBodiesReceived(body);
 
         template.sendBody(uri, body);
         assertMockEndpointsSatisifed();
+        System.out.println(endpoint.getExchanges().get(0).getIn().getBody());
     }
 
     public void testTCPEncodeUTF8InputIsString() throws Exception {
@@ -132,8 +135,8 @@
         endpoint.expectedBodiesReceived(body);
 
         template.sendBody(uri, body);
-        // This fails, see CAMEL-381 and MinaConverter
-        //assertMockEndpointsSatisifed();
+
+        assertMockEndpointsSatisifed();
     }
 
     public void testUDPEncodeUTF8InputIsStringNoMock() throws Exception {
@@ -148,8 +151,7 @@
             public void configure() {
                 from(uri).process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
-                        byte[] in = exchange.getIn().getBody(byte[].class);
-                        String s = new String(in, "UTF-8");
+                        String s = exchange.getIn().getBody(String.class);
                         assertEquals(hello, s);
                         exchange.getOut().setBody(bye);
                     }
@@ -166,8 +168,7 @@
         producer.process(exchange);
         producer.stop();
 
-        byte[] out = exchange.getOut().getBody(byte[].class);
-        String s = new String(out, "UTF-8");
+        String s = exchange.getOut().getBody(String.class);
         assertEquals(bye, s);
     }