1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.test;
18
19
20 import org.apache.turbine.modules.actions.sessionvalidator.SessionValidator;
21 import org.apache.turbine.modules.ActionLoader;
22 import org.apache.turbine.modules.PageLoader;
23 import org.apache.turbine.services.resources.TurbineResources;
24 import org.apache.turbine.services.template.TurbineTemplate;
25 import org.apache.turbine.util.RunData;
26
27 /***
28 * This class is designed to aid in the testing of Jetspeed
29 * page generation. It includes methods that mimic what
30 * is done in turbine.
31 *
32 * As a minimum you test case should look like:
33 * <CODE>
34 * {
35 * setupRunData(rundata);
36 * generatePage(rundata);
37 * outputPage(rundata);
38 * }
39 * </CODE>
40 *
41 * @author <a href="paulsp@apache.org">Paul Spencer</a>
42 * @version $Id: TurbineTestUtilities.java,v 1.1 2004/04/07 22:02:41 jford Exp $
43 */
44 public abstract class TurbineTestUtilities
45 {
46 /***
47 * Do all of the initialization and setup of RunData. This includes
48 * setting up the session, users.
49 *
50 * Note: This code is modeled after Turbine's org.apache.turbine.Turbine
51 *
52 * @param rundata Rundata to setup
53 * @throws Exception General exceptions
54 */
55 public static void setupRunData(RunData rundata) throws Exception
56 {
57 if (rundata == null)
58 throw new NullPointerException("rundata is null");
59
60
61 SessionValidator sessionValidator = (SessionValidator)ActionLoader
62 .getInstance().getInstance(TurbineResources.getString(
63 "action.sessionvalidator"));
64 if (sessionValidator == null)
65 throw new NullPointerException("Failed to get a SessonValidator");
66
67
68 rundata.setScreen( rundata.getParameters().getString("screen") );
69 rundata.setAction( rundata.getParameters().getString("action") );
70
71
72 if ( rundata.hasAction()
73 && rundata.getAction().equalsIgnoreCase(TurbineResources
74 .getString("action.login"))
75 || rundata.getAction().equalsIgnoreCase(TurbineResources
76 .getString("action.logout")))
77 {
78 if (rundata.getAction().equalsIgnoreCase(TurbineResources
79 .getString("action.login")))
80 {
81 String[] names = rundata.getSession().getValueNames();
82 if (names != null)
83 {
84 for (int i=0; i< names.length; i++)
85 {
86 rundata.getSession().removeValue(names[i]);
87 }
88 }
89 }
90 ActionLoader.getInstance().exec( rundata, rundata.getAction() );
91 rundata.setAction(null);
92 }
93
94
95 ActionLoader.getInstance().exec(
96 rundata,TurbineResources.getString("action.sessionvalidator") );
97
98
99 ActionLoader.getInstance().exec(
100 rundata,TurbineResources.getString("action.accesscontroller"));
101
102 }
103
104 /***
105 * Generate the page/content defined by rundata
106 * @param rundata Rundata to setup
107 * @throws Exception General exceptions
108 */
109 public static void generatePage(RunData rundata) throws Exception
110 {
111 if (rundata == null)
112 throw new NullPointerException("rundata is null");
113
114 String defaultPage = TurbineTemplate.getDefaultPageName(rundata);
115 PageLoader.getInstance().exec(rundata, defaultPage);
116 }
117
118 /***
119 * Instuct turbine, via rundata, to output the page.
120 *
121 * Note: This code is modeled after Turbine's org.apache.turbine.Turbine
122 *
123 * @param rundata Rundata to setup
124 * @throws Exception General exceptions
125 */
126 public static void outputPage(RunData rundata) throws Exception
127 {
128 if (rundata == null)
129 throw new NullPointerException("rundata is null");
130
131 rundata.getResponse().setLocale( rundata.getLocale() );
132 rundata.getResponse().setContentType( rundata.getContentType() );
133 rundata.getResponse().setStatus( rundata.getStatusCode() );
134 rundata.getPage().output(rundata.getOut());
135
136 try
137 {
138 rundata.getOut().close();
139 }
140 catch (Exception e)
141 {
142
143 }
144 }
145
146 }