KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > dottedname > DottedNameTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 /*
25  * $Header: /cvs/glassfish/admin/mbeans/tests/com/sun/enterprise/admin/dottedname/DottedNameTest.java,v 1.3 2005/12/25 03:43:07 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:43:07 $
28  */

29  
30
31 package com.sun.enterprise.admin.dottedname;
32
33 /*
34     This MBean must be modified to store its aliases within domain.xml. For now, it uses
35     an internal implementation.
36  */

37 public final class DottedNameTest extends junit.framework.TestCase
38 {
39         public
40     DottedNameTest( )
41     {
42     }
43     
44         public void
45     attemptInvalidName( String JavaDoc name )
46     {
47         try
48         {
49             final DottedName dottedName = new DottedName( name );
50             fail( "expected dotted name to fail: \"" + name + "\"");
51         }
52         catch( Exception JavaDoc e )
53         {
54             // good, we expected to get here
55
}
56     }
57     
58     public final static String JavaDoc LEGAL_CHARS = DottedName.LEGAL_CHARS;
59             
60     public final static String JavaDoc 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 JavaDoc e )
76         {
77             // good
78
}
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 JavaDoc 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 JavaDoc
98     {
99         attemptInvalidName( "" );
100     }
101     
102         public void
103     testScopeOnly()
104         throws Exception JavaDoc
105     {
106         new DottedName( "domain" );
107     }
108     
109         public void
110     testMissingValue()
111         throws Exception JavaDoc
112     {
113         attemptInvalidName( "domain." );
114     }
115     
116         public void
117     testBadSyntax()
118         throws Exception JavaDoc
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 JavaDoc
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 JavaDoc
138     {
139         attemptInvalidName( "mydomain:" );
140     }
141     
142         public void
143     testDomainAndScopeOnly()
144         throws Exception JavaDoc
145     {
146         new DottedName( "mydomain:domain" );
147     }
148     
149         public void
150     testLongName()
151         throws Exception JavaDoc
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 JavaDoc
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 JavaDoc
175     {
176         final String JavaDoc 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 JavaDoc
197     {
198         new DottedName( "domain." + DottedName.escapePart( "" + '.' ) );
199     }
200     
201     
202         public void
203     testLegalChars()
204         throws Exception JavaDoc
205     {
206         for( int i = 0; i < LEGAL_CHARS.length(); ++i )
207         {
208             final char theChar = LEGAL_CHARS.charAt( i );
209             
210             final String JavaDoc escapedChar = DottedName.escapePart( "" + theChar );
211             new DottedName( "domain." + escapedChar );
212         }
213     }
214 }
215
216
217
218
219
220
221
222
223
Popular Tags