1 23 package com.sun.enterprise.management.util.jmx; 24 25 import javax.management.ObjectName ; 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 44 newObjectName( final String s ) 45 { 46 return JMXUtil.newObjectName( s ); 47 } 48 49 50 public void 51 testEquals() 52 { 53 final ObjectName name1 = newObjectName( "amx:j2eeType=FOO,name=FOO-NAME" ); 54 final ObjectName 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 name1 = newObjectName( "amx:j2eeType=FOO,name=FOO-NAME" ); 64 final ObjectName name2 = newObjectName( "amx:name=FOO-NAME,j2eeType=FOO" ); 65 66 final ObjectName name3 = newObjectName( "amx:j2eeType=FOO,name=FOO-BAR" ); 67 final ObjectName name4 = newObjectName( "amx:name=FOO-BAR,j2eeType=FOO" ); 68 69 final ObjectName nameA = newObjectName( "amx:name=A" ); 70 final ObjectName nameB = newObjectName( "amx:name=B" ); 71 72 final ObjectName 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 |