KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > jmx > support > AliasMgrTest


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-cli/cli-api/src/java/com/sun/cli/jmx/support/AliasMgrTest.java,v 1.3 2005/12/25 03:45:44 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:45:44 $
28  */

29  
30
31 package com.sun.cli.jmx.support;
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 AliasMgrTest extends junit.framework.TestCase
38 {
39         public
40     AliasMgrTest( )
41     {
42     }
43     
44         public void
45     attemptInvalidName( String JavaDoc name )
46     {
47         try
48         {
49             create().createAlias( name, "bad name" );
50             fail( "expected alias 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 = "-_." +
59             "0123456789" +
60             "abcdefghijklmnopqrstuvwxyz" +
61             "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
62             
63     public final static String JavaDoc ILLEGAL_CHARS =
64             "!@#$%^&*()+=" +
65             "~`{}[]:;\"\'<>,?/" +
66             "\n\r\t";
67
68         AliasMgrMBean
69     create( )
70     {
71         return( new AliasMgr( new AliasMgrHashMapImpl() ) );
72     }
73     
74         public void
75     testEmptyName()
76         throws Exception JavaDoc
77     {
78         attemptInvalidName( "" );
79     }
80         public void
81     testIllegalChars()
82     {
83         for( int i = 0; i < ILLEGAL_CHARS.length(); ++i )
84         {
85             final char theChar = ILLEGAL_CHARS.charAt( i );
86             
87             attemptInvalidName( "" + theChar );
88             attemptInvalidName( "x" + theChar + "y" );
89         }
90     }
91     
92         public void
93     testLegalChars()
94         throws Exception JavaDoc
95     {
96         final AliasMgrMBean aliasMgr = create();
97                 
98         aliasMgr.createAlias( LEGAL_CHARS, "test" );
99             
100         for( int i = 0; i < LEGAL_CHARS.length(); ++i )
101         {
102             final char theChar = LEGAL_CHARS.charAt( i );
103             
104             aliasMgr.createAlias( "" + theChar, "test" );
105         }
106     }
107     
108     
109     final String JavaDoc TEST = "test.";
110     final String JavaDoc TEST_VALUE = "test value";
111     
112         public void
113     testLifecycle()
114         throws Exception JavaDoc
115     {
116         final AliasMgrMBean aliasMgr = create();
117         
118         aliasMgr.createAlias( TEST, TEST_VALUE );
119         assertEquals( TEST_VALUE, aliasMgr.resolveAlias( TEST ) );
120         
121         aliasMgr.deleteAlias( TEST );
122         assertEquals( null, aliasMgr.resolveAlias( TEST ) );
123     }
124     
125     
126     
127         public void
128     testList()
129         throws Exception JavaDoc
130     {
131         final AliasMgrMBean aliasMgr = create();
132         assertEquals( 0, aliasMgr.listAliases( true ).length );
133         assertEquals( 0, aliasMgr.getAliases( ).length );
134         
135         aliasMgr.createAlias( TEST, TEST_VALUE );
136         assertEquals( 1, aliasMgr.listAliases( true ).length );
137         assertEquals( 1, aliasMgr.listAliases( false ).length );
138         assertEquals( 1, aliasMgr.getAliases( ).length );
139         
140         String JavaDoc [] listedAliases = aliasMgr.listAliases( false );
141         assertEquals( TEST, listedAliases[ 0 ] );
142         
143         listedAliases = aliasMgr.listAliases( true );
144         assertEquals( TEST + "=" + TEST_VALUE , listedAliases[ 0 ] );
145     }
146 }
147
148
149
150
151
152
153
154
155
Popular Tags