1 package org.jencks; 2 3 import junit.framework.TestCase; 4 import org.springframework.context.ConfigurableApplicationContext; 5 import org.springframework.context.support.ClassPathXmlApplicationContext; 6 7 import javax.jms.Session; 8 9 /*** 10 * @version $Revision: 1.1 $ 11 */ 12 public abstract class SpringTestSupport extends TestCase { 13 protected ConfigurableApplicationContext applicationContext; 14 15 protected void setUp() throws Exception { 16 applicationContext = createApplicationContext(); 17 assertNotNull("Should have an ApplicationContext", applicationContext); 18 } 19 20 21 protected void tearDown() throws Exception { 22 if (applicationContext != null) { 23 applicationContext.close(); 24 } 25 } 26 27 protected ConfigurableApplicationContext createApplicationContext() { 28 return new ClassPathXmlApplicationContext(getApplicationContextXml()); 29 } 30 31 protected abstract String getApplicationContextXml(); 32 33 /*** 34 * Finds the mandatory bean in the application context failing if its not there 35 */ 36 protected Object getBean(String name) { 37 Object answer = applicationContext.getBean(name); 38 assertNotNull("Could not find bean in ApplicationContext called: " + name, answer); 39 return answer; 40 } 41 }