1 17 package org.apache.geronimo.j2ee.deployment; 18 19 import java.io.IOException ; 20 import java.util.Collections ; 21 import java.util.Map ; 22 import java.util.jar.JarFile ; 23 24 import org.apache.geronimo.common.DeploymentException; 25 import org.apache.geronimo.deployment.DeploymentContext; 26 import org.apache.geronimo.deployment.ModuleIDBuilder; 27 import org.apache.geronimo.deployment.NamespaceDrivenBuilder; 28 import org.apache.geronimo.deployment.util.DeploymentUtil; 29 import org.apache.geronimo.gbean.AbstractName; 30 import org.apache.geronimo.gbean.AbstractNameQuery; 31 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 32 import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl; 33 import org.apache.geronimo.kernel.Jsr77Naming; 34 import org.apache.geronimo.kernel.Naming; 35 import org.apache.geronimo.kernel.config.ConfigurationData; 36 import org.apache.geronimo.kernel.repository.Artifact; 37 import org.apache.geronimo.kernel.repository.ArtifactManager; 38 import org.apache.geronimo.kernel.repository.ArtifactResolver; 39 import org.apache.geronimo.kernel.repository.DefaultArtifactManager; 40 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver; 41 import org.apache.geronimo.kernel.repository.Environment; 42 import org.apache.geronimo.kernel.repository.ImportType; 43 import org.apache.geronimo.testsupport.TestSupport; 44 45 50 public abstract class EARConfigBuilderTestSupport 51 extends TestSupport 52 { 53 protected static String WEB_NAMESPACE = "foo"; 54 55 protected static JarFile earFile; 56 57 protected static MockConfigStore configStore = new MockConfigStore(); 58 59 protected static ArtifactManager artifactManager = new DefaultArtifactManager(); 60 61 protected static ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager, Collections.EMPTY_SET, null); 62 63 protected static MockEJBConfigBuilder ejbConfigBuilder = new MockEJBConfigBuilder(); 64 65 protected static MockWARConfigBuilder webConfigBuilder = new MockWARConfigBuilder(); 66 67 protected static MockConnectorConfigBuilder connectorConfigBuilder = new MockConnectorConfigBuilder(); 68 69 protected static ActivationSpecInfoLocator activationSpecInfoLocator = connectorConfigBuilder; 70 71 protected static ModuleBuilder appClientConfigBuilder = null; 72 73 protected final static ModuleIDBuilder idBuilder = new ModuleIDBuilder(); 74 75 protected static final NamespaceDrivenBuilder securityBuilder = null; 76 77 protected static final NamespaceDrivenBuilder serviceBuilder = null; 78 79 protected static final Naming naming = new Jsr77Naming(); 80 81 protected static final AbstractName rootConfig = naming.createRootName(new Artifact("test", "stuff", "", "car"), "test", "test") ; 82 83 protected static final AbstractName transactionManagerObjectName = naming.createChildName(rootConfig, "TransactionManager", "TransactionManager"); 84 85 protected static final AbstractName connectionTrackerObjectName = naming.createChildName(rootConfig, "ConnectionTracker", "ConnectionTracker"); 86 87 protected static final AbstractName transactionalTimerObjectName = naming.createChildName(rootConfig, "TransactionalThreaPooledTimer", "ThreadPooledTimer"); 88 89 protected static final AbstractName nonTransactionalTimerObjectName = naming.createChildName(rootConfig, "NonTransactionalThreaPooledTimer", "ThreadPooledTimer"); 90 91 protected static final AbstractName serverName = naming.createChildName(rootConfig, "J2EEServer", "Server"); 92 93 protected static final AbstractName earName = naming.createRootName(new Artifact("org.apache.geronimo.test.test-ear", "ear", "", "ear"), "test", NameFactory.J2EE_APPLICATION); 94 95 protected static final AbstractName ejbModuleName = naming.createChildName(earName, "ejb-jar", NameFactory.EJB_MODULE); 96 97 protected static final AbstractName webModuleName = naming.createChildName(earName, "war", NameFactory.WEB_MODULE); 98 99 protected static final AbstractName raModuleName = naming.createChildName(earName, "rar", NameFactory.RESOURCE_ADAPTER_MODULE); 100 101 protected Environment defaultParentId; 102 103 protected static String contextRoot = "test"; 104 105 protected static final Map portMap = null; 106 107 protected final AbstractNameQuery transactionManagerAbstractNameQuery = new AbstractNameQuery(transactionManagerObjectName, null); 108 109 protected final AbstractNameQuery connectionTrackerAbstractNameQuery = new AbstractNameQuery(connectionTrackerObjectName, null); 110 111 protected final AbstractNameQuery transactionalTimerAbstractNameQuery = new AbstractNameQuery(transactionalTimerObjectName, null); 112 113 protected final AbstractNameQuery nonTransactionalTimerAbstractNameQuery = new AbstractNameQuery(nonTransactionalTimerObjectName, null); 114 115 protected final AbstractNameQuery corbaGBeanAbstractNameQuery = new AbstractNameQuery(serverName, null); 116 117 protected void setUp() throws Exception { 118 super.setUp(); 119 120 defaultParentId = new Environment(); 121 defaultParentId.addDependency(new Artifact("org.apache.geronimo.tests", "test", "1", "car"), ImportType.ALL); 122 } 123 124 public void testBuildConfiguration() throws Exception { 125 ConfigurationData configurationData = null; 126 DeploymentContext context = null; 127 try { 128 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId, 129 transactionManagerAbstractNameQuery, 130 connectionTrackerAbstractNameQuery, 131 transactionalTimerAbstractNameQuery, 132 nonTransactionalTimerAbstractNameQuery, 133 corbaGBeanAbstractNameQuery, 134 null, 135 null, 136 ejbConfigBuilder, 137 webConfigBuilder, 138 connectorConfigBuilder, 139 activationSpecInfoLocator, 140 appClientConfigBuilder, 141 securityBuilder, 142 serviceBuilder, 143 naming); 144 145 Object plan = configBuilder.getDeploymentPlan(null, earFile, idBuilder); 146 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore); 147 configurationData = getConfigurationData(context); 148 } finally { 149 if (context != null) { 150 context.close(); 151 } 152 if (configurationData != null) { 153 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir()); 154 } 155 } 156 } 157 158 public void testBadEJBJARConfiguration() throws Exception { 159 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId, 160 transactionManagerAbstractNameQuery, 161 connectionTrackerAbstractNameQuery, 162 transactionalTimerAbstractNameQuery, 163 nonTransactionalTimerAbstractNameQuery, 164 corbaGBeanAbstractNameQuery, 165 null, 166 null, 167 ejbConfigBuilder, 168 webConfigBuilder, 169 connectorConfigBuilder, 170 activationSpecInfoLocator, 171 appClientConfigBuilder, 172 securityBuilder, 173 serviceBuilder, 174 naming); 175 176 ConfigurationData configurationData = null; 177 DeploymentContext context = null; 178 try { 179 Object plan = configBuilder.getDeploymentPlan(resolveFile("src/test/resources/plans/test-bad-ejb-jar.xml"), earFile, idBuilder); 180 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore); 181 configurationData = getConfigurationData(context); 182 fail("Should have thrown a DeploymentException"); 183 } catch (DeploymentException e) { 184 if (e.getCause() instanceof IOException ) { 185 fail("Should not be complaining about bad vendor DD for invalid module entry"); 186 } 187 } finally { 188 if (context != null) { 189 context.close(); 190 } 191 if (configurationData != null) { 192 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir()); 193 } 194 } 195 } 196 197 public void testBadWARConfiguration() throws Exception { 198 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId, 199 transactionManagerAbstractNameQuery, 200 connectionTrackerAbstractNameQuery, 201 transactionalTimerAbstractNameQuery, 202 nonTransactionalTimerAbstractNameQuery, 203 corbaGBeanAbstractNameQuery, 204 null, 205 null, 206 ejbConfigBuilder, 207 webConfigBuilder, 208 connectorConfigBuilder, 209 activationSpecInfoLocator, 210 appClientConfigBuilder, 211 securityBuilder, 212 serviceBuilder, 213 naming); 214 215 ConfigurationData configurationData = null; 216 DeploymentContext context = null; 217 try { 218 Object plan = configBuilder.getDeploymentPlan(resolveFile("src/test/resources/plans/test-bad-war.xml"), earFile, idBuilder); 219 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore); 220 configurationData = getConfigurationData(context); 221 fail("Should have thrown a DeploymentException"); 222 } catch (DeploymentException e) { 223 if (e.getCause() instanceof IOException ) { 224 fail("Should not be complaining about bad vendor DD for invalid module entry"); 225 } 226 } finally { 227 if (context != null) { 228 context.close(); 229 } 230 if (configurationData != null) { 231 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir()); 232 } 233 } 234 } 235 236 public void testBadRARConfiguration() throws Exception { 237 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId, 238 transactionManagerAbstractNameQuery, 239 connectionTrackerAbstractNameQuery, 240 transactionalTimerAbstractNameQuery, 241 nonTransactionalTimerAbstractNameQuery, 242 corbaGBeanAbstractNameQuery, 243 null, 244 null, 245 ejbConfigBuilder, 246 webConfigBuilder, 247 connectorConfigBuilder, 248 activationSpecInfoLocator, 249 appClientConfigBuilder, 250 securityBuilder, 251 serviceBuilder, 252 naming); 253 254 ConfigurationData configurationData = null; 255 DeploymentContext context = null; 256 try { 257 Object plan = configBuilder.getDeploymentPlan(resolveFile("src/test/resources/plans/test-bad-rar.xml"), earFile, idBuilder); 258 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore); 259 configurationData = getConfigurationData(context); 260 fail("Should have thrown a DeploymentException"); 261 } catch (DeploymentException e) { 262 if (e.getCause() instanceof IOException ) { 263 fail("Should not be complaining about bad vendor DD for invalid module entry"); 264 } 265 } finally { 266 if (context != null) { 267 context.close(); 268 } 269 if (configurationData != null) { 270 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir()); 271 } 272 } 273 } 274 275 public void testBadCARConfiguration() throws Exception { 276 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId, 277 transactionManagerAbstractNameQuery, 278 connectionTrackerAbstractNameQuery, 279 transactionalTimerAbstractNameQuery, 280 nonTransactionalTimerAbstractNameQuery, 281 corbaGBeanAbstractNameQuery, 282 null, 283 null, 284 ejbConfigBuilder, 285 webConfigBuilder, 286 connectorConfigBuilder, 287 activationSpecInfoLocator, 288 appClientConfigBuilder, 289 securityBuilder, 290 serviceBuilder, 291 naming); 292 293 ConfigurationData configurationData = null; 294 DeploymentContext context = null; 295 try { 296 Object plan = configBuilder.getDeploymentPlan(resolveFile("src/test/resources/plans/test-bad-car.xml"), earFile, idBuilder); 297 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore); 298 configurationData = getConfigurationData(context); 299 fail("Should have thrown a DeploymentException"); 300 } catch (DeploymentException e) { 301 if (e.getCause() instanceof IOException ) { 302 fail("Should not be complaining about bad vendor DD for invalid module entry"); 303 } 304 } finally { 305 if (context != null) { 306 context.close(); 307 } 308 if (configurationData != null) { 309 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir()); 310 } 311 } 312 } 313 314 public void testNoEJBDeployer() throws Exception { 315 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId, 316 transactionManagerAbstractNameQuery, 317 connectionTrackerAbstractNameQuery, 318 transactionalTimerAbstractNameQuery, 319 nonTransactionalTimerAbstractNameQuery, 320 corbaGBeanAbstractNameQuery, 321 null, 322 null, 323 null, 324 webConfigBuilder, 325 connectorConfigBuilder, 326 activationSpecInfoLocator, 327 appClientConfigBuilder, 328 securityBuilder, 329 serviceBuilder, 330 naming); 331 332 333 ConfigurationData configurationData = null; 334 DeploymentContext context = null; 335 try { 336 Object plan = configBuilder.getDeploymentPlan(null, earFile, idBuilder); 337 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore); 338 configurationData = getConfigurationData(context); 339 fail("Should have thrown a DeploymentException"); 340 } catch (DeploymentException e) { 341 } finally { 343 if (context != null) { 344 context.close(); 345 } 346 if (configurationData != null) { 347 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir()); 348 } 349 } 350 } 351 352 public void testNoWARDeployer() throws Exception { 353 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId, 354 transactionManagerAbstractNameQuery, 355 connectionTrackerAbstractNameQuery, 356 transactionalTimerAbstractNameQuery, 357 nonTransactionalTimerAbstractNameQuery, 358 corbaGBeanAbstractNameQuery, 359 null, 360 null, 361 ejbConfigBuilder, 362 null, 363 connectorConfigBuilder, 364 activationSpecInfoLocator, 365 appClientConfigBuilder, 366 securityBuilder, 367 serviceBuilder, 368 naming); 369 370 ConfigurationData configurationData = null; 371 DeploymentContext context = null; 372 try { 373 Object plan = configBuilder.getDeploymentPlan(null, earFile, idBuilder); 374 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore); 375 configurationData = getConfigurationData(context); 376 fail("Should have thrown a DeploymentException"); 377 } catch (DeploymentException e) { 378 } finally { 380 if (context != null) { 381 context.close(); 382 } 383 if (configurationData != null) { 384 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir()); 385 } 386 } 387 } 388 389 public void testNoConnectorDeployer() throws Exception { 390 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId, 391 transactionManagerAbstractNameQuery, 392 connectionTrackerAbstractNameQuery, 393 transactionalTimerAbstractNameQuery, 394 nonTransactionalTimerAbstractNameQuery, 395 corbaGBeanAbstractNameQuery, 396 null, 397 null, 398 ejbConfigBuilder, 399 webConfigBuilder, 400 null, 401 activationSpecInfoLocator, 402 appClientConfigBuilder, 403 securityBuilder, 404 serviceBuilder, 405 naming); 406 407 ConfigurationData configurationData = null; 408 DeploymentContext context = null; 409 try { 410 Object plan = configBuilder.getDeploymentPlan(null, earFile, idBuilder); 411 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore); 412 configurationData = getConfigurationData(context); 413 fail("Should have thrown a DeploymentException"); 414 } catch (DeploymentException e) { 415 } finally { 417 if (context != null) { 418 context.close(); 419 } 420 if (configurationData != null) { 421 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir()); 422 } 423 } 424 } 425 426 protected ConfigurationData getConfigurationData(DeploymentContext context) throws Exception { 427 context.addGBean("geronimo", J2EEServerImpl.GBEAN_INFO); 429 430 return context.getConfigurationData(); 431 } 432 433 protected static void close(Module module) { 434 if (module != null) { 435 module.close(); 436 } 437 } 438 } 439 | Popular Tags |