Return-Path: Delivered-To: apmail-geronimo-activemq-users-archive@www.apache.org Received: (qmail 99821 invoked from network); 6 Jun 2006 14:16:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Jun 2006 14:16:02 -0000 Received: (qmail 70876 invoked by uid 500); 6 Jun 2006 14:16:02 -0000 Delivered-To: apmail-geronimo-activemq-users-archive@geronimo.apache.org Received: (qmail 70858 invoked by uid 500); 6 Jun 2006 14:16:02 -0000 Mailing-List: contact activemq-users-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-users@geronimo.apache.org Delivered-To: mailing list activemq-users@geronimo.apache.org Received: (qmail 70849 invoked by uid 99); 6 Jun 2006 14:16:01 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Jun 2006 07:16:01 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of james.strachan@gmail.com designates 66.249.92.175 as permitted sender) Received: from [66.249.92.175] (HELO ug-out-1314.google.com) (66.249.92.175) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Jun 2006 07:16:01 -0700 Received: by ug-out-1314.google.com with SMTP id m3so1881033uge for ; Tue, 06 Jun 2006 07:15:39 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=NgJ2xW1Vf78DvSR9eokX5LB94yv69lE5ZOFUdr2FNB8dVaN9QCUglpRCNn9DqMUzM468bNILZRynqyOVWj9dEcVw/j8s1fddHLoMN8x1AUPAgoSj9MzUDQfdnpozUgkjzA07Nchv4JpH+LbbviLR3dB92r/KhqNkRsHoXkXRUM4= Received: by 10.67.89.6 with SMTP id r6mr4545051ugl; Tue, 06 Jun 2006 07:15:38 -0700 (PDT) Received: by 10.66.255.17 with HTTP; Tue, 6 Jun 2006 07:15:38 -0700 (PDT) Message-ID: Date: Tue, 6 Jun 2006 15:15:38 +0100 From: "James Strachan" To: activemq-users@geronimo.apache.org Subject: Re: Using ActiveMQ embedded sever for Testing In-Reply-To: <4733351.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4717413.post@talk.nabble.com> <4733351.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Rather than all this code and these abstractions - why not just replace it with the one line of code mentioned in the FAQ entry (http://incubator.apache.org/activemq/how-to-unit-test-jms-code.html)- then there's no complexity of JNDI etc? ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); If you need to use a destination just create it Destination foo = new ActiveMQQueue("foo.bar"); then your testing code is nice and simple. On 6/6/06, drystone wrote: > > > Thanks for the help but I am still struggling to get it to work. I have > create an object to act as my broker service: > > public class ActiveMqEmbeddedServer { > public static final String DEFAULT_CONNECTOR_URI = > "vm://localhost:8686"; > private BrokerService brokerService = null; > public ActiveMqEmbeddedServer( String connectorUri ) { > brokerService = new BrokerService(); > brokerService.setPersistent( false ); > brokerService.addConnector( connectorUri ); > brokerService.start(); > } > public void addQueue( String queueName ) { > // Not sure want I am doing here > String fullQueueName = ActiveMQDestination.QUEUE_QUALIFIED_PREFIX + > queueName; > ActiveMQDestination destination = > ActiveMQDestination.createDestination( fullQueueName, > ActiveMQDestination.QUEUE_TYPE ); > PolicyEntry policyEntry = new PolicyEntry(); > //policyEntry.configure( new Queue( destination, null, null, null, > null ) ); > policyEntry.setDestination( destination ); > List policyEntries = new ArrayList(); > policyEntries.add( policyEntry ); > PolicyMap policyMap = new PolicyMap(); > policyMap.setPolicyEntries( policyEntries ); > brokerService.setDestinationPolicy( policyMap ); > } > } > > I was hoping that this would act as my jms server. I have a JMS sender > object that does > > Properties properties = new Properties(); > properties.put( Context.INITIAL_CONTEXT_FACTORY, > "org.apache.activemq.jndi.ActiveMQInitialContextFactory" ); > properties.put( Context.PROVIDER_URL, "vm://localhost:8686"); > InitialContext initialContext = new InitialContext( properties ); > Queue queue = (Queue) initialContext.lookup( "TestQueue" ); > QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) > initialContext.lookup( > "ConnectionFactory" ); > QueueConnection queueConnection = > queueConnectionFactory.createQueueConnection(); > QueueSession queueSession = queueConnection.createQueueSession( false, > Session.AUTO_ACKNOWLEDGE ); > QueueSender queueSender = queueSession.createSender( queue ) > Message jmsMessage = queueSession.createTextMessage( message.toString() ); > queueSender.send( message ); > queueConnection.start(); > queueSender.close(); > queueConnection.stop(); > > My test looks like this: > > public class JmsSendingAndReceivingTest extends TestCase { > private static final String TEST_MESSAGE = "This is a test message"; > private static final String TEST_QUEUE_NAME = "TestQueue"; > private ActiveMqEmbeddedServer embeddedServer = null; > private ActiveMqConfiguration configuration = null; > protected void setUp() throws Exception { > super.setUp(); > configuration = new ActiveMqConfiguration( "localhost", "8686", > "TestQueue", > ActiveMqConfiguration.Protocol.VM, null ); > embeddedServer = new ActiveMqEmbeddedServer( > configuration.getProvidorUrl() ); > embeddedServer.addQueue( TEST_QUEUE_NAME ); > } > public void testSendAndRecieve() throws JmsException { > JmsSender jmsSender = new JmsSender( configuration ); > jmsSender.sendMessage( TEST_MESSAGE ); > } > protected void tearDown() throws Exception { > super.tearDown(); > embeddedServer.stopService(); > } > } > > I was hoping that I would be able to add queues and topics to the broker > server and use them through the normal JMS manner. Please can you point me > in the right direction. > Thanks for your help, > D > -- > View this message in context: http://www.nabble.com/Using-ActiveMQ-embedded-sever-for-Testing-t1736053.html#a4733351 > Sent from the ActiveMQ - User forum at Nabble.com. > > -- James ------- http://radio.weblogs.com/0112098/