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