Your RouteBuilder into the test method doesn't be added into the camel context.

Here is an example of setting the RouteBuilder
public class MyTest extends CamelTestSupport {

    @Test
    public void yourTest() throws Exception {
        // do some test here, you can remove the consumer template
    }

    // set up the camelContext
    protected CamelContext createCamelContext() throws Exception {
        CamelContext camelContext = super.createCamelContext();
camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false&broker.useJmx=false"));
        return camelContext;
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
errorHandler(deadLetterChannel("mock:error")); from("activemq:Player.1.VirtualTopic.TABLE.1").to("mock:player1");
            }
        };
    }
}

Mick Knutson wrote:
So I have this in my unit test now:

    @EndpointInject(uri = "mock:player1")
    protected MockEndpoint mockPlayer;

    @Test
    public void testGetStatusUpdateMessage() throws Exception {
        log.info("testGetStatusUpdateMessage");

        // we expect Hello World received in our mock endpoint
        mockPlayer.expectedBodiesReceived("Hello World");


        RouteBuilder builder = new RouteBuilder() {
            public void configure() {
                errorHandler(deadLetterChannel("mock:error"));


from("activemq:Player.1.VirtualTopic.TABLE.1").to("mock:player1");
            }
        };


        TableService tableService = (TableService) context
                .getBean("tableServiceProxy");
        boolean response = tableService.sendStatusUpdate("123");
        log.info("... the bet was successfully placed: " + response);
        assertTrue(response);

        String body = consumer.receiveBody(
                "activemq:Player.1.VirtualTopic.TABLE.1", String.class);

        assertEquals("Hello World", body);
        mock.assertIsSatisfied();
    }


Then on the server that I start up, I see:

INFO: //----------------------------------------------------------------//
Aug 5, 2009 7:04:01 PM com.wiredducks.service.impl.TableServiceImpl
sendStatusUpdate
INFO: sendStatusUpdate: 123
Aug 5, 2009 7:04:01 PM
org.apache.activemq.transport.failover.FailoverTransport doReconnect
INFO: Successfully connected to tcp://localhost:61616
Aug 5, 2009 7:04:02 PM com.wiredducks.service.impl.TableServiceImpl
sendStatusUpdate
INFO: //----- Messge Sent -----//
Aug 5, 2009 7:04:02 PM com.wiredducks.service.impl.TableServiceImpl
sendStatusUpdate
INFO: //----------------------------------------------------------------//



But I am not able to understand how to trace the message from the server to
@EndpointInject(uri="activemq:VirtualTopic.TABLE.1")

to ensure it arrived there.



Then on my client JUNit test case, it still hangs:

*Running com.wiredducks.service.test.TableServiceTest
3955 [main] DEBUG org.apache.camel.impl.DefaultCamelContext  -
mock://player1 converted to endpoint: Endpoint[mock://player1] by component:
org.apache.camel.component.mock.mockcompon...@c16f0c
 3979 [main] INFO  com.wiredducks.service.test.TableServiceTest  -
testGetStatusUpdateMessage
 4084 [main] INFO  com.wiredducks.service.test.TableServiceTest  - ... the
bet was successfully placed: true
 4089 [main] DEBUG org.apache.camel.impl.DefaultCamelContext  -
activemq://Player.1.VirtualTopic.TABLE.1 converted to endpoint:
Endpoint[activemq://Player.1.VirtualTopic.TABLE.1] by component:
org.apache.activemq.camel.component.activemqcompon...@1dfd2293
 4118 [ActiveMQ Task] INFO
org.apache.activemq.transport.failover.FailoverTransport  - Successfully
connected to tcp://localhost:61616
*



---
Thank You…

Mick Knutson, President

BASE Logic, Inc.
Enterprise Architecture, Design, Mentoring & Agile Consulting
p. (866) BLiNC-411: (254-6241-1)
f. (415) 685-4233

Website: http://baselogic.com
Linked IN: http://linkedin.com/in/mickknutson
Vacation Rental: http://tahoe.baselogic.com
---



On Wed, Aug 5, 2009 at 6:22 PM, Willem Jiang <willem.ji...@gmail.com> wrote:

I think the consumer template should work.
String body =
consumer.receiveBody("activemq:Player.1.VirtualTopic.TABLE.1",
String.class);


Or you can try to setup the route rule first for the Unit test.

form("activemq:Player.1.VirtualTopic.TABLE.1").to("mock:player1");

then you can using the camel mock API[1] to check if the mock endpoint get
the message.

[1]http://camel.apache.org/mock.html

Willem


Mick Knutson wrote:

That is what I am trying to wrap my head around. I am trying to figure out
a
way to either create a consumer like:
http://camel.apache.org/activemq.html

But still can't seem to understand how to fit this into a unit test in
question. Not sure how that sets a remote destination which is what I need
right?

---
Thank You…

Mick Knutson, President

BASE Logic, Inc.
Enterprise Architecture, Design, Mentoring & Agile Consulting
p. (866) BLiNC-411: (254-6241-1)
f. (415) 685-4233

Website: http://baselogic.com
Linked IN: http://linkedin.com/in/mickknutson
Vacation Rental: http://tahoe.baselogic.com
---



On Wed, Aug 5, 2009 at 6:03 PM, Willem Jiang <willem.ji...@gmail.com>
wrote:

 Can your consumer start to receive the message before calling the
sendStatusUpdate method ?

You may need using other thread to call the sendStatusUpdate.

Willem

Mick Knutson wrote:

 Is there anything else I would have to setup with my embedded broker to
be
able to test sending a message to a VirtualTopic to get routed to the
subscribed Queues?

Here is what I have on my server:


  *...@endpointinject(uri="activemq:**VirtualTopic.TABLE.1")
  ProducerTemplate producer;

  public boolean sendStatusUpdate(String body) {
      log.info("//------------------**------------------------------**
----------------//");
      log.info("sendStatusUpdate: " + body);
      log.info("//------------------**------------------------------**
----------------//");

      //Send message to
      producer.sendBody("<hello>**world!</hello>");

      return true;
  }*


Here is my client unit test:

  *...@test
  public void testGetStatusUpdateMessage() throws Exception {
      log.info("testGetStatusUpdateMessage");

      TableService tableService = (TableService)
context.getBean("tableServiceProxy");
      boolean response = tableService.sendStatusUpdate("123");
      log.info("... the bet was successfully placed: " + response);
      assertTrue(response);

      String body =
consumer.receiveBody("activemq:Player.1.VirtualTopic.TABLE.1",
String.class);

      assertEquals("Hello World", body);

  }*


Now I am not able to get any body messages on
*activemq:Player.1.VirtualTopic.TABLE.1
a*nd I have only used the embedded broker at this point.

So what actually happens is my tests run freezes. I assume it is waiting
for
a message to be delivered onto *activemq:Player.1.VirtualTopic.TABLE.1
*that
never arrives.


---
Thank You…

Mick Knutson, President

BASE Logic, Inc.
Enterprise Architecture, Design, Mentoring & Agile Consulting
p. (866) BLiNC-411: (254-6241-1)
f. (415) 685-4233

Website: http://baselogic.com
Linked IN: http://linkedin.com/in/mickknutson
Vacation Rental: http://tahoe.baselogic.com
---





Reply via email to