1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.spring;
22
23 import javax.servlet.ServletContext;
24
25 import junit.framework.TestCase;
26 import org.apache.struts2.StrutsConstants;
27 import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
28 import org.springframework.mock.web.MockServletContext;
29 import org.springframework.web.context.ConfigurableWebApplicationContext;
30 import org.springframework.web.context.WebApplicationContext;
31 import org.springframework.web.context.support.XmlWebApplicationContext;
32
33 /***
34 * Unit test for {@link StrutsSpringObjectFactory}.
35 *
36 */
37 public class StrutsSpringObjectFactoryTest extends TestCase {
38
39 public void testNoSpringContext() throws Exception {
40
41 StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory(null, null, new MockServletContext());
42
43 assertEquals(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, fac.getAutowireStrategy());
44 }
45
46 public void testWithSpringContext() throws Exception {
47
48
49 ConfigurableWebApplicationContext ac = new XmlWebApplicationContext();
50 ServletContext msc = (ServletContext) new MockServletContext();
51 msc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
52 ac.setServletContext(msc);
53 ac.setConfigLocations(new String[] {"org/apache/struts2/spring/StrutsSpringObjectFactoryTest-applicationContext.xml"});
54 ac.refresh();
55 StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory("constructor", null, msc);
56
57 assertEquals(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, fac.getAutowireStrategy());
58 }
59
60
61 }