1 16 17 package org.springframework.web.context.support; 18 19 import java.io.File ; 20 21 import junit.framework.TestCase; 22 23 import org.springframework.context.support.StaticApplicationContext; 24 import org.springframework.mock.web.MockServletContext; 25 import org.springframework.web.util.WebUtils; 26 27 31 public class WebApplicationObjectSupportTests extends TestCase { 32 33 public void testWebApplicationObjectSupport() { 34 StaticWebApplicationContext wac = new StaticWebApplicationContext(); 35 wac.setServletContext(new MockServletContext()); 36 File tempDir = new File (""); 37 wac.getServletContext().setAttribute(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, tempDir); 38 wac.refresh(); 39 WebApplicationObjectSupport wao = new WebApplicationObjectSupport() { 40 }; 41 wao.setApplicationContext(wac); 42 assertEquals(wao.getServletContext(), wac.getServletContext()); 43 assertEquals(wao.getTempDir(), tempDir); 44 } 45 46 public void testWebApplicationObjectSupportWithWrongContext() { 47 StaticApplicationContext ac = new StaticApplicationContext(); 48 WebApplicationObjectSupport wao = new WebApplicationObjectSupport() { 49 }; 50 try { 51 wao.setApplicationContext(ac); 52 wao.getWebApplicationContext(); 53 fail("Should have thrown IllegalStateException"); 54 } 55 catch (IllegalStateException ex) { 56 } 58 } 59 60 } 61 | Popular Tags |