KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.*;
25 import java.sql.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.test.*;
30 import com.methodhead.auth.*;
31 import com.methodhead.sitecontext.*;
32 import com.methodhead.tree.*;
33 import com.methodhead.*;
34 import servletunit.struts.*;
35 import org.apache.struts.action.*;
36 import org.apache.cactus.*;
37 import com.methodhead.shim.*;
38 import com.methodhead.res.*;
39 import com.methodhead.reg.*;
40
41 public class HomeActionTest extends CactusStrutsTestCase {
42
43   SiteContext siteContext1_ = null;
44   SiteContext siteContext2_ = null;
45   User user1_ = null;
46
47   FoldingTreeNode root = null;
48   SiteMapTree tree = null;
49
50   private void createData() {
51
52     ShimUtils.setUpShimSession( request, SiteContext.getDefaultContext() );
53
54     siteContext1_ = new SiteContext();
55     siteContext1_.getDomains().add( "methodhead.com" );
56     siteContext1_.saveNew();
57
58     siteContext2_ = new SiteContext();
59     siteContext2_.getDomains().add( "danhensgen.com" );
60     siteContext2_.saveNew();
61   }
62
63   static {
64     TestUtils.initLogger();
65     TestUtils.initDb();
66   }
67
68   public HomeActionTest( String JavaDoc name ) {
69     super( name );
70   }
71
72   public void setUp() {
73     try {
74       super.setUp();
75
76       ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
77
78       user1_ = new User();
79       user1_.getRoles().add( DefaultTransferPolicy.ROLE_SYSADMIN );
80
81       AuthUtil.setUser( request, user1_ );
82     }
83     catch ( Exception JavaDoc e ) {
84       fail( e.getMessage() );
85     }
86   }
87
88   public void tearDown()
89   throws
90     Exception JavaDoc {
91     super.tearDown();
92     ShimUtils.tearDownShimSession( request );
93     session.getServletContext().removeAttribute( ShimGlobals.SITEMAPMAP_KEY );
94   }
95
96   public void testDoSwitch() {
97     try {
98       TestData.createUsers();
99       AuthUtil.setUser( request, TestData.user1 );
100
101       session.setAttribute( ResGlobals.FILETREE_KEY, new FileTree() );
102
103       setRequestPathInfo( "/switch" );
104       addRequestParameter( "id", "2" );
105       actionPerform();
106
107       verifyForwardPath( "/home.do" );
108
109       assertNull( session.getAttribute( ResGlobals.FILETREE_KEY ) );
110     }
111     catch ( Exception JavaDoc e ) {
112       e.printStackTrace();
113       fail();
114     }
115   }
116 }
117
Popular Tags