1 23 package com.sun.enterprise.management.ext.offline; 24 25 import java.util.Set ; 26 import java.util.HashSet ; 27 28 import javax.management.ObjectName ; 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 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 54 createObjectName( final String j2eeType, final String 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 <String > 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 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 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 e ) 101 { 102 } 103 104 try 105 { 106 reg.addMapping( createObjectName( "XXX", "ZZZ" ), "foo", dummySet() ); 107 reg.addMapping( createObjectName( "XXX", "ZZZ" ), "foo", dummySet() ); 109 assert false : "Expected exception adding same ObjectName"; 110 } 111 catch ( Exception 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 <String > attrs = dummySet(); 125 final ObjectName [] objectNames = new ObjectName [ ITER ]; 126 final String [] prefixes = new String [ ITER ]; 127 128 for( int i = 0; i < ITER; ++i ) 129 { 130 final String prefix = "foo" + i; 131 final ObjectName 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 objectName = objectNames[ i ]; 145 final String 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 |