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.support.ClassPathXmlApplicationContext;\r
\r
+import org.argeo.slc.core.SlcException;\r
+import org.argeo.slc.core.process.SlcExecution;\r
+\r
/** Helper for tests using a Spring application co,text. */\r
public abstract class AbstractSpringTestCase extends TestCase {\r
private ApplicationContext context;\r
}\r
return context;\r
}\r
- \r
+\r
/** Returns a bean from the underlying context */\r
- protected <T> T getBean(String beanId){\r
- return (T)getContext().getBean(beanId);\r
+ protected <T> T getBean(String beanId) {\r
+ return (T) getContext().getBean(beanId);\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
+ throw new SlcException("Cannot retrieve a unique bean of type "\r
+ + clss);\r
+ }\r
}\r
\r
/**\r