KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > sitecontext > SiteContextActionTest


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.sitecontext;
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 servletunit.struts.*;
31 import org.apache.struts.action.*;
32 import org.apache.cactus.*;
33 import com.methodhead.auth.*;
34 import com.methodhead.aikp.*;
35 import com.methodhead.*;
36
37 public class SiteContextActionTest extends CactusStrutsTestCase {
38
39   private SiteContext siteContext = null;
40   private DynaActionForm form = null;
41   private List list = null;
42
43   static {
44     TestUtils.initLogger();
45   }
46
47   public SiteContextActionTest( String JavaDoc name ) {
48     super( name );
49   }
50
51   public void setUp() {
52     try {
53       super.setUp();
54
55       ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
56
57       TestData.createUsers();
58       AuthUtil.setUser( request, TestData.user1 );
59     }
60     catch ( Exception JavaDoc e ) {
61       fail( e.getMessage() );
62     }
63   }
64
65   public void tearDown()
66   throws
67     Exception JavaDoc {
68     super.tearDown();
69   }
70
71   public void testPopulateForm() {
72     try {
73       setRequestPathInfo( "/siteContext" );
74       addRequestParameter( "action", "edit" );
75       addRequestParameter( "id", "" + TestData.siteContext2.get( "id" ) );
76       actionPerform();
77
78       verifyInputForward();
79
80       form = ( DynaActionForm )getActionForm();
81       assertEquals( "site2.com\nwww.site2.com", form.get( "domainsText" ) );
82       assertEquals( "", form.get( "path" ) );
83     }
84     catch ( Exception JavaDoc e ) {
85       e.printStackTrace();
86       fail();
87     }
88   }
89
90   public void testPopulatePersistable() {
91     try {
92       setRequestPathInfo( "/siteContext" );
93       addRequestParameter( "action", "save" );
94       addRequestParameter( "id", "" + TestData.siteContext1.get( "id" ) );
95       addRequestParameter( "domainsText", "newsite1.com" );
96       addRequestParameter( "path", "test" );
97       actionPerform();
98
99       siteContext = new SiteContext();
100       assertTrue( siteContext.loadForDomainAndPath( "newsite1.com", "test" ) );
101       assertEquals( TestData.siteContext1.get( "id" ), siteContext.get( "id" ) );
102     }
103     catch ( Exception JavaDoc e ) {
104       e.printStackTrace();
105       fail();
106     }
107   }
108
109   public void testDoList() {
110     try {
111       setRequestPathInfo( "/siteContext" );
112       addRequestParameter( "action", "list" );
113       actionPerform();
114
115       verifyForward( "list" );
116
117       form = ( DynaActionForm )getActionForm();
118
119       list = ( List )form.get( "list" );
120       assertEquals( 4, list.size() );
121
122       siteContext = ( SiteContext )list.get( 0 );
123       assertEquals( 1, siteContext.getDomains().size() );
124       assertEquals( "DEFAULT", siteContext.getDomains().get( 0 ) );
125
126       siteContext = ( SiteContext )list.get( 1 );
127       assertEquals( 1, siteContext.getDomains().size() );
128       assertEquals( "site1.com", siteContext.getDomains().get( 0 ) );
129
130       siteContext = ( SiteContext )list.get( 2 );
131       assertEquals( "site2.com", siteContext.getDomains().get( 0 ) );
132       assertEquals( 2, siteContext.getDomains().size() );
133       assertEquals( "www.site2.com", siteContext.getDomains().get( 1 ) );
134
135       siteContext = ( SiteContext )list.get( 3 );
136       assertEquals( 1, siteContext.getDomains().size() );
137       assertEquals( "site3.com", siteContext.getDomains().get( 0 ) );
138       assertEquals( "path", siteContext.getString( "path" ) );
139     }
140     catch ( Exception JavaDoc e ) {
141       e.printStackTrace();
142       fail();
143     }
144   }
145
146   public void testDoCancelSave() {
147     setRequestPathInfo( "/siteContext" );
148     addRequestParameter( "action", "save" );
149     addRequestParameter( "cancel", "Cancel" );
150     addRequestParameter( "id", "" + TestData.siteContext1.get( "id" ) );
151     addRequestParameter( "domainsText", "danhensgen.com" );
152     addRequestParameter( "path", "test" );
153     actionPerform();
154
155     verifyForwardPath( "/siteContext.do?action=list" );
156   }
157
158   public void testDoCancelDelete() {
159     setRequestPathInfo( "/siteContext" );
160     addRequestParameter( "action", "delete" );
161     addRequestParameter( "cancel", "Cancel" );
162     addRequestParameter( "id", "" + TestData.siteContext1.get( "id" ) );
163     addRequestParameter( "domainsText", "danhensgen.com" );
164     addRequestParameter( "path", "test" );
165     actionPerform();
166
167     verifyInputForward();
168   }
169 }
170
Popular Tags