1 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 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 e ) { 84 fail( e.getMessage() ); 85 } 86 } 87 88 public void tearDown() 89 throws 90 Exception { 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 e ) { 112 e.printStackTrace(); 113 fail(); 114 } 115 } 116 } 117 | Popular Tags |