tags:

views:

243

answers:

1

Does anyone have an example of using Apache Qpid within a standalone junit test.

Ideally I want to be able to create a queue on the fly which I can put/get msgs within my test. So I'm not testing QPid within my test, I'll use integration tests for that, however be very useful to test methods handling msgs with having to mock out a load of services.

A: 

Hi Wiretap, The Qpid project has a number of tests that use an embedded broker for testing. Whilst we use a base case to handle startup shutdown you could do the following to simply integrate a broker within your tests:

public void setUp() { int port=1;

// Config is actually a Configuaration File App Registry object, or Configuration Application Registry.

    ApplicationRegistry.initialise(config, port);

    TransportConnection.createVMBroker(port);        

}

public void test() {...}

public void tearDown() { TransportConnection.killVMBroker(port); ApplicationRegistry.remove(port); }

Then for the connection you need to specify the conectionURL for the broker. i.e. borkerlist='vm://1'