1 23 24 29 package com.sun.enterprise.management.config; 30 31 import java.util.Set ; 32 import java.util.Map ; 33 34 import javax.management.AttributeList ; 35 import javax.management.Notification ; 36 import javax.management.NotificationListener ; 37 import javax.management.MBeanServerConnection ; 38 import javax.management.NotCompliantMBeanException ; 39 40 import com.sun.appserv.management.base.XTypes; 41 import com.sun.appserv.management.base.AMX; 42 import com.sun.appserv.management.base.QueryMgr; 43 44 import com.sun.appserv.management.client.AppserverConnectionSource; 45 46 import com.sun.appserv.management.config.ClusterConfig; 47 import com.sun.appserv.management.config.ConfigConfig; 48 import com.sun.appserv.management.config.StandaloneServerConfig; 49 import com.sun.appserv.management.config.ResourceRefConfig; 50 import com.sun.appserv.management.config.MailResourceConfig; 51 import com.sun.appserv.management.config.DomainConfig; 52 53 54 55 import com.sun.enterprise.management.AMXTestBase; 56 import com.sun.enterprise.management.Capabilities; 57 58 59 61 public final class ReferencesTest extends AMXTestBase 62 { 63 public ReferencesTest() 64 { 65 } 66 67 68 private static final String MAIL_RESOURCE_NAME = "test/mail1"; 69 70 MailResourceConfig 71 createMailResourceConfig() 72 { 73 final MailResourceConfig mr = 74 getDomainConfig().createMailResourceConfig( 75 MAIL_RESOURCE_NAME, 76 "localhost", 77 "mailuser@domain.com", 78 "mailfrom@domain.com", 79 null ); 80 return mr; 81 } 82 83 MailResourceConfig 84 ensureMailResourceConfig() 85 { 86 final Map <String ,MailResourceConfig> mails = 87 getDomainConfig().getMailResourceConfigMap(); 88 89 MailResourceConfig mr = mails.get( MAIL_RESOURCE_NAME ); 90 if ( mr == null ) 91 { 92 mr = createMailResourceConfig(); 93 } 94 return mr; 95 } 96 97 void 98 removeMailResourceConfig() 99 { 100 final Map <String ,MailResourceConfig> mails = 101 getDomainConfig().getMailResourceConfigMap(); 102 103 MailResourceConfig mr = mails.get( MAIL_RESOURCE_NAME ); 104 if ( mr != null ) 105 { 106 getDomainConfig().removeMailResourceConfig( mr.getName() ); 107 } 108 } 109 110 public void 111 testCreateAndRemoveResourceRefStandaloneServer() 112 throws Exception 113 { 114 if ( ! checkNotOffline( "testCreateRemove" ) ) 115 { 116 return; 117 } 118 119 final Map <String ,AppserverConnectionSource> nodeAgents = 120 getNodeAgents(); 121 122 if ( nodeAgents.keySet().size() == 0 ) 123 { 124 warning( 125 "testCreateAndRemoveResourceRefStandaloneServer: no Node Agents--SKIPPING TEST" ); 126 return; 127 } 128 final String nodeAgentName = nodeAgents.keySet().iterator().next(); 129 130 final ConfigSetup setup = new ConfigSetup( getDomainRoot() ); 131 132 ensureMailResourceConfig(); 133 134 final String serverName = "testCreateAndRemoveResourceRefStandaloneServer"; 135 final String configName = serverName + "-config"; 136 137 final ConfigConfig config = setup.createConfig( configName ); 138 try 139 { 140 final int basePort = 34770; 141 142 final StandaloneServerConfig server = 143 setup.createServer( serverName, basePort, nodeAgentName, configName ); 144 try 145 { 146 final ResourceRefConfig ref = 147 server.createResourceRefConfig( MAIL_RESOURCE_NAME ); 148 assert( ref != null ); 149 150 server.removeResourceRefConfig( ref.getName() ); 151 } 152 catch( Exception e ) 153 { 154 setup.removeServer( serverName ); 155 throw e; 156 } 157 finally 158 { 159 removeMailResourceConfig(); 160 } 161 } 162 catch( Exception e ) 163 { 164 setup.removeConfig( configName ); 165 throw e; 166 } 167 } 168 169 public void 170 testCreateRefToMissingTarget() 171 { 172 if ( ! checkNotOffline( "testCreateRemove" ) ) 173 { 174 return; 175 } 176 177 final String MISSING_NAME = "NonExistent"; 178 179 final DomainConfig domainConfig = getDomainRoot().getDomainConfig(); 180 final StandaloneServerConfig serverConfig = 181 domainConfig.getStandaloneServerConfigMap().get( "server" ); 182 183 try 184 { 185 serverConfig.createResourceRefConfig( MISSING_NAME ); 186 assert false; 187 188 serverConfig.createDeployedItemRefConfig( MISSING_NAME ); 189 assert false; 190 } 191 catch( Exception e ) 192 { 193 } 195 196 } 197 198 211 212 364 365 366 } 367 368 369 | Popular Tags |