001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.transfer;
022:
023: import java.util.*;
024: import java.sql.*;
025: import java.io.*;
026: import junit.framework.*;
027: import org.apache.log4j.*;
028: import com.methodhead.persistable.*;
029: import com.methodhead.test.*;
030: import servletunit.struts.*;
031: import org.apache.struts.action.*;
032: import org.apache.cactus.*;
033: import com.methodhead.sitecontext.*;
034: import com.methodhead.reg.*;
035: import com.methodhead.aikp.*;
036: import com.methodhead.auth.*;
037: import com.methodhead.property.*;
038: import com.methodhead.*;
039:
040: public class SiteContextActionTest extends CactusStrutsTestCase {
041:
042: SiteContext siteContext = null;
043: SiteExtension siteExtension = null;
044: List list = null;
045: Extension[] extensions = null;
046: DynaActionForm form = null;
047: User user = null;
048:
049: static {
050: TestUtils.initLogger();
051: }
052:
053: public SiteContextActionTest(String name) {
054: super (name);
055: }
056:
057: public void setUp() {
058: try {
059: super .setUp();
060:
061: ConnectionSingleton.runBatchUpdate(new FileReader(
062: "webapp/WEB-INF/db/transfer-reset.sql"));
063: } catch (Exception e) {
064: fail(e.getMessage());
065: }
066: }
067:
068: public void tearDown() throws Exception {
069: super .tearDown();
070: }
071:
072: /*
073: public void testDoDelete() {
074: TestData.createUsers();
075:
076: //
077: // delete the site context
078: //
079: setRequestPathInfo( "/siteContext.do" );
080: addRequestParameter( "action", "delete" );
081: addRequestParameter( "id", "1" );
082: actionPerform();
083:
084: verifyForwardPath( "/siteContext.do?action=list" );
085:
086: //
087: // user/site context association should have been deleted
088: //
089: user = new User();
090: user.load( new IntKey( "1" ) );
091:
092: assertEquals( 0, user.getRoles().size() );
093: }
094: */
095:
096: public void testDoInitExtension() {
097: TestData.createSiteExtensions();
098: AuthUtil.setUser(request, TestData.user1);
099: MockExtension.setInit(false);
100: MockExtension2.setInit(false);
101:
102: //
103: // init MockExtension2
104: //
105: setRequestPathInfo("/initExtension");
106: addRequestParameter("id", "1");
107: addRequestParameter("classname",
108: "com.methodhead.transfer.MockExtension2");
109: actionPerform();
110:
111: verifyForwardPath("/siteContext.do?action=edit&id=1");
112:
113: siteExtension = new SiteExtension();
114: list = siteExtension
115: .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",
124: siteExtension.getString("class_name"));
125: assertEquals(true, siteExtension.getBoolean("enabled"));
126:
127: siteExtension = (SiteExtension) list.get(1);
128: assertEquals("com.methodhead.transfer.MockExtension2",
129: siteExtension.getString("class_name"));
130: assertEquals(true, siteExtension.getBoolean("enabled"));
131:
132: //
133: // mockmodule should have been inited
134: //
135: assertEquals(false, MockExtension.getInit());
136: assertEquals(true, MockExtension2.getInit());
137: }
138:
139: public void testDoDestroyExtension() {
140: TestData.createSiteExtensions();
141: AuthUtil.setUser(request, TestData.user1);
142: MockExtension.setDestroy(0);
143: MockExtension2.setDestroy(0);
144:
145: //
146: // destroy MockExtension
147: //
148: setRequestPathInfo("/destroyExtension");
149: addRequestParameter("id", "1");
150: addRequestParameter("classname",
151: "com.methodhead.transfer.MockExtension2");
152: actionPerform();
153:
154: verifyForward("confirm");
155: }
156:
157: public void testDoDestroyExtensionConfirm() {
158: TestData.createSiteExtensions();
159: AuthUtil.setUser(request, TestData.user1);
160: MockExtension.setDestroy(0);
161: MockExtension2.setDestroy(0);
162:
163: //
164: // destroy MockExtension
165: //
166: setRequestPathInfo("/destroyExtension");
167: addRequestParameter("id", "1");
168: addRequestParameter("classname",
169: "com.methodhead.transfer.MockExtension");
170: addRequestParameter("confirm", "Confirm");
171: actionPerform();
172:
173: verifyForwardPath("/siteContext.do?action=edit&id=1");
174:
175: siteExtension = new SiteExtension();
176: list = siteExtension
177: .loadAllForSiteContext(TestData.siteContext1);
178:
179: //
180: // should have zero modules enabled
181: //
182: assertEquals(0, list.size());
183:
184: //
185: // MockModule2 should have been destroyed for site context 1
186: //
187: assertEquals(1, MockExtension.getDestroy());
188: assertEquals(0, MockExtension2.getDestroy());
189: }
190:
191: public void testDoDisableExtension() {
192: TestData.createSiteExtensions();
193: AuthUtil.setUser(request, TestData.user1);
194:
195: //
196: // disable MockExtension
197: //
198: setRequestPathInfo("/disableExtension");
199: addRequestParameter("id", "1");
200: addRequestParameter("classname",
201: "com.methodhead.transfer.MockExtension");
202: actionPerform();
203:
204: verifyForwardPath("/siteContext.do?action=edit&id=1");
205:
206: siteExtension = new SiteExtension();
207: list = siteExtension
208: .loadAllForSiteContext(TestData.siteContext1);
209:
210: //
211: // should have MockExtension disabled
212: //
213: assertEquals(1, list.size());
214:
215: siteExtension = (SiteExtension) list.get(0);
216: assertEquals("com.methodhead.transfer.MockExtension",
217: siteExtension.getString("class_name"));
218: assertEquals(false, siteExtension.getBoolean("enabled"));
219: }
220:
221: public void testDoEnableExtension() {
222: TestData.createSiteExtensions();
223: AuthUtil.setUser(request, TestData.user1);
224:
225: //
226: // disable MockExtension
227: //
228: siteExtension = new SiteExtension();
229: siteExtension.load(TestData.siteContext1,
230: "com.methodhead.transfer.MockExtension");
231: siteExtension.setBoolean("enabled", false);
232: siteExtension.save();
233:
234: //
235: // enable MockExtension
236: //
237: setRequestPathInfo("/enableExtension");
238: addRequestParameter("id", "1");
239: addRequestParameter("classname",
240: "com.methodhead.transfer.MockExtension");
241: actionPerform();
242:
243: verifyForwardPath("/siteContext.do?action=edit&id=1");
244:
245: siteExtension = new SiteExtension();
246: list = siteExtension
247: .loadAllForSiteContext(TestData.siteContext1);
248:
249: //
250: // should have MockExtension disabled
251: //
252: assertEquals(1, list.size());
253:
254: siteExtension = (SiteExtension) list.get(0);
255: assertEquals("com.methodhead.transfer.MockExtension",
256: siteExtension.getString("class_name"));
257: assertEquals(true, siteExtension.getBoolean("enabled"));
258: }
259: }
|