KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > ext > offline > OfflineDottedNamesRegistryTest


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.ext.offline;
24
25 import java.util.Set JavaDoc;
26 import java.util.HashSet JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29
30 import com.sun.appserv.management.base.Util;
31 import com.sun.appserv.management.util.misc.GSetUtil;
32
33 import com.sun.enterprise.management.AMXTestBase;
34 import com.sun.enterprise.management.offline.OfflineDottedNamesRegistry;
35
36
37 /**
38  */

39 public final class OfflineDottedNamesRegistryTest extends junit.framework.TestCase
40 {
41         public
42     OfflineDottedNamesRegistryTest()
43     {
44     }
45
46         private OfflineDottedNamesRegistry
47     create()
48     {
49         return new OfflineDottedNamesRegistry();
50     }
51     
52     
53         private ObjectName JavaDoc
54     createObjectName( final String JavaDoc j2eeType, final String JavaDoc name)
55     {
56         return Util.newObjectName( "amx", Util.makeRequiredProps( j2eeType, name ) );
57     }
58     
59         public void
60     testCreate()
61     {
62         create();
63     }
64     
65         private Set JavaDoc<String JavaDoc>
66     dummySet()
67     {
68         return GSetUtil.newStringSet( "hello", "there" );
69     }
70     
71     
72         public void
73     testIllegalAdd()
74     {
75         final OfflineDottedNamesRegistry reg = create();
76         
77         try
78         {
79             reg.addMapping( null, "foo", dummySet() );
80             assert false : "Expected exception adding null ObjectName";
81         }
82         catch ( Exception JavaDoc e )
83         {
84         }
85         
86         try
87         {
88             reg.addMapping( createObjectName( "XXX", "ZZZ" ), null, dummySet() );
89             assert false : "Expected exception adding null prefix";
90         }
91         catch ( Exception JavaDoc e )
92         {
93         }
94         
95         try
96         {
97             reg.addMapping( createObjectName( "XXX", "ZZZ" ), "foo", null );
98             assert false : "Expected exception adding null attributes";
99         }
100         catch ( Exception JavaDoc e )
101         {
102         }
103         
104         try
105         {
106             reg.addMapping( createObjectName( "XXX", "ZZZ" ), "foo", dummySet() );
107             // try to add again
108
reg.addMapping( createObjectName( "XXX", "ZZZ" ), "foo", dummySet() );
109             assert false : "Expected exception adding same ObjectName";
110         }
111         catch ( Exception JavaDoc e )
112         {
113         }
114     }
115     
116     
117         public void
118     testAddRemove()
119     {
120         final OfflineDottedNamesRegistry reg = create();
121         
122         final int ITER = 1000;
123         
124         final Set JavaDoc<String JavaDoc> attrs = dummySet();
125         final ObjectName JavaDoc[] objectNames = new ObjectName JavaDoc[ ITER ];
126         final String JavaDoc[] prefixes = new String JavaDoc[ ITER ];
127         
128         for( int i = 0; i < ITER; ++i )
129         {
130             final String JavaDoc prefix = "foo" + i;
131             final ObjectName JavaDoc objectName = createObjectName( "test" + i, "" + i );
132
133             objectNames[ i ] = objectName;
134             prefixes[ i ] = prefix;
135             
136             reg.addMapping( objectName, prefix, attrs );
137             assert( reg.getPrefix( objectName ) == prefix );
138             assert( reg.getObjectName( prefix ) == objectName );
139             assert( reg.getLegalAttributes( objectName ).equals( attrs ) );
140         }
141         
142         for( int i = 0; i < ITER; ++i )
143         {
144             final ObjectName JavaDoc objectName = objectNames[ i ];
145             final String JavaDoc prefix = prefixes[ i ];
146             
147             assert( reg.getPrefix( objectName ) == prefix );
148             assert( reg.getObjectName( prefix ) == objectName );
149             assert( reg.getLegalAttributes( objectName ).equals( attrs ) );
150             
151             reg.removeMapping( objectName );
152             
153             assert( reg.getPrefix( objectName) == null );
154             assert( reg.getObjectName( prefixes[ i ] ) == null );
155             assert( reg.getLegalAttributes( objectName ) == null );
156         }
157     }
158 }
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
Popular Tags