AbstractSpringAction Test Case available?
colletts Feb 29, 2008 12:10 AMHi,
Are there any Junit helper classes for creating test cases for AbstractSpringAction(s)?
I am looking for something along the lines of spring classes like AbstractDependencyInjectionSpringContextTests.
Failing that are there any good examples of using Junit to test JBoss ESB actions?
I tried to create an AbstractSpringAction and ConfigTree programatically in the testcase but I can't seem to get the Spring Container to initialise in a junit test.
Test Class
public class MySpringEnabledActionTest extends AbstractDependencyInjectionSpringContextTests{
 public void testSayHelloAopStyle() throws Exception {
 String messageObject = "Message Body String Object";
 Message esbMessage = MessageFactory.getInstance().getMessage();
 esbMessage.getBody().add(messageObject);
 Message returnMessage;
 File esbConfigFile = new File("C:/dev/workspace/TestJBossESBSpringAOP/src/main/resources/META-INF/jboss-esb.xml");
 FileInputStream fis = new FileInputStream(esbConfigFile);
 ConfigTree configTree = ConfigTree.fromInputStream(fis);
 MySpringEnabledAction mySpringEnabledAction = new MySpringEnabledAction(configTree);
 returnMessage = mySpringEnabledAction.sayHelloAopStyle(esbMessage);
 assertSame(messageObject,returnMessage.getBody().get());
 }
 ...
}this works to a point; but in the actual AbstractSpringAction the spring bean factory is not initialised.
 public class MySpringEnabledAction extends AbstractSpringAction
 {
 public MySpringEnabledAction(ConfigTree config) throws Exception
 {
 configTree = config;
 }
 public Message sayHelloAopStyle(Message message) throws Exception
 {
 String springContextXml = configTree.getAttribute("springContextXml");
 logger.error("springContextXml from contextTree is " + springContextXml); \\ shows that the springContextXml attribute is null
 BeanFactory beanFactory = getBeanFactory();
 if (beanFactory==null){
 logger.error("Beanfactory is null"); \\ because the springContext is null the beanfactory is null??
 } else{
 logger.error("Beanfactory is NOT null");
 }
 SaySomething hello = (SaySomething) beanFactory.getBean("helloObject"); \\null pointer exception here
 logHeader();
 // interceptor will get applied here
 // check the console output to see the interceptor changed the message
 hello.setGreeting((String)message.getBody().get());
 logFooter();
 return message;
 }
The jboss-esb.xml is exactly the same as from the sample quickstart spring_aop i.e. there is a springContextXml attribute pointing to the spring-context.xml
Using jbossesb-server-4.2.1GA in windows XP win32 with Eclipse 3.3.1.1 and Maven 2.0 running the test cases
Thanks
Steve
 
    