1 20 21 package com.methodhead.shim; 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 38 public class HomeActionTest extends CactusStrutsTestCase { 39 40 TestSite site_ = null; 41 SiteContext siteContext1_ = null; 42 SiteContext siteContext2_ = null; 43 44 FoldingTreeNode root = null; 45 SiteMapTree tree = null; 46 47 private void createData() { 48 site_ = new TestSite(); 49 site_.createPages(); 50 site_.createLinks(); 51 site_.createSiteMap(); 52 53 ShimUtils.setUpShimSession( request, SiteContext.getDefaultContext() ); 54 55 siteContext1_ = new SiteContext(); 56 siteContext1_.getDomains().add( "methodhead.com" ); 57 siteContext1_.saveNew(); 58 59 siteContext2_ = new SiteContext(); 60 siteContext2_.getDomains().add( "danhensgen.com" ); 61 siteContext2_.saveNew(); 62 } 63 64 static { 65 TestUtils.initLogger(); 66 TestUtils.initDb(); 67 } 68 69 public HomeActionTest( String name ) { 70 super( name ); 71 } 72 73 public void setUp() { 74 try { 75 super.setUp(); 76 77 ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) ); 78 79 TestData.createUsers(); 80 AuthUtil.setUser( request, TestData.user1 ); 81 } 82 catch ( Exception e ) { 83 fail( e.getMessage() ); 84 } 85 } 86 87 public void tearDown() 88 throws 89 Exception { 90 super.tearDown(); 91 ShimUtils.tearDownShimSession( request ); 92 session.getServletContext().removeAttribute( ShimGlobals.SITEMAPMAP_KEY ); 93 } 94 95 public void testDoHome() { 96 try { 97 ShimUtils.setUpShimSession( request, SiteContext.getDefaultContext() ); 98 99 setRequestPathInfo( "/home" ); 100 actionPerform(); 101 102 verifyForward( "form" ); 103 } 104 catch ( Exception e ) { 105 e.printStackTrace(); 106 fail(); 107 } 108 } 109 110 public void testDoHomeWithHomePage() { 111 try { 112 createData(); 113 114 setRequestPathInfo( "/home" ); 115 actionPerform(); 116 117 verifyForwardPath( "/editPage.do?id=1" ); 118 } 119 catch ( Exception e ) { 120 e.printStackTrace(); 121 fail(); 122 } 123 } 124 125 public void testDoHomeNoSiteContext() { 126 try { 127 setRequestPathInfo( "/home" ); 128 actionPerform(); 129 130 verifyForward( "form" ); 131 } 132 catch ( Exception e ) { 133 e.printStackTrace(); 134 fail(); 135 } 136 } 137 138 public void testDoOpenLink() { 139 try { 140 createData(); 141 142 tree = ShimUtils.getSiteMapTree( request ); 143 root = ( FoldingTreeNode )tree.getRoot(); 144 assertTrue( !root.getOpened() ); 145 146 setRequestPathInfo( "/link" ); 147 addRequestParameter( "open", "" + root.hashCode() ); 148 actionPerform(); 149 150 verifyForwardPath( "/siteMap.do" ); 151 152 assertTrue( root.getOpened() ); 153 154 setRequestPathInfo( "/link" ); 155 addRequestParameter( "close", "" + root.hashCode() ); 156 actionPerform(); 157 158 verifyForwardPath( "/siteMap.do" ); 159 160 assertTrue( !root.getOpened() ); 161 } 162 catch ( Exception e ) { 163 e.printStackTrace(); 164 fail(); 165 } 166 } 167 168 public void testDoSwitch() { 169 try { 170 createData(); 171 172 setRequestPathInfo( "/switch" ); 173 addRequestParameter( "id", "" + siteContext2_.getInt( "id" ) ); 174 actionPerform(); 175 176 verifyForwardPath( "/home.do" ); 177 178 assertEquals( siteContext2_, SiteContext.getContext( request ) ); 179 assertNotNull( ShimUtils.getSiteMapTree( request ) ); 180 } 181 catch ( Exception e ) { 182 e.printStackTrace(); 183 fail(); 184 } 185 } 186 187 public void testDoSiteMap() { 188 try { 189 createData(); 190 191 setRequestPathInfo( "/siteMap" ); 192 actionPerform(); 193 194 verifyForward( "form" ); 195 } 196 catch ( Exception e ) { 197 e.printStackTrace(); 198 fail(); 199 } 200 } 201 } 202 | Popular Tags |