DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Andreas has posted 2 posts at DZone. View Full User Profile

Testing New Bean Scopes With Spring 2.0 - Example

11.15.2006
| 3804 views |
  • submit to reddit
        // scoped bean definition
	<bean id="scopedBean"
		class="org.bla.ScopedBeanImpl"
		scope="session">
		<aop:scoped-proxy />
	</bean>
// an example test case
public class ScopedBeanTest extends AbstractRequestContextFilterTestBase {

	protected String[] getConfigLocations() {
		return new String[] { "classpath:applicationContext-with-scopedBean.xml" };
	}


	@Test
	public void testScopedBean() throws Exception {

		new FilterTest(new FilterChain() {

			public void doFilter(ServletRequest arg0, ServletResponse arg1)
					throws IOException, ServletException {
				ScopedBean scopedBean = (ScopedBean) applicationContext
						.getBean("scopedBean");
				...
				/* 
				 * let the classses under test do something with your scopedBean
				 * and check if modifications are done correctly 
				 */
				...
			}

		}).run();

	}