1 20 21 package com.methodhead.shim; 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 com.methodhead.sitecontext.*; 31 import com.methodhead.*; 32 import com.methodhead.auth.*; 33 import servletunit.struts.*; 34 import org.apache.struts.action.*; 35 import org.apache.cactus.*; 36 37 public class LoginActionTest extends CactusStrutsTestCase { 38 39 SiteContext siteContext = null; 40 41 static { 42 TestUtils.initLogger(); 43 TestUtils.initDb(); 44 } 45 46 public LoginActionTest( String name ) { 47 super( name ); 48 } 49 50 public void setUp() { 51 try { 52 super.setUp(); 53 54 ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) ); 55 56 TestData.createUsers(); 57 } 58 catch ( Exception e ) { 59 fail( e.getMessage() ); 60 } 61 } 62 63 public void tearDown() 64 throws 65 Exception { 66 super.tearDown(); 67 } 68 69 public void testDoLoginNoSite() throws Exception { 70 setRequestPathInfo( "/login" ); 74 addRequestParameter( "login", "test1@methodhead.com" ); 75 addRequestParameter( "password", "password" ); 76 addRequestParameter( "site", "" ); 77 actionPerform(); 78 79 verifyForward( "loggedIn" ); 80 81 assertNull( SiteContext.getContext( request ) ); 82 assertNull( session.getAttribute( ShimGlobals.SITEMAPTREE_KEY ) ); 83 } 84 85 public void testDoLoginSite() throws Exception { 86 setRequestPathInfo( "/login" ); 90 addRequestParameter( "login", "test2@methodhead.com" ); 91 addRequestParameter( "password", "password" ); 92 addRequestParameter( "site", "site1.com" ); 93 actionPerform(); 94 95 verifyForward( "loggedIn" ); 96 97 siteContext = SiteContext.getContext( request ); 98 assertNotNull( siteContext ); 99 assertEquals( TestData.siteContext1, siteContext ); 100 assertNotNull( session.getAttribute( ShimGlobals.SITEMAPTREE_KEY ) ); 101 } 102 103 public void testDoLoginSiteWithPath() throws Exception { 104 setRequestPathInfo( "/login" ); 108 addRequestParameter( "login", "test3@methodhead.com" ); 109 addRequestParameter( "password", "password" ); 110 addRequestParameter( "site", "site3.com/path" ); 111 actionPerform(); 112 113 verifyForward( "loggedIn" ); 114 115 siteContext = SiteContext.getContext( request ); 116 assertNotNull( siteContext ); 117 assertEquals( TestData.siteContext3, siteContext ); 118 assertNotNull( session.getAttribute( ShimGlobals.SITEMAPTREE_KEY ) ); 119 } 120 } 121 | Popular Tags |