KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > LoginActionTest


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.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 JavaDoc 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 JavaDoc e ) {
59       fail( e.getMessage() );
60     }
61   }
62
63   public void tearDown()
64   throws
65     Exception JavaDoc {
66     super.tearDown();
67   }
68
69   public void testDoLoginNoSite() throws Exception JavaDoc {
70     //
71
// log in to no site
72
//
73
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 JavaDoc {
86     //
87
// log in to a site, no path
88
//
89
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 JavaDoc {
104     //
105
// log into site with path
106
//
107
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