1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.util;
18
19
20 import junit.awtui.TestRunner;
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23
24
25 import org.apache.cactus.ServletTestCase;
26 import org.apache.cactus.WebRequest;
27 import org.apache.cactus.WebResponse;
28
29
30 import org.apache.jetspeed.capability.CapabilityMap;
31 import org.apache.jetspeed.om.profile.Profile;
32 import org.apache.jetspeed.services.Profiler;
33 import org.apache.jetspeed.services.resources.JetspeedResources;
34 import org.apache.jetspeed.services.rundata.JetspeedRunData;
35 import org.apache.jetspeed.test.TurbineTestUtilities;
36
37
38
39 import org.apache.turbine.services.pull.TurbinePull;
40 import org.apache.turbine.services.velocity.TurbineVelocity;
41 import org.apache.turbine.util.RunData;
42 import org.apache.turbine.util.RunDataFactory;
43
44
45 import org.apache.velocity.context.Context;
46
47 /***
48 *
49 * @author <a href="paulsp@apache.org">Paul Spencer</a>
50 * @version $Id: TestMimeType.java,v 1.1 2004/04/07 22:02:42 jford Exp $
51 */
52
53 public class TestMimeType extends ServletTestCase
54 {
55 private static final String TEST_ANON_USER_NAME = "";
56 private static final String TEST_CONTEXT = null;
57 private static final String TEST_DEFAULT_PAGE = "default";
58 private static final String TEST_HOST = "localhost";
59 private static final String TEST_SERVLET = "/portal";
60 private static final String TEST_GROUP = "apache";
61 private static final String TEST_PAGE = "news";
62 private static final String TEST_USER = "turbine";
63 private static final String TEST_USER_PASSWORD = "turbine";
64
65 private RunData rundata = null;
66
67 /***
68 * Defines the testcase name for JUnit.
69 *
70 * @param name the testcase's name.
71 */
72 public TestMimeType(String name)
73 {
74 super(name);
75 }
76
77 /***
78 * Start the tests.
79 *
80 * @param args the arguments. Not used
81 */
82 public static void main(String args[])
83 {
84 TestRunner.main(new String[] { TestMimeType.class.getName() });
85 }
86
87 /***
88 * Creates the test suite.
89 *
90 * @return a test suite (<code>TestSuite</code>) that includes all methods
91 * starting with "test"
92 */
93 public static Test suite()
94 {
95
96 return new TestSuite(TestMimeType.class);
97 }
98
99 /***
100 * Sets up the test case.
101 *
102 */
103 protected void setUp () throws Exception
104 {
105 }
106
107 /***
108 * Test: DefaultURL
109 * With the default URL "/"
110 * 1) A page is generated
111 * 2) The user is anonymous
112 * 3) Group and Role are not set
113 */
114 public void beginDefaultURL(WebRequest theRequest)
115 {
116 System.out.println("URL = " + theRequest.getURL());
117 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET, "", null);
118 System.out.println("post set URL = " + theRequest.getURL());
119 }
120
121 /***
122 * Execute the test
123 *
124 * @throws Exception
125 */
126 public void testDefaultURL() throws Exception
127 {
128
129 rundata = RunDataFactory.getRunData(request, response, config);
130 assertNotNull("Got rundata", rundata);
131 TurbineTestUtilities.setupRunData(rundata);
132
133
134 CapabilityMap cm = ((JetspeedRunData) rundata).getCapability();
135 assertNotNull("Got Capability", cm);
136
137
138 Profile profile = Profiler.getProfile(rundata);
139 assertNotNull("Got profile from Profiler", profile);
140 System.out.println("DocumentName = " + profile.getDocument().getName());
141
142
143 Context context = TurbineVelocity.getContext(rundata);
144 assertNotNull("Got context", context);
145 TurbinePull.populateContext(context, rundata);
146
147
148 assertNotNull("Got jlink from context", context.get("jlink"));
149
150
151 TurbineTestUtilities.generatePage(rundata);
152 assertEquals("Verifying page's character set",
153 rundata.getCharSet(),
154 JetspeedResources.getString(JetspeedResources.CONTENT_ENCODING_KEY, "utf-8"));
155
156 TurbineTestUtilities.outputPage(rundata);
157
158
159 RunDataFactory.putRunData(rundata);
160 }
161
162 public void endDefaultURL(WebResponse theResponse)
163 {
164 System.out.println("text length = " + theResponse.getText().length());
165 }
166 }