WebSpringPentahoObjectFactory extends AbstractSpringPentahoObjectFactory { public void init( String configFile, Object context ) { if ( !( context instanceof ServletContext ) ) { String msg = Messages.getInstance().getErrorString( "WebSpringPentahoObjectFactory.ERROR_0001_CONTEXT_NOT_SUPPORTED", ServletContext.class.getName(), context.getClass().getName() ); throw new IllegalArgumentException( msg ); } ServletContext servletContext = (ServletContext) context; beanFactory = (XmlWebApplicationContext) WebApplicationContextUtils.getRequiredWebApplicationContext( servletContext ); } WebSpringPentahoObjectFactory(); void init( String configFile, Object context );  }
@Test public void testInit() throws Exception { WebSpringPentahoObjectFactory factory = new WebSpringPentahoObjectFactory(); XmlWebApplicationContext webAppContext = mock( XmlWebApplicationContext.class ); when( context.getAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE ) ).thenReturn( webAppContext ); factory.init( null, context ); }
@Test( expected = IllegalArgumentException.class ) public void testInit_noServletContext() throws Exception { WebSpringPentahoObjectFactory factory = new WebSpringPentahoObjectFactory(); factory.init( null, new Object() ); }