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