This project has retired. For details please refer to its
Attic page.
TurbineTestUtilities xref
1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.test;
1819// Turbine imports20import org.apache.turbine.modules.actions.sessionvalidator.SessionValidator;
21import org.apache.turbine.modules.ActionLoader;
22import org.apache.turbine.modules.PageLoader;
23import org.apache.turbine.services.resources.TurbineResources;
24import org.apache.turbine.services.template.TurbineTemplate;
25import org.apache.turbine.util.RunData;
2627/***28 * This class is designed to aid in the testing of Jetspeed29 * page generation. It includes methods that mimic what30 * 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*/44publicabstractclassTurbineTestUtilities45 {
46/***47 * Do all of the initialization and setup of RunData. This includes48 * setting up the session, users.49 *50 * Note: This code is modeled after Turbine's org.apache.turbine.Turbine51 *52 * @param rundata Rundata to setup53 * @throws Exception General exceptions54 */55publicstaticvoid setupRunData(RunData rundata) throws Exception
56 {
57if (rundata == null)
58thrownew NullPointerException("rundata is null");
5960// Get the instance of the Session Validator.61 SessionValidator sessionValidator = (SessionValidator)ActionLoader
62 .getInstance().getInstance(TurbineResources.getString(
63"action.sessionvalidator"));
64if (sessionValidator == null)
65thrownew NullPointerException("Failed to get a SessonValidator");
6667// Fill in the screen and action variables.68 rundata.setScreen( rundata.getParameters().getString("screen") );
69 rundata.setAction( rundata.getParameters().getString("action") );
7071// Login or out if requested72if ( rundata.hasAction()
73 && rundata.getAction().equalsIgnoreCase(TurbineResources
74 .getString("action.login"))
75 || rundata.getAction().equalsIgnoreCase(TurbineResources
76 .getString("action.logout")))
77 {
78if (rundata.getAction().equalsIgnoreCase(TurbineResources
79 .getString("action.login")))
80 {
81 String[] names = rundata.getSession().getValueNames();
82if (names != null)
83 {
84for (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 }
9394// Do the session validation95 ActionLoader.getInstance().exec(
96 rundata,TurbineResources.getString("action.sessionvalidator") );
9798// Put the access control list (ACL) into rundata.99 ActionLoader.getInstance().exec(
100 rundata,TurbineResources.getString("action.accesscontroller"));
101102 }
103104/***105 * Generate the page/content defined by rundata106 * @param rundata Rundata to setup107 * @throws Exception General exceptions108 */109publicstaticvoid generatePage(RunData rundata) throws Exception
110 {
111if (rundata == null)
112thrownew NullPointerException("rundata is null");
113114 String defaultPage = TurbineTemplate.getDefaultPageName(rundata);
115 PageLoader.getInstance().exec(rundata, defaultPage);
116 }
117118/***119 * Instuct turbine, via rundata, to output the page.120 *121 * Note: This code is modeled after Turbine's org.apache.turbine.Turbine122 *123 * @param rundata Rundata to setup124 * @throws Exception General exceptions125 */126publicstaticvoid outputPage(RunData rundata) throws Exception
127 {
128if (rundata == null)
129thrownew NullPointerException("rundata is null");
130131 rundata.getResponse().setLocale( rundata.getLocale() );
132 rundata.getResponse().setContentType( rundata.getContentType() );
133 rundata.getResponse().setStatus( rundata.getStatusCode() );
134 rundata.getPage().output(rundata.getOut());
135136try137 {
138 rundata.getOut().close();
139 }
140catch (Exception e)
141 {
142// Ignore.143 }
144 }
145146 }