KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > transfer > SiteContextActionTest


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.transfer;
22
23 import java.util.*;
24 import java.sql.*;
25 import java.io.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.test.*;
30 import servletunit.struts.*;
31 import org.apache.struts.action.*;
32 import org.apache.cactus.*;
33 import com.methodhead.sitecontext.*;
34 import com.methodhead.reg.*;
35 import com.methodhead.aikp.*;
36 import com.methodhead.auth.*;
37 import com.methodhead.property.*;
38 import com.methodhead.*;
39
40 public class SiteContextActionTest extends CactusStrutsTestCase {
41
42   SiteContext siteContext = null;
43   SiteExtension siteExtension = null;
44   List list = null;
45   Extension[] extensions = null;
46   DynaActionForm form = null;
47   User user = null;
48
49   static {
50     TestUtils.initLogger();
51   }
52
53   public SiteContextActionTest( String JavaDoc name ) {
54     super( name );
55   }
56
57   public void setUp() {
58     try {
59       super.setUp();
60
61       ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
62     }
63     catch ( Exception JavaDoc e ) {
64       fail( e.getMessage() );
65     }
66   }
67
68   public void tearDown()
69   throws
70     Exception JavaDoc {
71     super.tearDown();
72   }
73
74 /*
75   public void testDoDelete() {
76     TestData.createUsers();
77
78     //
79     // delete the site context
80     //
81     setRequestPathInfo( "/siteContext.do" );
82     addRequestParameter( "action", "delete" );
83     addRequestParameter( "id", "1" );
84     actionPerform();
85
86     verifyForwardPath( "/siteContext.do?action=list" );
87
88     //
89     // user/site context association should have been deleted
90     //
91     user = new User();
92     user.load( new IntKey( "1" ) );
93
94     assertEquals( 0, user.getRoles().size() );
95   }
96 */

97
98   public void testDoInitExtension() {
99     TestData.createSiteExtensions();
100     AuthUtil.setUser( request, TestData.user1 );
101     MockExtension.setInit( false );
102     MockExtension2.setInit( false );
103
104     //
105
// init MockExtension2
106
//
107
setRequestPathInfo( "/initExtension" );
108     addRequestParameter( "id", "1" );
109     addRequestParameter( "classname", "com.methodhead.transfer.MockExtension2" );
110     actionPerform();
111
112     verifyForwardPath( "/siteContext.do?action=edit&id=1" );
113
114     siteExtension = new SiteExtension();
115     list = siteExtension.loadAllForSiteContext( TestData.siteContext1 );
116
117     //
118
// should have two modules enabled
119
//
120
assertEquals( 2, list.size() );
121
122     siteExtension = ( SiteExtension )list.get( 0 );
123     assertEquals( "com.methodhead.transfer.MockExtension", siteExtension.getString( "class_name" ) );
124     assertEquals( true, siteExtension.getBoolean( "enabled" ) );
125
126     siteExtension = ( SiteExtension )list.get( 1 );
127     assertEquals( "com.methodhead.transfer.MockExtension2", siteExtension.getString( "class_name" ) );
128     assertEquals( true, siteExtension.getBoolean( "enabled" ) );
129
130     //
131
// mockmodule should have been inited
132
//
133
assertEquals( false, MockExtension.getInit() );
134     assertEquals( true, MockExtension2.getInit() );
135   }
136
137   public void testDoDestroyExtension() {
138     TestData.createSiteExtensions();
139     AuthUtil.setUser( request, TestData.user1 );
140     MockExtension.setDestroy( 0 );
141     MockExtension2.setDestroy( 0 );
142
143     //
144
// destroy MockExtension
145
//
146
setRequestPathInfo( "/destroyExtension" );
147     addRequestParameter( "id", "1" );
148     addRequestParameter( "classname", "com.methodhead.transfer.MockExtension2" );
149     actionPerform();
150
151     verifyForward( "confirm" );
152   }
153
154   public void testDoDestroyExtensionConfirm() {
155     TestData.createSiteExtensions();
156     AuthUtil.setUser( request, TestData.user1 );
157     MockExtension.setDestroy( 0 );
158     MockExtension2.setDestroy( 0 );
159
160     //
161
// destroy MockExtension
162
//
163
setRequestPathInfo( "/destroyExtension" );
164     addRequestParameter( "id", "1" );
165     addRequestParameter( "classname", "com.methodhead.transfer.MockExtension" );
166     addRequestParameter( "confirm", "Confirm" );
167     actionPerform();
168
169     verifyForwardPath( "/siteContext.do?action=edit&id=1" );
170
171     siteExtension = new SiteExtension();
172     list = siteExtension.loadAllForSiteContext( TestData.siteContext1 );
173
174     //
175
// should have zero modules enabled
176
//
177
assertEquals( 0, list.size() );
178
179     //
180
// MockModule2 should have been destroyed for site context 1
181
//
182
assertEquals( 1, MockExtension.getDestroy() );
183     assertEquals( 0, MockExtension2.getDestroy() );
184   }
185
186   public void testDoDisableExtension() {
187     TestData.createSiteExtensions();
188     AuthUtil.setUser( request, TestData.user1 );
189
190     //
191
// disable MockExtension
192
//
193
setRequestPathInfo( "/disableExtension" );
194     addRequestParameter( "id", "1" );
195     addRequestParameter( "classname", "com.methodhead.transfer.MockExtension" );
196     actionPerform();
197
198     verifyForwardPath( "/siteContext.do?action=edit&id=1" );
199
200     siteExtension = new SiteExtension();
201     list = siteExtension.loadAllForSiteContext( TestData.siteContext1 );
202
203     //
204
// should have MockExtension disabled
205
//
206
assertEquals( 1, list.size() );
207
208     siteExtension = ( SiteExtension )list.get( 0 );
209     assertEquals( "com.methodhead.transfer.MockExtension", siteExtension.getString( "class_name" ) );
210     assertEquals( false, siteExtension.getBoolean( "enabled" ) );
211   }
212
213   public void testDoEnableExtension() {
214     TestData.createSiteExtensions();
215     AuthUtil.setUser( request, TestData.user1 );
216
217     //
218
// disable MockExtension
219
//
220
siteExtension = new SiteExtension();
221     siteExtension.load( TestData.siteContext1, "com.methodhead.transfer.MockExtension" );
222     siteExtension.setBoolean( "enabled", false );
223     siteExtension.save();
224
225     //
226
// enable MockExtension
227
//
228
setRequestPathInfo( "/enableExtension" );
229     addRequestParameter( "id", "1" );
230     addRequestParameter( "classname", "com.methodhead.transfer.MockExtension" );
231     actionPerform();
232
233     verifyForwardPath( "/siteContext.do?action=edit&id=1" );
234
235     siteExtension = new SiteExtension();
236     list = siteExtension.loadAllForSiteContext( TestData.siteContext1 );
237
238     //
239
// should have MockExtension disabled
240
//
241
assertEquals( 1, list.size() );
242
243     siteExtension = ( SiteExtension )list.get( 0 );
244     assertEquals( "com.methodhead.transfer.MockExtension", siteExtension.getString( "class_name" ) );
245     assertEquals( true, siteExtension.getBoolean( "enabled" ) );
246   }
247 }
248
Popular Tags