KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > context > support > WebApplicationObjectSupportTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.context.support;
18
19 import java.io.File JavaDoc;
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 /**
28  * @author Juergen Hoeller
29  * @since 28.08.2003
30  */

31 public class WebApplicationObjectSupportTests extends TestCase {
32
33     public void testWebApplicationObjectSupport() {
34         StaticWebApplicationContext wac = new StaticWebApplicationContext();
35         wac.setServletContext(new MockServletContext());
36         File JavaDoc tempDir = new File JavaDoc("");
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 JavaDoc ex) {
56             // expected
57
}
58     }
59
60 }
61
Popular Tags