KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > TestData


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead;
22
23 import org.apache.commons.beanutils.*;
24 import com.methodhead.persistable.*;
25 import com.methodhead.sitecontext.*;
26 import com.methodhead.property.*;
27 import com.methodhead.reg.*;
28 import com.methodhead.transfer.*;
29 import com.methodhead.shim.*;
30 import java.sql.*;
31 import org.apache.commons.io.*;
32 import java.io.*;
33 import java.util.*;
34 import org.apache.commons.io.filefilter.*;
35
36 public class TestData {
37
38   // constructors /////////////////////////////////////////////////////////////
39

40   // constants ////////////////////////////////////////////////////////////////
41

42   // classes //////////////////////////////////////////////////////////////////
43

44   // methods //////////////////////////////////////////////////////////////////
45

46   public static void createSiteContexts() {
47     siteContext1 = new SiteContext();
48     siteContext1.getDomains().add( "site1.com" );
49     siteContext1.saveNew();
50
51     siteContext2 = new SiteContext();
52     siteContext2.getDomains().add( "site2.com" );
53     siteContext2.getDomains().add( "www.site2.com" );
54     siteContext2.saveNew();
55
56     siteContext3 = new SiteContext();
57     siteContext3.getDomains().add( "site3.com" );
58     siteContext3.setString( "path", "path" );
59     siteContext3.saveNew();
60   }
61
62   public static void createProperties() {
63     Property.setProperty( SiteContext.getDefaultContext(), SiteExtension.PROPERTY_EXTENSIONS, "com.methodhead.transfer.MockExtension,com.methodhead.transfer.MockExtension2", "", new Boolean JavaDoc( true ) );
64   }
65
66   public static void createSiteExtensions() {
67     createUsers();
68     createProperties();
69
70     siteExtension1 = new SiteExtension();
71     siteExtension1.setInt( "sitecontext_id", siteContext1.getInt( "id" ) );
72     siteExtension1.setString( "class_name", "com.methodhead.transfer.MockExtension" );
73     siteExtension1.setBoolean( "enabled", true );
74     siteExtension1.saveNew();
75   }
76
77   public static void createSiteContextAikps()
78   throws
79     SQLException {
80     createDynaClassAndTable();
81
82     siteContextAikp1 = new SiteContextAikp( dynaClass );
83     siteContextAikp1.setSiteContext( siteContext1 );
84     siteContextAikp1.setString( "field", "siteContextAikp1" );
85     siteContextAikp1.saveNew();
86
87     siteContextAikp2 = new SiteContextAikp( dynaClass );
88     siteContextAikp2.setSiteContext( siteContext1 );
89     siteContextAikp2.setString( "field", "siteContextAikp2" );
90     siteContextAikp2.saveNew();
91
92     siteContextAikp3 = new SiteContextAikp( dynaClass );
93     siteContextAikp3.setSiteContext( siteContext2 );
94     siteContextAikp3.setString( "field", "siteContextAikp3" );
95     siteContextAikp3.saveNew();
96   }
97
98   public static void createDynaClassAndTable()
99   throws
100     SQLException {
101     createSiteContexts();
102
103     try {
104       ConnectionSingleton.runUpdate( "DROP TABLE sitecontextaikp" );
105     }
106     catch ( SQLException e ) {
107     }
108     ConnectionSingleton.runUpdate( "CREATE TABLE sitecontextaikp (id INT NOT NULL, sitecontext_id INT NOT NULL, field VARCHAR(64) NOT NULL)" );
109
110     DynaProperty[] dynaProperties =
111       new DynaProperty[] {
112         new DynaProperty( "id", Integer JavaDoc.class ),
113         new DynaProperty( "sitecontext_id", Integer JavaDoc.class ),
114         new DynaProperty( "field", String JavaDoc.class )
115       };
116
117     dynaClass =
118       new BasicDynaClass(
119         "sitecontextaikp", SiteContextAikp.class, dynaProperties );
120   }
121
122   public static void createRoles() {
123     createSiteContexts();
124
125     role1 = new Role();
126     role1.setSiteContext( siteContext1 );
127     role1.setName( DefaultTransferPolicy.ROLE_SYSADMIN );
128
129     role2 = new Role();
130     role2.setSiteContext( siteContext1 );
131     role2.setName( DefaultTransferPolicy.ROLE_SITEADMIN );
132
133     role3 = new Role();
134     role3.setSiteContext( siteContext2 );
135     role3.setName( DefaultTransferPolicy.ROLE_WEBMASTER );
136
137     role4 = new Role();
138     role4.setSiteContext( SiteContext.getDefaultContext() );
139     role4.setName( DefaultTransferPolicy.ROLE_SYSADMIN );
140
141     role5 = new Role();
142     role5.setSiteContext( siteContext3 );
143     role5.setName( DefaultTransferPolicy.ROLE_WEBMASTER );
144   }
145
146   public static void createUsers() {
147     createRoles();
148
149     user1 = new User();
150     user1.setString( "password", "password" );
151     user1.getRoles().add( role1 );
152     user1.getRoles().add( role4 ); // need this for a lot of tests
153
user1.getContact().setString( "firstname", "User1" );
154     user1.getContact().setString( "lastname", "BBB" );
155     user1.getContact().setString( "email", "test1@methodhead.com" );
156     user1.saveNew();
157
158     user2 = new User();
159     user2.setString( "password", "password" );
160     user2.getRoles().add( role2 );
161     user2.getContact().setString( "firstname", "User2" );
162     user2.getContact().setString( "lastname", "CCC" );
163     user2.getContact().setString( "email", "test2@methodhead.com" );
164     user2.saveNew();
165
166     user3 = new User();
167     user3.setString( "password", "password" );
168     user3.getRoles().add( role3 );
169     user3.getRoles().add( role5 );
170     user3.getContact().setString( "firstname", "User3" );
171     user3.getContact().setString( "lastname", "AAA" );
172     user3.getContact().setString( "email", "test3@methodhead.com" );
173     user3.saveNew();
174   }
175
176   public static void createPages() {
177     createSiteContexts();
178
179     Panel panel = null;
180
181     panel = new Panel();
182     panel.setName( "body" );
183     panel.setModuleClass( "com.methodhead.shim.MockModule" );
184
185     page1 = new Page();
186     page1.setSiteContext( SiteContext.getDefaultContext() );
187     page1.set( "title", "Page1" );
188     page1.set( "alttitle", "altPage1" );
189     page1.set( "aliasname", "page1" );
190     page1.setBoolean( "hidden", false );
191     page1.setString( "template", "template.jsp" );
192     page1.set( "metadescription", "metadescription" );
193     page1.set( "metakeywords", "metakeywords" );
194     page1.addPanel( panel );
195     page1.saveNew();
196
197     page2 = new Page();
198     page2.setSiteContext( SiteContext.getDefaultContext() );
199     page2.saveNew();
200
201     page3 = new Page();
202     page3.setSiteContext( SiteContext.getDefaultContext() );
203     page3.saveNew();
204
205     page4 = new Page();
206     page4.setSiteContext( SiteContext.getDefaultContext() );
207     page4.saveNew();
208
209     page5 = new Page();
210     page5.setSiteContext( SiteContext.getDefaultContext() );
211     page5.saveNew();
212   }
213
214   public static void createLinks() {
215     createPages();
216
217     // Link1
218
// Link2
219
// Link3
220
// Link4
221
// Link5
222
link1 = new Link();
223     link1.setTitle( "Link1" );
224     link1.setPageId( page1.getInt( "id" ) );
225
226     link2 = new Link();
227     link2.setTitle( "Link2" );
228     link2.setPageId( page2.getInt( "id" ) );
229
230     link3 = new Link();
231     link3.setTitle( "Link3" );
232     link3.setPageId( page3.getInt( "id" ) );
233
234     link4 = new Link();
235     link4.setTitle( "Link4" );
236     link4.setPageId( page4.getInt( "id" ) );
237
238     link5 = new Link();
239     link5.setTitle( "Link5" );
240     link5.setPageId( page5.getInt( "id" ) );
241
242     link1.add( link2 );
243     link2.add( link3 );
244     link1.add( link4 );
245     link1.add( link5 );
246   }
247
248   public static void createSiteMap() {
249     createLinks();
250
251     siteMap1 = new SiteMap();
252     siteMap1.setSiteContext( SiteContext.getDefaultContext() );
253     siteMap1.setRoot( link1 );
254     siteMap1.save();
255   }
256
257   public static void createPageNotFoundPage() {
258     createSiteMap();
259
260     pageNotFoundPage = new Page();
261     pageNotFoundPage.setSiteContext( SiteContext.getDefaultContext() );
262     pageNotFoundPage.set( "title", "Page Not Found Page" );
263     pageNotFoundPage.set( "aliasname", "pagenotfound" );
264     pageNotFoundPage.setBoolean( "hidden", false );
265     pageNotFoundPage.setString( "template", "template3.jsp" ); // we'll use this to distinguish this page in tests
266
pageNotFoundPage.saveNew();
267
268     pageNotFoundLink = new Link();
269     pageNotFoundLink.setTitle( "Page Not Found Page" );
270     pageNotFoundLink.setPageId( pageNotFoundPage.getInt( "id" ) );
271
272     link1.add( pageNotFoundLink );
273
274     siteMap1.save();
275   }
276
277   public static void createWebappFiles(
278     File webappDir )
279   throws
280     IOException {
281
282     //
283
// delete test files if they exist
284
//
285
FileUtils.deleteDirectory( new File( webappDir, "0" ) );
286     FileUtils.deleteDirectory( new File( webappDir, "1" ) );
287     FileUtils.deleteDirectory( new File( webappDir, "2" ) );
288     FileUtils.deleteDirectory( new File( webappDir, "3" ) );
289     FileUtils.deleteDirectory( new File( webappDir, "WEB-INF/resources" ) );
290
291     //
292
// copy files; we have to skip svn directories because cactus doesn't seem
293
// to delete them when starting tests and this hangs up the process
294
//
295
for ( Iterator iter = FileUtils.iterateFiles( new File( "support/webapp", "" ), TrueFileFilter.INSTANCE, FileFilterUtils.makeSVNAware( TrueFileFilter.INSTANCE ) ); iter.hasNext(); ) {
296       File file = ( File )iter.next();
297       FileUtils.copyFile( file, new File( webappDir, file.getPath().substring( "support/webapp/".length() ) ) );
298     }
299   }
300
301   // properties ///////////////////////////////////////////////////////////////
302

303   // attributes ///////////////////////////////////////////////////////////////
304

305   public static SiteContext siteContext1 = null;
306   public static SiteContext siteContext2 = null;
307   public static SiteContext siteContext3 = null;
308
309   public static SiteExtension siteExtension1 = null;
310
311   public static SiteContextAikp siteContextAikp1 = null;
312   public static SiteContextAikp siteContextAikp2 = null;
313   public static SiteContextAikp siteContextAikp3 = null;
314
315   public static DynaClass dynaClass = null;
316
317   public static Role role1 = null;
318   public static Role role2 = null;
319   public static Role role3 = null;
320   public static Role role4 = null;
321   public static Role role5 = null;
322
323   public static User user1 = null;
324   public static User user2 = null;
325   public static User user3 = null;
326
327   public static Page page1 = null;
328   public static Page page2 = null;
329   public static Page page3 = null;
330   public static Page page4 = null;
331   public static Page page5 = null;
332   public static Page pageNotFoundPage = null;
333
334   public static Link link1 = null;
335   public static Link link2 = null;
336   public static Link link3 = null;
337   public static Link link4 = null;
338   public static Link link5 = null;
339   public static Link pageNotFoundLink = null;
340
341   public static SiteMap siteMap1 = null;
342 }
343
Popular Tags