You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/11/15 17:20:16 UTC

svn commit: r595348 - /activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java

Author: jstrachan
Date: Thu Nov 15 08:20:14 2007
New Revision: 595348

URL: http://svn.apache.org/viewvc?rev=595348&view=rev
Log:
refactored the test case to be easier to read

Modified:
    activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java

Modified: activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java?rev=595348&r1=595347&r2=595348&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java (original)
+++ activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java Thu Nov 15 08:20:14 2007
@@ -16,73 +16,30 @@
  */
 package org.apache.camel.component.mina;
 
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import junit.framework.TestCase;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
+import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class MinaVmTest extends TestCase {
-    protected CamelContext container = new DefaultCamelContext();
-    protected CountDownLatch latch = new CountDownLatch(1);
-    protected Exchange receivedExchange;
+public class MinaVmTest extends ContextTestSupport {
     protected String uri = "mina:vm://localhost:8080";
-    protected Producer<MinaExchange> producer;
 
     public void testMinaRoute() throws Exception {
+        MockEndpoint endpoint = getMockEndpoint("mock:result");
+        Object body = "Hello there!";
+        endpoint.expectedBodiesReceived(body);
 
-        // now lets fire in a message
-        Endpoint<MinaExchange> endpoint = container.getEndpoint(uri);
-        MinaExchange exchange = endpoint.createExchange();
-        Message message = exchange.getIn();
-        message.setBody("Hello there!");
-        message.setHeader("cheese", 123);
-
-        producer = endpoint.createProducer();
-        producer.start();
-        producer.process(exchange);
-
-        // now lets sleep for a while
-        boolean received = latch.await(5, TimeUnit.SECONDS);
-        assertTrue("Did not receive the message!", received);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        container.addRoutes(createRouteBuilder());
-        container.start();
-    }
-
+        template.sendBodyAndHeader(uri, body, "cheese", 123);
 
-    @Override
-    protected void tearDown() throws Exception {
-        if (producer != null) {
-            producer.stop();
-        }
-        container.stop();
+        assertMockEndpointsSatisifed();
     }
 
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from(uri).process(new Processor() {
-                    public void process(Exchange e) {
-                        System.out.println("Received exchange: " + e.getIn());
-                        receivedExchange = e;
-                        latch.countDown();
-                    }
-                });
+                from(uri).to("mock:result");
             }
         };
     }