Line 0
Link Here
|
|
|
1 |
package org.apache.jasper.compiler; |
2 |
|
3 |
import static org.easymock.EasyMock.*; |
4 |
|
5 |
import org.apache.catalina.Engine; |
6 |
import org.apache.catalina.core.ApplicationContext; |
7 |
import org.apache.catalina.core.StandardContext; |
8 |
import org.apache.catalina.core.StandardEngine; |
9 |
import org.apache.catalina.core.StandardService; |
10 |
import org.apache.catalina.core.StandardWrapper; |
11 |
import org.apache.jasper.EmbeddedServletOptions; |
12 |
import org.apache.jasper.JasperException; |
13 |
import org.apache.jasper.Options; |
14 |
import org.apache.jasper.servlet.JspServletWrapper; |
15 |
|
16 |
import junit.framework.TestCase; |
17 |
|
18 |
public class JspRuntimeContextTest extends TestCase { |
19 |
|
20 |
JspRuntimeContext context; |
21 |
ApplicationContext ctxt; |
22 |
Options options; |
23 |
|
24 |
protected void setUp() throws Exception { |
25 |
super.setUp(); |
26 |
StandardWrapper config = new StandardWrapper(); |
27 |
config.addInitParameter("maxLoadedJsps", "2"); |
28 |
StandardContext std1 = new StandardContext(); |
29 |
StandardContext std2 = new StandardContext(); |
30 |
Engine std3 = new StandardEngine(); |
31 |
std3.setService(new StandardService()); |
32 |
std2.setParent(std3); |
33 |
std1.setParent(std2); |
34 |
ctxt = new ApplicationContext(std1); |
35 |
options = new EmbeddedServletOptions(config, ctxt); |
36 |
|
37 |
context = new JspRuntimeContext(ctxt, options); |
38 |
} |
39 |
|
40 |
public void testCheckUnloadDisabled() { |
41 |
options = (Options) createMock(Options.class); |
42 |
expect(options.getScratchDir()).andReturn(null); |
43 |
expect(options.getClassPath()).andReturn(null); |
44 |
expect(options.getDevelopment()).andReturn(false); |
45 |
expect(options.getMaxLoadedJsps()).andReturn(-1); |
46 |
replay(options); |
47 |
context = new JspRuntimeContext(ctxt, options); |
48 |
context.checkUnload(); |
49 |
verify(options); |
50 |
} |
51 |
|
52 |
public void testCheckUnloadEnabledSizeTooFewJsps() { |
53 |
options = (Options) createMock(Options.class); |
54 |
expect(options.getScratchDir()).andReturn(null); |
55 |
expect(options.getClassPath()).andReturn(null); |
56 |
expect(options.getDevelopment()).andReturn(false); |
57 |
expect(options.getMaxLoadedJsps()).andReturn(1); |
58 |
expect(options.getCheckInterval()).andReturn(0); |
59 |
expect(options.getMaxLoadedJsps()).andReturn(1); |
60 |
replay(options); |
61 |
context = new JspRuntimeContext(ctxt, options); |
62 |
context.checkUnload(); |
63 |
verify(options); |
64 |
} |
65 |
|
66 |
public void testCheckUnloadEnabledSizeEnoughJsps() throws JasperException { |
67 |
options = (Options) createMock(Options.class); |
68 |
expect(options.getScratchDir()).andReturn(null); |
69 |
expect(options.getClassPath()).andReturn(null); |
70 |
expect(options.getDevelopment()).andReturn(false); |
71 |
expect(options.getMaxLoadedJsps()).andReturn(1); |
72 |
expect(options.getCheckInterval()).andReturn(0); |
73 |
expect(options.getMaxLoadedJsps()).andReturn(1); |
74 |
expect(options.getMaxLoadedJsps()).andReturn(1); |
75 |
replay(options); |
76 |
context = new JspRuntimeContext(ctxt, options); |
77 |
context.addWrapper("first", new JspServletWrapper(new StandardWrapper(), options, "/first.jsp", false, context)); |
78 |
context.addWrapper("second", new JspServletWrapper(new StandardWrapper(), options, "/second.jsp", false, context)); |
79 |
context.checkUnload(); |
80 |
verify(options); |
81 |
} |
82 |
} |