1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Map ; 26 27 import javax.management.ObjectName ; 28 29 import com.sun.appserv.management.DomainRoot; 30 import com.sun.appserv.management.base.AMX; 31 import com.sun.appserv.management.base.Util; 32 33 import com.sun.appserv.management.base.SystemInfo; 34 import com.sun.appserv.management.config.DomainConfig; 35 import com.sun.appserv.management.config.ConfigConfig; 36 37 import com.sun.appserv.management.util.misc.MapUtil; 38 import com.sun.appserv.management.util.misc.StringUtil; 39 40 41 import com.sun.enterprise.management.AMXTestBase; 42 import com.sun.enterprise.management.Capabilities; 43 import com.sun.enterprise.management.MultipleServerSupportRequired; 44 45 46 48 public final class ConfigConfigTest extends AMXTestBase 49 implements MultipleServerSupportRequired 50 { 51 public 52 ConfigConfigTest() 53 { 54 if ( checkNotOffline( "ensureDefaultInstance" ) ) 55 { 56 ensureDefaultInstance( getDomainRoot() ); 57 } 58 59 } 60 61 public static ConfigConfig 62 ensureDefaultInstance( final DomainRoot domainRoot ) 63 { 64 ConfigConfig config = null; 65 66 final DomainConfig domainConfig = domainRoot.getDomainConfig(); 67 final Map <String ,ConfigConfig> existing = domainConfig.getConfigConfigMap(); 68 69 if ( supportsMultipleServers( domainRoot ) ) 70 { 71 config = existing.get( getDefaultInstanceName( domainRoot ) ); 72 if ( config == null ) 73 { 74 final ConfigSetup setup = new ConfigSetup( domainRoot ); 75 config = setup.createConfig( getDefaultInstanceName( domainRoot ) ); 76 } 77 } 78 else 79 { 80 config = existing.get( PE_CONFIG_NAME ); 81 assert( config != null ) : "No config named " + StringUtil.quote( PE_CONFIG_NAME ); 82 } 83 return config; 84 } 85 86 public static String 87 getDefaultInstanceName( final DomainRoot domainRoot ) 88 { 89 String name = null; 90 91 if ( domainRoot.getSystemInfo().supportsFeature( SystemInfo.MULTIPLE_SERVERS_FEATURE ) ) 92 { 93 name = getDefaultInstanceName( "ConfigConfigTest" ); 94 } 95 else 96 { 97 name = PE_CONFIG_NAME; 98 } 99 return name; 100 } 101 102 103 private ConfigConfig 104 create( final String name ) 105 throws Throwable 106 { 107 final ConfigSetup setup = new ConfigSetup( getDomainRoot() ); 108 109 setup.removeConfig( name ); 110 111 final ConfigConfig config = setup.createConfig( name ); 112 assert( name.equals( config.getName() ) ); 113 114 final Map <String ,Object > attrs = Util.getExtra( config ).getAllAttributes(); 116 119 return config; 120 } 121 122 public void 123 testCreateRemove() 124 throws Throwable 125 { 126 if ( ! checkNotOffline( "testCreateRemove" ) ) 127 { 128 return; 129 } 130 131 final String NAME = "ConfigConfigTest.testCreateRemove"; 132 133 final Map <String ,ConfigConfig> before = getDomainConfig().getConfigConfigMap(); 134 135 final int NUM = 2; 136 final ConfigConfig[] configs = new ConfigConfig[ NUM ]; 137 138 for( int i = 0; i < NUM; ++i ) 139 { 140 configs[ i ] = create( NAME + i ); 141 } 142 143 final ConfigSetup setup = new ConfigSetup( getDomainRoot() ); 144 for( final ConfigConfig config : configs ) 145 { 146 setup.removeConfig( config.getName() ); 147 148 try 150 { 151 Util.getExtra( config ).getAllAttributes(); 152 fail( "Config " + config.getName() + " should no longer exist" ); 153 } 154 catch( Exception e ) 155 { 156 } 158 } 159 160 final Map <String ,ConfigConfig> after = getDomainConfig().getConfigConfigMap(); 161 assert( before.keySet().equals( after.keySet() ) ); 162 } 163 } 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | Popular Tags |