1 57 58 package util; 59 60 import java.util.StringTokenizer ; 61 62 import junit.framework.Test; 63 import junit.framework.TestCase; 64 import junit.framework.TestSuite; 65 66 import org.apache.wsif.util.WSIFUtils; 67 68 73 public class WildcardTest extends TestCase { 74 75 public WildcardTest(String name) { 76 super(name); 77 } 78 79 public static void main(String [] args) { 80 junit.textui.TestRunner.run(suite()); 81 } 82 83 public static Test suite() { 84 return new TestSuite(WildcardTest.class); 85 } 86 87 public void testWildcardCompare() throws Throwable { 88 89 assertTrue( "t1", cmp( "foo.com", "foo.com" ) ); 90 assertTrue( "t2", !cmp( "xxx.com", "foo.com" ) ); 91 assertTrue( "t3", !cmp( "foo.com", "xxx.com" ) ); 92 93 assertTrue( "t4", cmp( "*.com", "foo.com" ) ); 94 assertTrue( "t5", cmp( "foo.*", "foo.com" ) ); 95 assertTrue( "t6", !cmp( "*.com", "foo.cxm" ) ); 96 assertTrue( "t7", !cmp( "foo.*", "fxo.com" ) ); 97 98 assertTrue( "t8", cmp( "hur.*.com", "hur.ibm.com" ) ); 99 assertTrue( "t9", !cmp( "hur.*.com", "hxr.ibm.com" ) ); 100 assertTrue( "t10", !cmp( "hur.*.com", "hur.ibm.cxm" ) ); 101 102 assertTrue( "t11", cmp( "hur*y.*.com", "hursley.ibm.com" ) ); 103 assertTrue( "t12", !cmp( "hur*y.*.com", "xursley.ibm.com" ) ); 104 assertTrue( "t13", !cmp( "hur*y.*.com", "hurslex.ibm.com" ) ); 105 assertTrue( "t14", !cmp( "hur*y.*.com", "hursley.ibm.cxm" ) ); 106 107 assertTrue( "t15", !cmp( "foo.com", "" ) ); 108 assertTrue( "t16", !cmp( "", "foo.com" ) ); 109 assertTrue( "t17", cmp( "*", "foo.com" ) ); 110 111 assertTrue( "t18", !cmp( "hjkj", null ) ); 112 assertTrue( "t19", !cmp( "*", null ) ); 113 assertTrue( "t20", !cmp( null, "foo.com" ) ); 114 assertTrue( "t21", !cmp( null, null ) ); 115 116 } 117 118 private boolean cmp(String s1, String s2) { 119 return WSIFUtils.wildcardCompare( s1, s2, '*' ); 120 } 121 122 } 123
| Popular Tags
|