/* * This class comes as is, no warranties whatsoever. * Copyright Comerge AG 2009. All Rights Reserved." * * http://comerge.net */ package org.apache.activemq.tests; import java.io.File; import org.apache.activemq.broker.BrokerService; import org.junit.AfterClass; import org.junit.BeforeClass; /** * A test case which starts a active MQ message bus in the tests VM at address * EmbededActiveMQTestCase.MESSAGE_QUEUE_ADDRESS. The class makes sure to clean * up the bus after the tests have been executed. * * @author Benno Baumgartner (benno.baumgartner@comerge.net) */ public class EmbeddedActiveMQTestCase { public static final String MESSAGE_QUEUE_ADDRESS= "tcp://localhost:16161"; private static BrokerService fgMessageQueueService; @BeforeClass public static void setUpBeforeClass() throws Exception { fgMessageQueueService= new BrokerService(); fgMessageQueueService.addConnector(MESSAGE_QUEUE_ADDRESS); fgMessageQueueService.deleteAllMessages(); fgMessageQueueService.setPersistent(false); fgMessageQueueService.start(); } @AfterClass public static void tearDownAfterClass() throws Exception { if (fgMessageQueueService != null) { fgMessageQueueService.stop(); fgMessageQueueService.deleteAllMessages(); fgMessageQueueService= null; } File activeMQDateFolder= new File("activemq-data"); deleteFolder(activeMQDateFolder); } protected void stopQueue() throws Exception { fgMessageQueueService.stop(); fgMessageQueueService= null; } protected void startQueue() throws Exception { if (fgMessageQueueService != null) return; fgMessageQueueService= new BrokerService(); fgMessageQueueService.addConnector(MESSAGE_QUEUE_ADDRESS); fgMessageQueueService.setPersistent(false); fgMessageQueueService.start(); } public static void deleteFolder(File file) { File[] files= file.listFiles(); if (files != null) { for (File child : files) { deleteFolder(child); } } file.delete(); } }