KickJava   Java API By Example, From Geeks To Geeks.

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