KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > TestFixture


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package com.openedit;
14
15 import java.io.ByteArrayOutputStream JavaDoc;
16 import java.io.File JavaDoc;
17 import java.io.StringWriter JavaDoc;
18
19 import com.openedit.page.Page;
20 import com.openedit.page.PageRequestKeys;
21 import com.openedit.page.manage.PageManager;
22 import com.openedit.servlet.OpenEditEngine;
23 import com.openedit.users.User;
24 import com.openedit.users.UserManager;
25 import com.openedit.users.filesystem.FileSystemUserManager;
26 import com.openedit.util.SessionTool;
27 import com.openedit.web.Browser;
28
29
30 /**
31  * This class is a text fixture for JPublish/Open Edit.
32  *
33  * @author Eric Galluzzo
34  */

35 public class TestFixture
36 {
37     protected String JavaDoc fieldPath = null;
38     protected BaseWebServer fieldWebServer;
39
40     /**
41      * Constructor for TestFixture.
42      */

43     public TestFixture()
44     {
45         super();
46     }
47
48     /**
49      * @return
50      */

51     public String JavaDoc getPath()
52     {
53         return fieldPath;
54     }
55
56     /**
57      * @param inPath
58      */

59     public void setPath(String JavaDoc inPath)
60     {
61         fieldPath = inPath;
62     }
63
64
65
66     public WebPageRequest createPageRequest() throws OpenEditException
67     {
68         BaseWebPageRequest context = new TestWebPageRequest();
69
70         Browser browser = new Browser("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
71
72         Page page = getPageManager().getPage("/index.html");
73         context.putPageValue( PageRequestKeys.PAGE, page);
74         context.putPageValue( PageRequestKeys.CONTENT, page);
75         context.putPageValue( PageRequestKeys.BROWSER, browser);
76         context.putPageValue( PageRequestKeys.HOME, "");
77
78         ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
79         context.putPageValue( PageRequestKeys.OUTPUT_STREAM, out);
80         context.putPageValue( PageRequestKeys.OUTPUT_WRITER, new StringWriter JavaDoc());
81         User admin = getUserManager().getUser("admin");
82         FileSystemUserManager userManager = (FileSystemUserManager)getUserManager();
83         //System.out.println( "Group directory: " + userManager.getGroupDirectory().getAbsolutePath() );
84
//System.out.println( "User directory: " + userManager.getUserDirectory().getAbsolutePath() );
85
if ( admin != null )
86         {
87             context.putPageValue( PageRequestKeys.USER, admin );
88         }
89         context.putPageValue("username", "admin");
90
91         //URLUtilities util = (URLUtilities) inContext.getPageValue( "url_util" );
92
context.putPageValue(PageRequestKeys.WEB_SERVER_PATH,"http://localhost:8080");
93         SessionTool sessionTool = new SessionTool( context, getModuleManager() );
94         context.putPageValue( PageRequestKeys.CLASSTOOL, sessionTool );
95
96         getEngine().createPageStreamer( page, context);
97
98         return context;
99     }
100     
101     public WebPageRequest createPageRequest(String JavaDoc inPath)
102         throws OpenEditException
103     {
104         WebPageRequest context = (WebPageRequest) createPageRequest();
105         context.putPageValue("path", inPath);
106
107         Page dynamicpage = getPageManager().getPage(inPath);
108         context.putPageValue( PageRequestKeys.PAGE, dynamicpage);
109         context.putPageValue( PageRequestKeys.CONTENT, dynamicpage);
110         context.putPageValue( PageRequestKeys.USER, getUserManager().getUser("admin"));
111         getEngine().createPageStreamer( dynamicpage, context);
112
113         return context;
114     }
115
116     public OpenEditEngine getEngine()
117     {
118         return getWebServer().getOpenEditEngine();
119     }
120     public ModuleManager getModuleManager()
121     {
122         return getWebServer().getModuleManager();
123     }
124     
125     public PageManager getPageManager()
126     {
127         return getWebServer().getPageManager();
128     }
129     public UserManager getUserManager()
130     {
131         return getWebServer().getUserManager();
132     }
133     public WebServer getWebServer()
134     {
135         if (fieldWebServer == null)
136         {
137             fieldWebServer = new BaseWebServer();
138             String JavaDoc rootPath = System.getProperty("oe.root.path");
139             if ( rootPath == null )
140             {
141                 rootPath = "resources/test";
142             }
143             fieldWebServer.setRootDirectory(new File JavaDoc( rootPath));
144             fieldWebServer.initialize();
145         }
146
147         return fieldWebServer;
148     }
149 }
150
Popular Tags