KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > dottedname > DottedNameRegistryTest


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/mbeans/tests/com/sun/enterprise/admin/dottedname/DottedNameRegistryTest.java,v 1.3 2005/12/25 03:43:06 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:43:06 $
28  */

29  
30 package com.sun.enterprise.admin.dottedname;
31  
32 import java.util.Set JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34 import javax.management.MalformedObjectNameException JavaDoc;
35
36 public class DottedNameRegistryTest extends junit.framework.TestCase
37 {
38         DottedNameRegistry1To1Impl
39     createNew()
40     {
41         return( new DottedNameRegistry1To1Impl() );
42     }
43     
44         public void
45     testCreation()
46     {
47         createNew();
48     }
49     
50         public void
51     testNewIsEmpty()
52     {
53         assertEquals( 0, createNew().allDottedNameStrings().size() );
54     }
55     
56         public void
57     testAdd()
58         throws MalformedObjectNameException JavaDoc
59     {
60         final DottedNameRegistry1To1Impl registry = createNew();
61         final String JavaDoc dottedName = "a.b.c";
62         final ObjectName JavaDoc objectName = new ObjectName JavaDoc( ":name=test" );
63         
64         registry.add( dottedName, objectName );
65         
66         assertEquals( objectName, registry.dottedNameToObjectName( dottedName ) );
67         assertEquals( dottedName, registry.objectNameToDottedName( objectName ) );
68         
69         assertEquals( 1, registry.allDottedNameStrings().size() );
70         assertEquals( 1, registry.allObjectNames().size() );
71         assertEquals( dottedName, (String JavaDoc)registry.allDottedNameStrings().iterator().next() );
72     }
73     
74         public void
75     testRemove()
76         throws MalformedObjectNameException JavaDoc
77     {
78         final DottedNameRegistry1To1Impl registry = createNew();
79         final String JavaDoc dottedName = "a.b.c";
80         final ObjectName JavaDoc objectName = new ObjectName JavaDoc( ":name=test" );
81         
82         registry.add( dottedName, objectName );
83         registry.remove( dottedName, objectName );
84         
85         assertEquals( 0, registry.allDottedNameStrings().size() );
86         assertEquals( 0, registry.allObjectNames().size() );
87     }
88     
89         public void
90     testReplaceWorks()
91         throws MalformedObjectNameException JavaDoc
92     {
93         final DottedNameRegistry1To1Impl registry = createNew();
94         final String JavaDoc dottedName1 = "a.b.c";
95         final String JavaDoc dottedName2 = "a.b.c.d";
96         final ObjectName JavaDoc objectName = new ObjectName JavaDoc( ":name=test" );
97         
98         registry.add( dottedName1, objectName );
99         registry.add( dottedName2, objectName );
100         assertEquals( dottedName2, registry.objectNameToDottedName( objectName ) );
101     }
102
103     
104         public void
105     test1To1Mapping()
106         throws MalformedObjectNameException JavaDoc
107     {
108         final DottedNameRegistry1To1Impl registry = createNew();
109         final String JavaDoc dottedName1 = "a.b.c";
110         final String JavaDoc dottedName2 = "a.b.c.d";
111         final ObjectName JavaDoc objectName = new ObjectName JavaDoc( ":name=test" );
112         
113         registry.add( dottedName1, objectName );
114         registry.add( dottedName2, objectName );
115         
116         assertEquals( 1, registry.allDottedNameStrings().size() );
117         assertEquals( dottedName2, (String JavaDoc)registry.allDottedNameStrings().iterator().next() );
118     }
119     
120     /*
121         public void
122     testSpeed()
123         throws MalformedObjectNameException
124     {
125         final long start = System.currentTimeMillis();
126         
127         final DottedNameRegistry1To1Impl registry = createNew();
128         final String dottedName1 = "a.b.c";
129         final String dottedName2 = "a.b.c.d";
130         final ObjectName objectName = new ObjectName( ":name=test" );
131         
132         final int ITERATIONS = 50 * 1024;
133         for( int i = 0; i < ITERATIONS; ++i )
134         {
135             final String dottedName = "test." + i;
136             final ObjectName newObjectName = new ObjectName( ":" + "number=" + i );
137             
138             registry.add( dottedName, newObjectName );
139             registry.remove( dottedName, newObjectName );
140         }
141         
142         final long elapsed = System.currentTimeMillis() - start;
143         System.out.println( "elapsed = " + elapsed + " = " +
144             ((float)ITERATIONS / (float)elapsed) + " per milli" );
145     }
146     */

147 }
148
149
150
151
152
153
154
155
156
157
158
Popular Tags