You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/02/25 09:19:32 UTC

svn commit: r747704 - in /camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina: MinaCustomCodecTest.java MinaEncodingTest.java

Author: ningjiang
Date: Wed Feb 25 08:19:31 2009
New Revision: 747704

URL: http://svn.apache.org/viewvc?rev=747704&view=rev
Log:
CAMEL-1379 added a unit test

Modified:
    camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaCustomCodecTest.java
    camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java

Modified: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaCustomCodecTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaCustomCodecTest.java?rev=747704&r1=747703&r2=747704&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaCustomCodecTest.java (original)
+++ camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaCustomCodecTest.java Wed Feb 25 08:19:31 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.mina;
 
+import java.nio.charset.Charset;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.builder.RouteBuilder;
@@ -29,6 +31,7 @@
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.apache.mina.filter.codec.ProtocolEncoder;
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.filter.codec.textline.LineDelimiter;
 
 /**
  * Unit test with custom codec.
@@ -36,6 +39,7 @@
 public class MinaCustomCodecTest extends ContextTestSupport {
 
     protected String uri = "mina:tcp://localhost:11300?sync=true&codec=myCodec";
+   
     protected String badUri = "mina:tcp://localhost:11300?sync=true&codec=XXX";
 
     public void testMyCodec() throws Exception {
@@ -48,6 +52,26 @@
 
         mock.assertIsSatisfied();
     }
+    
+    public void testTCPEncodeUTF8InputIsString() throws Exception {
+        final String myUri = "mina:tcp://localhost:9080?encoding=UTF-8&sync=false";
+        this.context.addRoutes(new RouteBuilder() {
+            public void configure() {
+                from(myUri).to("mock:result");
+            }
+        });
+
+        MockEndpoint endpoint = getMockEndpoint("mock:result");
+
+        // include a UTF-8 char in the text \u0E08 is a Thai elephant
+        String body = "Hello Thai Elephant \u0E08";
+
+        endpoint.expectedMessageCount(1);
+        endpoint.expectedBodiesReceived(body);
+
+        template.sendBody(myUri, body);
+        assertMockEndpointsSatisfied();
+    }
 
     public void testBadConfiguration() throws Exception {
         try {
@@ -60,14 +84,14 @@
 
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry jndi = super.createRegistry();
-        jndi.bind("myCodec", new MyCodec());
+        jndi.bind("myCodec", new MyCodec());        
         return jndi;
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from(uri).transform(constant("Bye World")).to("mock:result");
+                from(uri).transform(constant("Bye World")).to("mock:result");                
             }
         };
     }
@@ -79,8 +103,8 @@
                 public void encode(IoSession ioSession, Object message, ProtocolEncoderOutput out)
                     throws Exception {
                     ByteBuffer bb = ByteBuffer.allocate(32).setAutoExpand(true);
-                    String s = (String) message;
-                    bb.put(s.getBytes());
+                    String s = (String) message;                    
+                    bb.put(s.getBytes("US-ASCII"));
                     bb.flip();
                     out.write(bb);
                 }
@@ -97,7 +121,7 @@
                 protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
                     if (in.remaining() > 0) {
                         byte[] buf = MinaConverter.toByteArray(in);
-                        out.write(new String(buf));
+                        out.write(new String(buf, "US-ASCII"));
                         return true;
                     } else {
                         return false;

Modified: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java?rev=747704&r1=747703&r2=747704&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java (original)
+++ camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaEncodingTest.java Wed Feb 25 08:19:31 2009
@@ -35,7 +35,7 @@
 public class MinaEncodingTest extends ContextTestSupport {
 
     public void testTCPEncodeUTF8InputIsBytes() throws Exception {
-        final String uri = "mina:tcp://localhost:8080?encoding=UTF-8&sync=false";
+        final String uri = "mina:tcp://localhost:9080?encoding=UTF-8&sync=false";
         this.context.addRoutes(new RouteBuilder() {
             public void configure() {
                 from(uri).to("mock:result");
@@ -55,7 +55,7 @@
     }
 
     public void testTCPEncodeUTF8InputIsString() throws Exception {
-        final String uri = "mina:tcp://localhost:8080?encoding=UTF-8&sync=false";
+        final String uri = "mina:tcp://localhost:9080?encoding=UTF-8&sync=false";
         this.context.addRoutes(new RouteBuilder() {
             public void configure() {
                 from(uri).to("mock:result");
@@ -75,7 +75,7 @@
     }
 
     public void testTCPEncodeUTF8TextLineInputIsString() throws Exception {
-        final String uri = "mina:tcp://localhost:8080?textline=true&encoding=UTF-8&sync=false";
+        final String uri = "mina:tcp://localhost:9080?textline=true&encoding=UTF-8&sync=false";
         this.context.addRoutes(new RouteBuilder() {
             public void configure() {
                 from(uri).to("mock:result");
@@ -98,7 +98,7 @@
     // See TextLineEncoder#encode where the message is converted to String using .toString()
 
     public void testUDPEncodeUTF8InputIsBytes() throws Exception {
-        final String uri = "mina:udp://localhost:8080?encoding=UTF-8&sync=false";
+        final String uri = "mina:udp://localhost:9080?encoding=UTF-8&sync=false";
         this.context.addRoutes(new RouteBuilder() {
             public void configure() {
                 from(uri).to("mock:result");
@@ -118,7 +118,7 @@
     }
 
     public void testUDPEncodeUTF8InputIsString() throws Exception {
-        final String uri = "mina:udp://localhost:8080?encoding=UTF-8&sync=false";
+        final String uri = "mina:udp://localhost:9080?encoding=UTF-8&sync=false";
         this.context.addRoutes(new RouteBuilder() {
             public void configure() {
                 from(uri).to("mock:result");
@@ -145,7 +145,7 @@
         final String hello = "Hello Thai Elephant \u0E08";
         final String bye = "Hello Thai Elephant \u0E08";
 
-        final String uri = "mina:udp://localhost:8080?sync=true&encoding=UTF-8";
+        final String uri = "mina:udp://localhost:9080?sync=true&encoding=UTF-8";
         this.context.addRoutes(new RouteBuilder() {
             public void configure() {
                 from(uri).process(new Processor() {
@@ -172,7 +172,7 @@
     }
 
     public void testInvalidEncoding() throws Exception {
-        final String uri = "mina:tcp://localhost:8080?textline=true&encoding=XXX&sync=false";
+        final String uri = "mina:tcp://localhost:9080?textline=true&encoding=XXX&sync=false";
 
         try {
             this.context.addRoutes(new RouteBuilder() {