KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > jmx > cmd > ArgHelperOptionsInfoTest


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/cmd/ArgHelperOptionsInfoTest.java,v 1.3 2005/12/25 03:45:28 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:45:28 $
28  */

29 package com.sun.cli.jmx.cmd;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Iterator JavaDoc;
33  
34
35
36 public class ArgHelperOptionsInfoTest extends junit.framework.TestCase
37 {
38
39         public void
40     testCreate()
41         throws ArgHelper.IllegalOptionException
42     {
43         new ArgHelperOptionsInfo();
44         new ArgHelperOptionsInfo( "a b c" );
45         new ArgHelperOptionsInfo( "aa bb,2 cc" );
46         new ArgHelperOptionsInfo( "long-option-dashed-name" );
47         new ArgHelperOptionsInfo( "long.option.dotted.name" );
48         new ArgHelperOptionsInfo( "long_option_underscore_name" );
49         new ArgHelperOptionsInfo( "long-option_mixed.name" );
50     }
51     
52     
53         void
54     checkCreateFailure( String JavaDoc options )
55         throws ArgHelper.IllegalOptionException
56     {
57         try
58         {
59             new ArgHelperOptionsInfo( options );
60             fail( "expected failure from option description \"" + options + "\"" );
61         }
62         catch( Exception JavaDoc e )
63         {
64             // good
65
}
66     }
67     
68         public void
69     testCreateFailures()
70         throws ArgHelper.IllegalOptionException
71     {
72         final String JavaDoc illegals = "~`!@#$%^&*()+={}[]|\\:;\"'<>?,/";
73         
74         for( int i = 0; i < illegals.length(); ++i )
75         {
76             checkCreateFailure( "" + illegals.charAt( i ) );
77         }
78     }
79     
80     
81         public void
82     testIllegals()
83         throws ArgHelper.IllegalOptionException
84     {
85         final ArgHelperOptionsInfo info = new ArgHelperOptionsInfo( "hello h" );
86         
87         assertEquals( false, info.isLegalOption( "hello" ) );
88         assertEquals( false, info.isLegalOption( "-hello" ) );
89         assertEquals( false, info.isLegalOption( "h" ) );
90         assertEquals( false, info.isLegalOption( "--h" ) );
91         assertEquals( false, info.isLegalOption( "-" ) );
92         assertEquals( false, info.isLegalOption( "--" ) );
93         assertEquals( false, info.isLegalOption( "" ) );
94     }
95     
96         public void
97     testLegals()
98         throws ArgHelper.IllegalOptionException
99     {
100         final ArgHelperOptionsInfo info = new ArgHelperOptionsInfo( "hello --there,3 x,1 -y,1" );
101         
102         assertEquals( true, info.isLegalOption( "--hello" ) );
103         assertEquals( true, info.isLegalOption( "--there" ) );
104         assertEquals( true, info.isLegalOption( "-x" ) );
105         assertEquals( true, info.isLegalOption( "-y" ) );
106     }
107     
108     
109         void
110     checkRedundantFailure( String JavaDoc args )
111     {
112         try
113         {
114             new ArgHelperOptionsInfo( args );
115             fail( "expected rejection of redundant option" );
116         }
117         catch( Exception JavaDoc e )
118         {
119         }
120     }
121
122         public void
123     testRedundant()
124         throws ArgHelper.IllegalOptionException
125     {
126         checkRedundantFailure( "a a" );
127         checkRedundantFailure( "aa aa" );
128         checkRedundantFailure( "--aa --aa" );
129         checkRedundantFailure( "-a -a" );
130     }
131
132         public void
133     testMixedArgs()
134         throws ArgHelper.IllegalOptionException
135     {
136         final ArgHelperOptionsInfo info = new ArgHelperOptionsInfo( "a b,1 c,2 d,3 --xyz,4" );
137         
138         assertEquals( true, info.isLegalOption( "-a" ) );
139         assertEquals( false, info.isLegalOption( "--a" ) );
140         assertEquals( 1, info.getNumValues( "-a" ) );
141         assertEquals( true, info.isBoolean( "-a" ) );
142         
143         assertEquals( 1, info.getNumValues( "-b" ) );
144         assertEquals( 2, info.getNumValues( "-c" ) );
145         assertEquals( 3, info.getNumValues( "-d" ) );
146         assertEquals( 4, info.getNumValues( "--xyz" ) );
147         
148     }
149
150
151
152         public
153     ArgHelperOptionsInfoTest()
154     {
155     }
156
157         public void
158     setUp()
159     {
160     }
161     
162         public void
163     tearDown()
164     {
165     }
166
167 }
168
169
Popular Tags