KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > jmx > util > ObjectNameQueryImplTest


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

29 package com.sun.cli.jmx.util;
30
31 import java.util.Set JavaDoc;
32 import java.util.HashSet JavaDoc;
33
34 import javax.management.ObjectName JavaDoc;
35
36 public class ObjectNameQueryImplTest extends junit.framework.TestCase
37 {
38         public void
39     testCreation()
40     {
41         new ObjectNameQueryImpl();
42     }
43     
44     static final Set JavaDoc EmptySet = java.util.Collections.EMPTY_SET;
45     static final String JavaDoc [] EmptyStrings = new String JavaDoc [0];
46     
47         static Set JavaDoc
48     createSet( ObjectName JavaDoc name )
49     {
50         final HashSet JavaDoc s = new HashSet JavaDoc();
51         
52         s.add( name );
53         
54         return( s );
55     }
56     
57         static Set JavaDoc
58     createSet( ObjectName JavaDoc [] names )
59     {
60         final HashSet JavaDoc s = new HashSet JavaDoc();
61         
62         for( int i = 0; i < names.length; ++i )
63         {
64             s.add( names[ i ] );
65         }
66         
67         return( s );
68     }
69     
70     
71         static ObjectName JavaDoc
72     createName( String JavaDoc nameString )
73     {
74         ObjectName JavaDoc name = null;
75         
76         try
77         {
78             name = new ObjectName JavaDoc( nameString );
79         }
80         catch( Exception JavaDoc e )
81         {
82             assert( false );
83         }
84         return( name );
85     }
86     
87         public void
88     testEmptySet()
89     {
90         final ObjectNameQuery q = new ObjectNameQueryImpl();
91         
92         assertEquals( 0, q.matchAny( EmptySet, null, null ).size() );
93         assertEquals( 0, q.matchAny( EmptySet, EmptyStrings, EmptyStrings ).size() );
94         assertEquals( 0, q.matchAny( EmptySet, null, EmptyStrings ).size() );
95         assertEquals( 0, q.matchAny( EmptySet, EmptyStrings, null ).size() );
96         
97         assertEquals( 0, q.matchAll( EmptySet, null, null ).size() );
98         assertEquals( 0, q.matchAll( EmptySet, EmptyStrings, EmptyStrings ).size() );
99         assertEquals( 0, q.matchAll( EmptySet, null, EmptyStrings ).size() );
100         assertEquals( 0, q.matchAll( EmptySet, EmptyStrings, null ).size() );
101     }
102     
103         public void
104     testSingleItem()
105     {
106         final ObjectName JavaDoc name1 = createName( ":name=test,type=test" );
107         final Set JavaDoc testSet = createSet( name1 );
108         
109         final ObjectNameQuery q = new ObjectNameQueryImpl();
110         
111         assertEquals( 1, q.matchAny( testSet,
112             null,
113             null ).size() );
114         
115         assertEquals( 1, q.matchAny( testSet,
116             new String JavaDoc [] { "type" },
117             new String JavaDoc [] { "test" } ).size() );
118             
119         assertEquals( 1, q.matchAny( testSet,
120             new String JavaDoc [] { "type" },
121             null ).size() );
122             
123         assertEquals( 1, q.matchAny( testSet,
124             null,
125             new String JavaDoc [] { "test" } ).size() );
126             
127             
128         assertEquals( 1, q.matchAny( testSet,
129             new String JavaDoc [] { "t.*" },
130             new String JavaDoc [] { ".*e.*" } ).size() );
131             
132             
133         assertEquals( 1, q.matchAny( testSet,
134             null,
135             new String JavaDoc [] { ".*e.*" } ).size() );
136         
137         
138         assertEquals( 0, q.matchAny( testSet, EmptyStrings, EmptyStrings ).size() );
139         assertEquals( 0, q.matchAny( testSet, null, EmptyStrings ).size() );
140         assertEquals( 0, q.matchAny( testSet, EmptyStrings, null ).size() );
141     }
142 }
143
144
145
146
147
148
149
Popular Tags