]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/main/java/org/argeo/slc/unit/SpringBasedTestCase.java
Progress on Web reporting
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / unit / SpringBasedTestCase.java
1 package org.argeo.slc.unit;
2
3 import junit.framework.TestCase;
4
5 import org.springframework.context.ApplicationContext;
6 import org.springframework.context.support.ClassPathXmlApplicationContext;
7
8 /** Helper for tests using a Spring application co,text. */
9 public abstract class SpringBasedTestCase extends TestCase {
10 private ApplicationContext context;
11
12 /**
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()}.
16 */
17 protected ApplicationContext getContext() {
18 if (context == null) {
19 context = new ClassPathXmlApplicationContext(
20 getApplicationContextLocation());
21 }
22 return context;
23 }
24
25 /**
26 * Th location of the application to load. The default implementation
27 * returns <i>applicationContext.xml</i> found in the same package as the
28 * test.
29 */
30 protected String getApplicationContextLocation() {
31 return inPackage("applicationContext.xml");
32 }
33
34 /**
35 * Prefixes the package of the class after converting the '.' to '/' in
36 * order to have a resource path.
37 */
38 protected String inPackage(String suffix) {
39 String prefix = getClass().getPackage().getName().replace('.', '/');
40 return prefix + '/' + suffix;
41 }
42 }