01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.spring;
06:
07: import com.opensymphony.webwork.WebWorkConstants;
08: import com.opensymphony.webwork.config.Configuration;
09: import junit.framework.TestCase;
10: import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
11: import org.springframework.mock.web.MockServletContext;
12: import org.springframework.web.context.ConfigurableWebApplicationContext;
13: import org.springframework.web.context.WebApplicationContext;
14: import org.springframework.web.context.support.XmlWebApplicationContext;
15:
16: import javax.servlet.ServletContext;
17:
18: /**
19: * Unit test for {@link WebWorkSpringObjectFactory}.
20: *
21: * @author Claus Ibsen
22: * @version $Date: 2006-03-14 17:49:54 +0100 (Tue, 14 Mar 2006) $ $Id: WebWorkSpringObjectFactoryTest.java 2405 2006-03-14 16:49:54Z tmjee $
23: */
24: public class WebWorkSpringObjectFactoryTest extends TestCase {
25:
26: public void testNoSpringContext() throws Exception {
27: // to cover situations where there will be logged an error
28: WebWorkSpringObjectFactory fac = new WebWorkSpringObjectFactory();
29: ServletContext msc = (ServletContext) new MockServletContext();
30: fac.init(msc);
31:
32: assertEquals(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, fac
33: .getAutowireStrategy());
34: }
35:
36: public void testWithSpringContext() throws Exception {
37: WebWorkSpringObjectFactory fac = new WebWorkSpringObjectFactory();
38:
39: // autowire by constructure, we try a non default setting in this unit test
40: Configuration.set(
41: WebWorkConstants.WEBWORK_OBJECTFACTORY_SPRING_AUTOWIRE,
42: "constructor");
43:
44: ConfigurableWebApplicationContext ac = new XmlWebApplicationContext();
45: ServletContext msc = (ServletContext) new MockServletContext();
46: msc
47: .setAttribute(
48: WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
49: ac);
50: ac.setServletContext(msc);
51: ac
52: .setConfigLocations(new String[] { "/com/opensymphony/webwork/spring/WebWorkSpringObjectFactoryTest-applicationContext.xml" });
53: ac.refresh();
54:
55: fac.init(msc);
56:
57: assertEquals(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR,
58: fac.getAutowireStrategy());
59: }
60:
61: }
|