KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.methodhead.auth.*;
31 import com.methodhead.util.*;
32 import com.methodhead.*;
33 import servletunit.struts.*;
34 import org.apache.struts.action.*;
35 import org.apache.commons.io.*;
36 import org.apache.cactus.*;
37
38 public class SiteContextFormTest extends CactusStrutsTestCase {
39
40   private DynaActionForm form = null;
41   private List list = null;
42
43   static {
44     TestUtils.initLogger();
45   }
46
47   public SiteContextFormTest( 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       //
61
// these directories get created during the test
62
//
63
FileUtils.deleteDirectory( ServletUtils.getRealFile( request, "4" ) );
64       FileUtils.deleteDirectory( ServletUtils.getRealFile( request, "WEB-INF/resources/4" ) );
65     }
66     catch ( Exception JavaDoc e ) {
67       fail( e.getMessage() );
68     }
69   }
70
71   public void tearDown()
72   throws
73     Exception JavaDoc {
74     super.tearDown();
75   }
76
77   public void testReset() {
78     setRequestPathInfo( "/siteContext" );
79     addRequestParameter( "action", "saveNew" );
80     addRequestParameter( "domainsText", " danhensgen.com \n\n www.danhensgen.com\n\n " );
81     actionPerform();
82
83     form = ( DynaActionForm )getActionForm();
84     list = ( List )form.get( "domains" );
85     assertEquals( 2, list.size() );
86
87     assertEquals( "danhensgen.com", list.get( 0 ) );
88     assertEquals( "www.danhensgen.com", list.get( 1 ) );
89   }
90
91   public void testValidateNoDomains() {
92     //
93
// no domains
94
//
95
setRequestPathInfo( "/siteContext" );
96     addRequestParameter( "action", "saveNew" );
97     actionPerform();
98
99     verifyInputForward();
100     verifyActionErrors( new String JavaDoc[] { "mhf.missingdomains" } );
101   }
102
103   public void testValidateInvalidDomains() {
104     //
105
// invalid domains
106
//
107
setRequestPathInfo( "/siteContext" );
108     addRequestParameter( "action", "saveNew" );
109     addRequestParameter( "domainsText", "dan hensgen.com" );
110     actionPerform();
111
112     verifyInputForward();
113     verifyActionErrors( new String JavaDoc[] { "mhf.invaliddomain" } );
114   }
115
116   public void testValidateLongDomainName() {
117     //
118
// a long domain name
119
//
120
setRequestPathInfo( "/siteContext" );
121     addRequestParameter( "action", "saveNew" );
122     addRequestParameter( "domainsText", "0123456789012345678901234567890123456789012345678901234567890123456789.com" );
123     actionPerform();
124
125     verifyInputForward();
126     verifyActionErrors( new String JavaDoc[] { "mhf.invaliddomain" } );
127   }
128
129   public void testExistingDomain() throws Exception JavaDoc{
130     //
131
// an existing domain/path
132
//
133
setRequestPathInfo( "/siteContext" );
134     addRequestParameter( "action", "saveNew" );
135     addRequestParameter( "domainsText", "site1.com" );
136     actionPerform();
137
138     verifyInputForward();
139     verifyActionErrors( new String JavaDoc[] { "mhf.domainexists" } );
140   }
141
142   public void testValidateExistingDomain2() {
143     //
144
// an existing domain/path, but not the one being saved
145
//
146
setRequestPathInfo( "/siteContext" );
147     addRequestParameter( "action", "save" );
148     addRequestParameter( "id", "1" );
149     addRequestParameter( "domainsText", "site2.com" );
150     actionPerform();
151
152     verifyInputForward();
153     verifyActionErrors( new String JavaDoc[] { "mhf.domainexists" } );
154   }
155
156   public void testValidateDashes() {
157     //
158
// dashes should be allowed
159
//
160
setRequestPathInfo( "/siteContext" );
161     addRequestParameter( "action", "saveNew" );
162     addRequestParameter( "id", "" );
163     addRequestParameter( "domainsText", "method-head.com" );
164     actionPerform();
165
166     verifyForwardPath( "/siteContext.do?action=list" );
167     verifyNoActionErrors();
168   }
169 }
170
Popular Tags