1 23 24 29 30 31 package com.sun.enterprise.admin.dottedname; 32 33 37 public final class DottedNameTest extends junit.framework.TestCase 38 { 39 public 40 DottedNameTest( ) 41 { 42 } 43 44 public void 45 attemptInvalidName( String name ) 46 { 47 try 48 { 49 final DottedName dottedName = new DottedName( name ); 50 fail( "expected dotted name to fail: \"" + name + "\""); 51 } 52 catch( Exception e ) 53 { 54 } 56 } 57 58 public final static String LEGAL_CHARS = DottedName.LEGAL_CHARS; 59 60 public final static String ILLEGAL_CHARS = 61 "!#%^&+=" + 62 "~`:\"\',?" + 63 "\n\r\t\"\'"; 64 65 66 private static final char BACKSLASH = '\\'; 67 public void 68 testEscapedEscapeChar() 69 { 70 try 71 { 72 DottedName dn = new DottedName( "test" + BACKSLASH + "Name" ); 73 assert( false ); 74 } 75 catch( IllegalArgumentException e ) 76 { 77 } 79 80 final DottedName dn = new DottedName( "test" + BACKSLASH + BACKSLASH + "Name" ); 81 assertEquals( "test" + BACKSLASH + BACKSLASH + "Name", dn.toString() ); 82 } 83 84 public void 85 testEscapedDot() 86 { 87 final String name = "test" + BACKSLASH + ".1.part" + BACKSLASH + ".1"; 88 final DottedName dn = new DottedName( name ); 89 assertEquals( "test.1", dn.getScope() ); 90 assertEquals( "part.1", dn.getParts().get( 0 ) ); 91 92 93 } 94 95 public void 96 testEmptyName() 97 throws Exception 98 { 99 attemptInvalidName( "" ); 100 } 101 102 public void 103 testScopeOnly() 104 throws Exception 105 { 106 new DottedName( "domain" ); 107 } 108 109 public void 110 testMissingValue() 111 throws Exception 112 { 113 attemptInvalidName( "domain." ); 114 } 115 116 public void 117 testBadSyntax() 118 throws Exception 119 { 120 attemptInvalidName( "." ); 121 attemptInvalidName( ".." ); 122 attemptInvalidName( "..." ); 123 attemptInvalidName( ".x.." ); 124 attemptInvalidName( "x.x.x." ); 125 } 126 127 public void 128 testWithDomain() 129 throws Exception 130 { 131 new DottedName( "mydomain:domain.locale" ); 132 new DottedName( "mydomain:domain.a.b.c.foo" ); 133 } 134 135 public void 136 testDomainOnly() 137 throws Exception 138 { 139 attemptInvalidName( "mydomain:" ); 140 } 141 142 public void 143 testDomainAndScopeOnly() 144 throws Exception 145 { 146 new DottedName( "mydomain:domain" ); 147 } 148 149 public void 150 testLongName() 151 throws Exception 152 { 153 final DottedName dn = new DottedName( "mydomain:scope.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p" ); 154 155 assertEquals( dn.getDomain(), "mydomain" ); 156 assertEquals( dn.getScope(), "scope" ); 157 assertEquals( dn.getParts().size(), 15 ); 158 assertEquals( dn.getParts().get( 14 ), "p" ); 159 } 160 161 public void 162 testEscapedName() 163 throws Exception 164 { 165 final DottedName dn = new DottedName( "domain.server\\.1.port" ); 166 167 assertEquals( dn.getScope(), "domain" ); 168 assertEquals( dn.getParts().get( 0 ), "server.1" ); 169 assertEquals( dn.getParts().get( 1 ), "port" ); 170 } 171 172 public void 173 testThatToStringMatchesOrig() 174 throws Exception 175 { 176 final String TEST = "domain.server\\.1.port"; 177 final DottedName dn = new DottedName( TEST ); 178 179 assertEquals( dn.toString(), TEST ); 180 } 181 182 public void 183 testIllegalChars() 184 { 185 for( int i = 0; i < ILLEGAL_CHARS.length(); ++i ) 186 { 187 final char theChar = ILLEGAL_CHARS.charAt( i ); 188 189 attemptInvalidName( "" + theChar ); 190 attemptInvalidName( "domain." + theChar + "y" ); 191 } 192 } 193 194 public void 195 testNameWithPartOfDot() 196 throws Exception 197 { 198 new DottedName( "domain." + DottedName.escapePart( "" + '.' ) ); 199 } 200 201 202 public void 203 testLegalChars() 204 throws Exception 205 { 206 for( int i = 0; i < LEGAL_CHARS.length(); ++i ) 207 { 208 final char theChar = LEGAL_CHARS.charAt( i ); 209 210 final String escapedChar = DottedName.escapePart( "" + theChar ); 211 new DottedName( "domain." + escapedChar ); 212 } 213 } 214 } 215 216 217 218 219 220 221 222 223 | Popular Tags |