1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.components.test;
18
19 import org.springframework.context.ApplicationContext;
20 import org.springframework.context.support.ClassPathXmlApplicationContext;
21
22 import junit.framework.TestCase;
23
24 /***
25 * <p>
26 * AbstractSpringTestCase
27 * </p>
28 * <p>
29 *
30 * </p>
31 *
32 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
33 * @version $Id: AbstractSpringTestCase.java 516448 2007-03-09 16:25:47Z ate $
34 *
35 */
36 public abstract class AbstractSpringTestCase extends TestCase
37 {
38 /***
39 * Provides access to the Spring ApplicationContext.
40 */
41 protected ClassPathXmlApplicationContext ctx;
42
43 /***
44 * setup Spring context as part of test setup
45 */
46 protected void setUp() throws Exception
47 {
48 super.setUp();
49 if (ctx == null)
50 {
51 String [] bootConfigurations = getBootConfigurations();
52 if (bootConfigurations != null)
53 {
54 ApplicationContext bootContext = new ClassPathXmlApplicationContext(bootConfigurations, true);
55 ctx = new ClassPathXmlApplicationContext(getConfigurations(), true, bootContext);
56 }
57 else
58 {
59 ctx = new ClassPathXmlApplicationContext(getConfigurations(), true);
60 }
61 }
62 }
63
64 /***
65 * close Spring context as part of test teardown
66 */
67 protected void tearDown() throws Exception
68 {
69 super.tearDown();
70 if (ctx != null)
71 {
72 ctx.close();
73 }
74 }
75
76 /***
77 * required specification of spring configurations
78 */
79 protected abstract String[] getConfigurations();
80
81 /***
82 * optional specification of boot spring configurations
83 */
84 protected String[] getBootConfigurations()
85 {
86 return null;
87 }
88 }