* @throws Exception the test failed
*/
public void testAvalonIntoSpringIntegration() throws Exception
{
SpringFrameworkService service = (SpringFrameworkService) this.container.lookup("springFrameworkService");
AbstractApplicationContext ctx = service.getAbstractApplicationContext();
// ensure that the Avalon SystemPropertyService updated the system properties (so it was properly started)
assertTrue(System.getProperty("FOO").equals("BAR"));
CustomAvalonService customAvalonService;
CustomSpringService customSpringService;
SystemPropertyService systemPropertyService;
ServiceManager serviceManager = (ServiceManager) ctx.getBean("avalonContainerBean");
// lookup and use the Spring bean using Spring's context
systemPropertyService = (SystemPropertyService) ctx.getBean("systemPropertyService");
assertNotNull(systemPropertyService);
// lookup and use the Spring bean using Spring's context
customSpringService = (CustomSpringService) ctx.getBean("customSpringService");
customSpringService.sayGretting();
assertEquals(customSpringService.getGreeting(), GREETING);
// lookup and use the Spring bean using Avalon's Service Manager
customSpringService = (CustomSpringService) serviceManager.lookup("customSpringService");
customSpringService.sayGretting();
assertEquals(customSpringService.getGreeting(), GREETING);
// lookup and use the Avalon service using Spring's context
customAvalonService = (CustomAvalonService) ctx.getBean("customAvalonService");
customAvalonService.sayGretting();
assertEquals(customAvalonService.getGreeting(), GREETING);
// lookup and use the Avalon service using Avalon's Service Manager
customAvalonService = (CustomAvalonService) serviceManager.lookup("customAvalonService");
customAvalonService.sayGretting();
assertEquals(customAvalonService.getGreeting(), GREETING);
// try to find a non-existing service using Avalon's Service Manager
try
{
serviceManager.lookup("foo");
fail("Looking up a non-existing service must throw a ServiceException");
}
catch(ServiceException e)
{
// nothing to do
}
catch(Exception e)
{
fail("Looking up a non-existing service must throw a ServiceException");
}
// try to find a non-existing service using Spring's context
try
{
ctx.getBean("foo");
fail("Looking up a non-existing service must throw a BeansException");
}
catch(BeansException e)
{
// nothing to do