1 23 package com.sun.enterprise.management.helper; 24 25 import java.util.Set ; 26 import java.util.HashSet ; 27 import java.util.Map ; 28 import java.util.HashMap ; 29 30 import com.sun.appserv.management.base.XTypes; 31 32 import com.sun.appserv.management.base.Util; 33 34 import com.sun.appserv.management.helper.RefHelper; 35 36 import com.sun.appserv.management.config.RefConfig; 37 import com.sun.appserv.management.config.ResourceRefConfig; 38 import com.sun.appserv.management.config.DeployedItemRefConfig; 39 import com.sun.appserv.management.config.ServerRefConfig; 40 import com.sun.appserv.management.config.ClusterRefConfig; 41 import com.sun.appserv.management.config.RefConfigReferent; 42 43 44 import com.sun.enterprise.management.AMXTestBase; 45 import com.sun.enterprise.management.Capabilities; 46 47 48 59 public final class RefHelperTest extends AMXTestBase 60 { 61 public 62 RefHelperTest( ) 63 { 64 } 65 66 public void 67 testFindResourceRefs() 68 { 69 final Set <ResourceRefConfig> refs1 = 70 RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), XTypes.RESOURCE_REF_CONFIG); 71 72 final Set <ResourceRefConfig> refs2 = 73 RefHelper.findAllResourceRefConfigs( getQueryMgr() ); 74 75 assertEquals( refs1, refs2 ); 76 } 77 78 public void 79 testFindDeployedItemRefs() 80 { 81 final Set <RefConfig> refs1 = 82 RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), XTypes.DEPLOYED_ITEM_REF_CONFIG); 83 84 final Set <DeployedItemRefConfig> refs2 = 85 RefHelper.findAllDeployedItemRefConfigs( getQueryMgr() ); 86 87 assertEquals( refs1, refs2 ); 88 } 89 90 91 public void 92 testFindServerRefs() 93 { 94 final Set <RefConfig> refs1 = 95 RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), XTypes.SERVER_REF_CONFIG); 96 97 final Set <ServerRefConfig> refs2 = 98 RefHelper.findAllServerRefConfigs( getQueryMgr() ); 99 100 assertEquals( refs1, refs2 ); 101 } 102 103 public void 104 testFindClusterRefs() 105 { 106 final Set <RefConfig> refs1 = 107 RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), XTypes.CLUSTER_REF_CONFIG); 108 109 final Set <ClusterRefConfig> refs2 = 110 RefHelper.findAllClusterRefConfigs( getQueryMgr() ); 111 112 assertEquals( refs1, refs2 ); 113 } 114 115 public void 116 testFindAllRefConfigs() 117 { 118 final Set <RefConfig> all = 119 RefHelper.findAllRefConfigs( getQueryMgr() ); 120 121 final Set <String > referentJ2EETypes = RefHelper.getReferentJ2EETypes(); 122 assert( referentJ2EETypes.size() >= 4 ); 123 124 final Set <RefConfig> allSeparately = new HashSet <RefConfig>(); 125 126 for( final String j2eeType : referentJ2EETypes ) 127 { 128 final Set <RefConfig> refs = 129 RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), j2eeType ) ; 130 131 for( final RefConfig ref : refs) 132 { 133 allSeparately.add( ref ); 134 } 135 } 136 137 assertEquals( all, allSeparately ); 138 } 139 140 141 public void 142 testFindAllRefConfigsByName() 143 { 144 final Set <RefConfig> refs = 145 RefHelper.findAllRefConfigs( getQueryMgr() ); 146 147 final Set <String > names = Util.getNames( refs ); 148 final Map <String ,Set <RefConfig>> byName = 149 new HashMap <String , Set <RefConfig>>(); 150 151 for( final String name : names ) 153 { 154 byName.put( name, new HashSet <RefConfig>() ); 155 } 156 157 for( final RefConfig ref : refs ) 159 { 160 final Set <RefConfig> s = byName.get( ref.getName() ); 161 162 s.add( ref ); 163 } 164 165 for( final String name : byName.keySet() ) 167 { 168 final Set <RefConfig> s = byName.get( name ); 169 170 final String lastJ2EEType = s.iterator().next().getJ2EEType(); 171 for( final RefConfig ref : s ) 172 { 173 assertEquals( ref.getJ2EEType(), lastJ2EEType ); 174 } 175 } 176 177 for( final String name : byName.keySet() ) 179 { 180 final Set <RefConfig> s = byName.get( name ); 181 182 final String j2eeType = s.iterator().next().getJ2EEType(); 183 final Set <RefConfig> s2 = 184 RefHelper.findAllRefConfigsWithName( getQueryMgr(), j2eeType, name ); 185 186 assertEquals( s, s2 ); 187 } 188 } 189 190 } 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | Popular Tags |