1 package org
.argeo
.slc
.unit
;
3 import junit
.framework
.TestCase
;
5 import org
.springframework
.context
.ApplicationContext
;
6 import org
.springframework
.context
.support
.ClassPathXmlApplicationContext
;
8 /** Helper for tests using a Spring application co,text. */
9 public abstract class AbstractSpringTestCase
extends TestCase
{
10 private ApplicationContext context
;
13 * Gets (and create if necessary) the application context to use. Default
14 * implementation uses a class path xml application context and calls
15 * {@link #getApplicationContextLocation()}.
17 protected ApplicationContext
getContext() {
18 if (context
== null) {
19 context
= new ClassPathXmlApplicationContext(
20 getApplicationContextLocation());
25 /** Returns a bean from the underlying context */
26 protected <T
> T
getBean(String beanId
){
27 return (T
)getContext().getBean(beanId
);
31 * Th location of the application to load. The default implementation
32 * returns <i>applicationContext.xml</i> found in the same package as the
35 protected String
getApplicationContextLocation() {
36 return inPackage("applicationContext.xml");
40 * Prefixes the package of the class after converting the '.' to '/' in
41 * order to have a resource path.
43 protected String
inPackage(String suffix
) {
44 String prefix
= getClass().getPackage().getName().replace('.', '/');
45 return prefix
+ '/' + suffix
;