1 package org.apache.turbine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.servlet.ServletConfig;
23 import javax.servlet.ServletContext;
24 import javax.servlet.ServletException;
25
26 import org.apache.turbine.test.BaseTestCase;
27 import org.apache.turbine.test.EnhancedMockHttpServletResponse;
28 import org.apache.turbine.util.TurbineConfig;
29
30 import com.mockobjects.servlet.MockHttpServletRequest;
31
32
33
34
35
36
37
38
39
40 public class TurbineTest extends BaseTestCase
41 {
42
43 public TurbineTest(String name) throws Exception
44 {
45 super(name);
46 }
47
48 public void testTurbineAndFirstGet() throws Exception
49 {
50 TurbineConfig tc = new TurbineConfig(".",
51 "/conf/test/CompleteTurbineResources.properties");
52 tc.initialize();
53
54 ServletConfig config = (ServletConfig) tc;
55 ServletContext context = config.getServletContext();
56 assertNotNull(Turbine.getDefaultServerData());
57 assertEquals("", Turbine.getServerName());
58 assertEquals("80", Turbine.getServerPort());
59 assertEquals("", Turbine.getScriptName());
60 Turbine t = tc.getTurbine();
61
62 MockHttpServletRequest request = getMockRequest();
63 EnhancedMockHttpServletResponse resp = new EnhancedMockHttpServletResponse();
64
65 t.doGet(request, resp);
66
67 assertEquals("8080", Turbine.getServerPort());
68 t.destroy();
69 }
70
71 public void testDefaultInputEncoding() throws Exception
72 {
73 TurbineConfig tc = new TurbineConfig(".",
74 "/conf/test/CompleteTurbineResources.properties");
75 tc.initialize();
76 Turbine t = tc.getTurbine();
77 assertNotNull(t.getDefaultInputEncoding());
78 assertEquals(TurbineConstants.PARAMETER_ENCODING_DEFAULT, t.getDefaultInputEncoding());
79 t.destroy();
80 }
81
82 public void testNonDefaultEncoding() throws ServletException
83 {
84 TurbineConfig tc = new TurbineConfig(".",
85 "/conf/test/CompleteTurbineResourcesWithEncoding.properties");
86 tc.initialize();
87 Turbine t = tc.getTurbine();
88 assertNotNull(t.getDefaultInputEncoding());
89 assertEquals("UTF-8", t.getDefaultInputEncoding());
90 }
91
92 }