KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > util > jmx > ObjectNameComparatorTest


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 import javax.management.ObjectName JavaDoc;
26
27 import com.sun.appserv.management.util.jmx.ObjectNameComparator;
28 import com.sun.appserv.management.util.jmx.JMXUtil;
29
30
31 public class ObjectNameComparatorTest extends junit.framework.TestCase
32 {
33     private final ObjectNameComparator mComparator;
34     
35         public
36     ObjectNameComparatorTest()
37     {
38         super( "ObjectNameComparatorTest" );
39         
40         mComparator = ObjectNameComparator.INSTANCE;
41     }
42
43        private ObjectName JavaDoc
44     newObjectName( final String JavaDoc s )
45     {
46         return JMXUtil.newObjectName( s );
47     }
48     
49
50         public void
51     testEquals()
52     {
53         final ObjectName JavaDoc name1 = newObjectName( "amx:j2eeType=FOO,name=FOO-NAME" );
54         final ObjectName JavaDoc name2 = newObjectName( "amx:name=FOO-NAME,j2eeType=FOO" );
55         
56         assert mComparator.compare( name1, name2 ) == 0;
57         assert mComparator.compare( name2, name1 ) == 0;
58     }
59     
60         public void
61     testUnequal()
62     {
63         final ObjectName JavaDoc name1 = newObjectName( "amx:j2eeType=FOO,name=FOO-NAME" );
64         final ObjectName JavaDoc name2 = newObjectName( "amx:name=FOO-NAME,j2eeType=FOO" );
65         
66         final ObjectName JavaDoc name3 = newObjectName( "amx:j2eeType=FOO,name=FOO-BAR" );
67         final ObjectName JavaDoc name4 = newObjectName( "amx:name=FOO-BAR,j2eeType=FOO" );
68         
69         final ObjectName JavaDoc nameA = newObjectName( "amx:name=A" );
70         final ObjectName JavaDoc nameB = newObjectName( "amx:name=B" );
71         
72         final ObjectName JavaDoc bbb = newObjectName( "bbb:name=foo" );
73         
74         assert mComparator.compare( name1, name2 ) == 0;
75         assert mComparator.compare( name2, name1 ) == 0;
76         assert mComparator.compare( name3, name4 ) == 0;
77         assert mComparator.compare( name4, name3 ) == 0;
78         
79         assert mComparator.compare( name1, name3 ) > 0;
80         assert mComparator.compare( name2, name3 ) > 0;
81         assert mComparator.compare( name3, name1 ) < 0;
82         assert mComparator.compare( name3, name2 ) < 0;
83         
84         assert mComparator.compare( name1, name4 ) > 0;
85         assert mComparator.compare( name2, name4 ) > 0;
86         assert mComparator.compare( name4, name2 ) < 0;
87         assert mComparator.compare( name4, name1 ) < 0;
88         
89         assert mComparator.compare( name1, nameA ) < 0;
90         assert mComparator.compare( nameA, name1 ) > 0;
91         
92         assert mComparator.compare( nameA, nameB ) < 0;
93         assert mComparator.compare( nameB, nameA ) > 0;
94         
95         assert mComparator.compare( name1, bbb ) < 0;
96         assert mComparator.compare( bbb, name1 ) > 0;
97     }
98     
99 }
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Popular Tags