1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.jetspeed.util;
17
18
19
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22
23
24 import org.apache.jetspeed.test.JetspeedTestCase;
25
26 /***
27 * Command Line Test Validation routines.
28 *
29 * @author <a href="mailto:ben.woodward@bbc.co.uk">Ben Woodward</a>
30 * @version $Id: TestValidation.java,v 1.1 2004/04/07 22:02:42 jford Exp $
31 */
32
33 public class TestValidation extends JetspeedTestCase
34 {
35 /***
36 * Defines the testcase name for JUnit.
37 *
38 * @param name the testcase's name.
39 */
40 public TestValidation( String name ) {
41 super( name );
42 }
43
44 /***
45 * Start the tests.
46 *
47 * @param args the arguments. Not used
48 */
49 public static void main(String args[]) {
50 junit.awtui.TestRunner.main( new String[] { TestValidation.class.getName() } );
51 }
52
53 public void setup() {
54 System.out.println("Setup: Testing Validation");
55 }
56
57 public static Test suite()
58 {
59
60 return new TestSuite( TestValidation.class );
61 }
62
63
64
65
66 public void testAlphaNumeric() throws Exception
67 {
68 String goodString = "The quick brown fox jumped over the lazy dog 0123456789";
69 String badString = "><£$$!&.*";
70
71 assertTrue(ValidationHelper.isAlphaNumeric(goodString, false));
72 assertTrue(!ValidationHelper.isAlphaNumeric(badString, false));
73 }
74
75 public void testLooseAlphaNumeric() throws Exception
76 {
77
78
79
80
81 String goodString[] = {"a","a.a","aaa.aaa","a-a","aaa-aaa", "(aaa) aaa", "+aa-aaa.aa", "555-4545", "555,4545"};
82 String badString[] = {"><£$$!&*."};
83
84
85 for (int ia=0; ia < goodString.length; ia++)
86 {
87 assertTrue(ValidationHelper.isLooseAlphaNumeric(goodString[ia], false));
88 System.out.println(goodString[ia]+" is Good: "+ValidationHelper.isLooseAlphaNumeric(goodString[ia], false));
89 }
90
91 for (int ib=0; ib < badString.length; ib++)
92 {
93 assertTrue(!ValidationHelper.isLooseAlphaNumeric(badString[ib], false));
94 System.out.println(badString[ib]+" is Bad: "+!ValidationHelper.isLooseAlphaNumeric(badString[ib], false));
95 }
96 }
97
98 public void testDecimal() throws Exception
99 {
100
101 String goodString[] = {"1","1.1","11.1","1.11","11.11"};
102 String badString[] = {"a","1.a","1-a","1..1","1.1.1"};
103
104 for (int ia=0; ia < goodString.length; ia++)
105 {
106 assertTrue(ValidationHelper.isDecimal(goodString[ia], false));
107 }
108
109 for (int ib=0; ib < badString.length; ib++)
110 {
111 assertTrue(!ValidationHelper.isDecimal(badString[ib], false));
112 }
113 }
114
115 public void testInteger() throws Exception
116 {
117
118 String goodString[] = {"1","11","111"};
119 String badString[] = {"a","1.1","1.a","1-a","1..1","1.1.1"};
120
121 for (int ia=0; ia < goodString.length; ia++)
122 {
123 assertTrue(ValidationHelper.isInteger(goodString[ia], false));
124 }
125
126 for (int ib=0; ib < badString.length; ib++)
127 {
128 assertTrue(!ValidationHelper.isInteger(badString[ib], false));
129 }
130 }
131
132
133 public void testEmailAddress() throws Exception
134 {
135
136 String goodString[] = {"a@b.c","a.b@c.d","aa@b.c","aaa@b.c"};
137 String badString[] = {"*@b.c","a","a@","@a",".@a","a@b.","a@b","a@@b.c","a@b@c.d","aaa@b^.c"};
138
139 for (int ia=0; ia < goodString.length; ia++)
140 {
141 assertTrue(ValidationHelper.isEmailAddress(goodString[ia], false));
142 }
143
144 for (int ib=0; ib < badString.length; ib++)
145 {
146 assertTrue(!ValidationHelper.isEmailAddress(badString[ib], false));
147 }
148 }
149
150 public void testURL() throws Exception
151 {
152 String goodString = "http://www.apache.org";
153 String badString = "me.";
154
155 assertTrue(ValidationHelper.isURL(goodString, false));
156 assertTrue(!ValidationHelper.isURL(badString, false));
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179 }
180
181
182