package org.argeo.slc.unit;\r
\r
-import java.util.Map;\r
-\r
import junit.framework.TestCase;\r
\r
import org.springframework.context.ApplicationContext;\r
+import org.springframework.context.ConfigurableApplicationContext;\r
import org.springframework.context.support.ClassPathXmlApplicationContext;\r
\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+\r
import org.argeo.slc.core.SlcException;\r
-import org.argeo.slc.core.process.SlcExecution;\r
+import org.argeo.slc.spring.SpringUtils;\r
\r
/** Helper for tests using a Spring application co,text. */\r
public abstract class AbstractSpringTestCase extends TestCase {\r
- private ApplicationContext context;\r
+ protected final Log log = LogFactory.getLog(getClass());\r
+ private ConfigurableApplicationContext context;\r
\r
/**\r
* Gets (and create if necessary) the application context to use. Default\r
* implementation uses a class path xml application context and calls\r
* {@link #getApplicationContextLocation()}.\r
*/\r
- protected ApplicationContext getContext() {\r
+ protected ConfigurableApplicationContext getContext() {\r
if (context == null) {\r
context = new ClassPathXmlApplicationContext(\r
getApplicationContextLocation());\r
}\r
\r
protected <T> T getBean(Class<? extends T> clss) {\r
- Map<String, T> map = getContext().getBeansOfType(clss);\r
- if (map.size() == 1) {\r
- return map.values().iterator().next();\r
- } else {\r
+ T bean = SpringUtils.loadSingleFromContext(getContext(), clss);\r
+ if (bean == null) {\r
throw new SlcException("Cannot retrieve a unique bean of type "\r
+ clss);\r
+ } else {\r
+ return bean;\r
}\r
}\r
\r