1 16 package org.apache.jetspeed.util; 17 18 19 import junit.framework.Test; 21 import junit.framework.TestSuite; 22 23 import org.apache.jetspeed.test.JetspeedTestCase; 25 26 32 33 public class TestValidation extends JetspeedTestCase 34 { 35 40 public TestValidation( String name ) { 41 super( name ); 42 } 43 44 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 return new TestSuite( TestValidation.class ); 61 } 62 63 64 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 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 179 } 180 181 182 183 | Popular Tags |