1 17 18 package org.apache.geronimo.connector.deployment; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import java.net.URLClassLoader ; 25 import java.sql.Connection ; 26 import java.sql.Statement ; 27 import java.util.Collections ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.LinkedHashSet ; 31 import java.util.List ; 32 import java.util.Map ; 33 import java.util.Set ; 34 import java.util.jar.JarFile ; 35 36 import javax.naming.Reference ; 37 import javax.sql.DataSource ; 38 39 import org.apache.geronimo.common.DeploymentException; 40 import org.apache.geronimo.deployment.DeploymentContext; 41 import org.apache.geronimo.deployment.ModuleIDBuilder; 42 import org.apache.geronimo.deployment.service.GBeanBuilder; 43 import org.apache.geronimo.deployment.util.DeploymentUtil; 44 import org.apache.geronimo.gbean.AbstractName; 45 import org.apache.geronimo.gbean.AbstractNameQuery; 46 import org.apache.geronimo.gbean.GBeanData; 47 import org.apache.geronimo.gbean.GBeanInfo; 48 import org.apache.geronimo.gbean.GBeanInfoBuilder; 49 import org.apache.geronimo.j2ee.deployment.ActivationSpecInfoLocator; 50 import org.apache.geronimo.j2ee.deployment.EARConfigBuilder; 51 import org.apache.geronimo.j2ee.deployment.EARContext; 52 import org.apache.geronimo.j2ee.deployment.Module; 53 import org.apache.geronimo.j2ee.deployment.ModuleBuilder; 54 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 55 import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl; 56 import org.apache.geronimo.kernel.Jsr77Naming; 57 import org.apache.geronimo.kernel.Kernel; 58 import org.apache.geronimo.kernel.KernelFactory; 59 import org.apache.geronimo.kernel.Naming; 60 import org.apache.geronimo.kernel.config.Configuration; 61 import org.apache.geronimo.kernel.config.ConfigurationData; 62 import org.apache.geronimo.kernel.config.ConfigurationStore; 63 import org.apache.geronimo.kernel.config.ConfigurationUtil; 64 import org.apache.geronimo.kernel.config.EditableConfigurationManager; 65 import org.apache.geronimo.kernel.config.EditableKernelConfigurationManager; 66 import org.apache.geronimo.kernel.config.InvalidConfigException; 67 import org.apache.geronimo.kernel.config.NoSuchConfigException; 68 import org.apache.geronimo.kernel.config.NullConfigurationStore; 69 import org.apache.geronimo.kernel.management.State; 70 import org.apache.geronimo.kernel.repository.Artifact; 71 import org.apache.geronimo.kernel.repository.ArtifactManager; 72 import org.apache.geronimo.kernel.repository.ArtifactResolver; 73 import org.apache.geronimo.kernel.repository.DefaultArtifactManager; 74 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver; 75 import org.apache.geronimo.kernel.repository.Environment; 76 import org.apache.geronimo.kernel.repository.ImportType; 77 import org.apache.geronimo.kernel.repository.Repository; 78 import org.apache.geronimo.system.serverinfo.BasicServerInfo; 79 import org.apache.geronimo.testsupport.TestSupport; 80 import org.apache.geronimo.transaction.manager.GeronimoTransactionManagerGBean; 81 import org.tranql.sql.jdbc.JDBCUtil; 82 83 86 public class ConnectorModuleBuilderTest extends TestSupport { 87 88 private boolean defaultXATransactionCaching = true; 89 private boolean defaultXAThreadCaching = false; 90 private int defaultMaxSize = 10; 91 private int defaultMinSize = 0; 92 private int defaultBlockingTimeoutMilliseconds = 5000; 93 private int defaultidleTimeoutMinutes = 15; 94 private Environment defaultEnvironment; 95 private ConfigurationStore configurationStore = new MockConfigStore(); 96 private Repository repository = new Repository() { 97 public boolean contains(Artifact artifact) { 98 return false; 99 } 100 101 public File getLocation(Artifact artifact) { 102 return null; 103 } 104 105 public LinkedHashSet getDependencies(Artifact artifact) { 106 return new LinkedHashSet (); 107 } 108 }; 109 110 private ActivationSpecInfoLocator activationSpecInfoLocator = new ActivationSpecInfoLocator() { 111 112 public Reference createResourceRef(AbstractNameQuery containerId, Class iface, Configuration configuration) { 113 return null; 114 } 115 116 public Reference createAdminObjectRef(AbstractNameQuery containerId, Class iface, Configuration configuration) { 117 return null; 118 } 119 120 public GBeanData locateActivationSpecInfo(AbstractNameQuery nameQuery, String messageListenerInterface, Configuration configuration) { 121 return null; 122 } 123 }; 124 125 private Kernel kernel; 126 private EditableConfigurationManager configurationManager; 127 private static final Naming naming = new Jsr77Naming(); 128 private static final Artifact bootId = new Artifact("test", "test", "42", "car"); 129 130 private static final AbstractNameQuery connectionTrackerName = new AbstractNameQuery(null, Collections.singletonMap("name", "ConnectionTracker")); 131 private AbstractName serverName; 132 private static final AbstractNameQuery transactionManagerName = new AbstractNameQuery(null, Collections.singletonMap("name", "TransactionManager")); 133 134 135 public void testBuildEar() throws Exception { 136 JarFile rarFile = null; 137 try { 138 rarFile = DeploymentUtil.createJarFile(new File (BASEDIR, "target/test-ear-noger.ear")); 139 GBeanBuilder serviceBuilder = new GBeanBuilder(null, null); 140 EARConfigBuilder configBuilder = new EARConfigBuilder(defaultEnvironment, 142 transactionManagerName, 143 connectionTrackerName, 144 null, 145 null, 146 null, 147 new AbstractNameQuery(serverName, J2EEServerImpl.GBEAN_INFO.getInterfaces()), 148 null, 149 null, 150 null, 151 new ConnectorModuleBuilder(defaultEnvironment, defaultMaxSize, defaultMinSize, defaultBlockingTimeoutMilliseconds, defaultidleTimeoutMinutes, defaultXATransactionCaching, defaultXAThreadCaching, Collections.singleton(serviceBuilder)), 152 activationSpecInfoLocator, 153 null, 154 null, 155 serviceBuilder, 156 kernel.getNaming()); 157 ConfigurationData configData = null; 158 DeploymentContext context = null; 159 ArtifactManager artifactManager = new DefaultArtifactManager(); 160 ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager, Collections.EMPTY_SET, null); 161 162 try { 163 File planFile = new File (BASEDIR, "src/test/data/data/external-application-plan.xml"); 164 ModuleIDBuilder idBuilder = new ModuleIDBuilder(); 165 Object plan = configBuilder.getDeploymentPlan(planFile, rarFile, idBuilder); 166 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, rarFile, idBuilder), plan, rarFile, Collections.singleton(configurationStore), artifactResolver, configurationStore); 167 168 context.addGBean("geronimo", J2EEServerImpl.GBEAN_INFO); 170 171 configData = context.getConfigurationData(); 172 } finally { 173 if (context != null) { 174 context.close(); 175 } 176 if (configData != null) { 177 DeploymentUtil.recursiveDelete(configData.getConfigurationDir()); 178 } 179 } 180 } finally { 181 DeploymentUtil.close(rarFile); 182 } 183 } 184 185 public void testBuildUnpackedModule() throws Exception { 186 InstallAction action = new InstallAction() { 187 public File getRARFile() { 188 return new File (BASEDIR, "target/test-rar-10"); 189 } 190 }; 191 executeTestBuildModule(action, false); 192 } 193 194 public void testBuildUnpackedAltSpecDDModule() throws Exception { 195 InstallAction action = new InstallAction() { 196 public File getVendorDD() { 197 return new File (BASEDIR, "target/test-rar-10/META-INF/geronimo-ra.xml"); 198 } 199 200 public URL getSpecDD() throws MalformedURLException { 201 return new File (BASEDIR, "target/test-rar-10/dummy.xml").toURL(); 202 } 203 204 public File getRARFile() { 205 return new File (BASEDIR, "target/test-rar-10"); 206 } 207 }; 208 try { 209 executeTestBuildModule(action, false); 210 fail("Spec alt-dd does not exist."); 211 } catch (DeploymentException e) { 212 } 213 } 214 215 public void testBuildUnpackedAltVendorDDModule() throws Exception { 216 InstallAction action = new InstallAction() { 217 public File getVendorDD() { 218 return new File (BASEDIR, "target/test-rar-10/dummy.xml"); 220 } 221 222 public URL getSpecDD() throws MalformedURLException { 223 return new File (BASEDIR, "target/test-rar-10/META-INF/ra.xml").toURL(); 224 } 225 226 public File getRARFile() { 227 return new File (BASEDIR, "target/test-rar-10"); 228 } 229 }; 230 try { 231 executeTestBuildModule(action, false); 232 fail("Vendor alt-dd does not exist."); 233 } catch (DeploymentException e) { 234 } 235 } 236 237 public void testBuildUnpackedAltSpecVendorDDModule() throws Exception { 238 InstallAction action = new InstallAction() { 239 public File getVendorDD() { 240 return new File (BASEDIR, "target/test-rar-10/META-INF/geronimo-ra.xml"); 242 } 243 244 public URL getSpecDD() throws MalformedURLException { 245 return new File (BASEDIR, "target/test-rar-10/META-INF/ra.xml").toURL(); 246 } 247 248 public File getRARFile() { 249 return new File (BASEDIR, "target/test-rar-10"); 250 } 251 }; 252 executeTestBuildModule(action, false); 253 } 254 255 public void testBuildPackedModule() throws Exception { 256 InstallAction action = new InstallAction() { 257 public File getRARFile() { 258 return new File (BASEDIR, "target/test-rar-10.rar"); 259 } 260 }; 261 executeTestBuildModule(action, false); 262 } 263 264 public void testBuildUnpackedModule15() throws Exception { 266 InstallAction action = new InstallAction() { 267 private File rarFile = new File (BASEDIR, "target/test-rar-15"); 268 269 public File getRARFile() { 270 return rarFile; 271 } 272 273 }; 274 executeTestBuildModule(action, true); 275 } 276 277 278 public void testBuildPackedModule15() throws Exception { 279 InstallAction action = new InstallAction() { 280 private File rarFile = new File (BASEDIR, "target/test-rar-15.rar"); 281 282 public File getRARFile() { 283 return rarFile; 284 } 285 286 }; 287 executeTestBuildModule(action, true); 288 } 289 290 public void testBuildPackedModule15LocalTx() throws Exception { 291 InstallAction action = new InstallAction() { 292 private File rarFile = new File (BASEDIR, "target/test-rar-15-localtx.rar"); 293 294 public File getRARFile() { 295 return rarFile; 296 } 297 298 }; 299 try { 300 executeTestBuildModule(action, true); 301 fail("transaction setting mismatch not detected"); 302 } catch (DeploymentException e) { 303 304 } 305 } 306 307 public void testBuildPackedModule15NoTx() throws Exception { 308 InstallAction action = new InstallAction() { 309 private File rarFile = new File (BASEDIR, "target/test-rar-15-notx.rar"); 310 311 public File getRARFile() { 312 return rarFile; 313 } 314 315 }; 316 try { 317 executeTestBuildModule(action, true); 318 fail("transaction setting mismatch not detected"); 319 } catch (DeploymentException e) { 320 321 } 322 } 323 324 325 private void executeTestBuildModule(InstallAction action, boolean is15) throws Exception { 326 String resourceAdapterName = "testRA"; 327 328 try { 329 ConnectorModuleBuilder moduleBuilder = new ConnectorModuleBuilder(defaultEnvironment, defaultMaxSize, defaultMinSize, defaultBlockingTimeoutMilliseconds, defaultidleTimeoutMinutes, defaultXATransactionCaching, defaultXAThreadCaching, Collections.singleton(new GBeanBuilder(null, null))); 330 File rarFile = action.getRARFile(); 331 332 ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); 333 ClassLoader cl = new URLClassLoader (new URL []{rarFile.toURL()}, oldCl); 334 335 Thread.currentThread().setContextClassLoader(cl); 336 337 JarFile rarJarFile = DeploymentUtil.createJarFile(rarFile); 338 AbstractName earName = null; 339 String moduleName = "geronimo/test-ear/1.0/car"; 340 Module module = moduleBuilder.createModule(action.getVendorDD(), rarJarFile, moduleName, action.getSpecDD(), null, null, earName, naming, new ModuleIDBuilder()); 341 if (module == null) { 342 throw new DeploymentException("Was not a connector module"); 343 } 344 assertEquals(moduleName, module.getEnvironment().getConfigId().toString()); 345 346 File tempDir = null; 347 try { 348 tempDir = DeploymentUtil.createTempDir(); 349 EARContext earContext = new EARContext(tempDir, 350 null, 351 module.getEnvironment(), 352 module.getType(), 353 naming, 354 configurationManager, 355 Collections.EMPTY_SET, 356 new AbstractNameQuery(serverName, J2EEServerImpl.GBEAN_INFO.getInterfaces()), 357 module.getModuleName(), transactionManagerName, 359 connectionTrackerName, 360 null, 361 null, 362 null 363 ); 364 365 action.install(moduleBuilder, earContext, module, configurationStore); 366 earContext.getClassLoader(); 367 moduleBuilder.initContext(earContext, module, cl); 368 moduleBuilder.addGBeans(earContext, module, cl, Collections.singleton(repository)); 369 370 ConfigurationData configurationData = earContext.getConfigurationData(); 371 AbstractName moduleAbstractName = earContext.getModuleName(); 372 earContext.close(); 373 374 verifyDeployment(configurationData, oldCl, moduleAbstractName, resourceAdapterName, is15, moduleName); 375 } finally { 376 module.close(); 377 DeploymentUtil.recursiveDelete(tempDir); 378 } 379 } finally { 380 kernel.shutdown(); 381 } 382 } 383 384 private void verifyDeployment(ConfigurationData configurationData, ClassLoader cl, AbstractName moduleAbstractName, String resourceAdapterName, boolean is15, String moduleName) throws Exception { 385 DataSource ds = null; 386 try { 387 388 Artifact configurationId = configurationData.getId(); 389 390 configurationManager.loadConfiguration(configurationData); 392 Configuration configuration = configurationManager.getConfiguration(configurationId); 393 configurationManager.startConfiguration(configurationId); 394 Set gb = configuration.getGBeans().keySet(); 395 for (Iterator iterator = gb.iterator(); iterator.hasNext();) { 396 AbstractName name = (AbstractName) iterator.next(); 397 if (State.RUNNING_INDEX != kernel.getGBeanState(name)) { 398 log.debug("Not running: " + name); 399 } 400 } 401 402 assertRunning(kernel, moduleAbstractName); 403 AbstractName resourceAdapterjsr77Name = naming.createChildName(moduleAbstractName, moduleName, NameFactory.RESOURCE_ADAPTER); 404 assertRunning(kernel, resourceAdapterjsr77Name); 405 AbstractName jcaResourcejsr77Name = naming.createChildName(resourceAdapterjsr77Name, moduleName, NameFactory.JCA_RESOURCE); 406 assertRunning(kernel, jcaResourcejsr77Name); 407 408 if (is15) { 410 Map activationSpecInfoMap = (Map ) kernel.getAttribute(moduleAbstractName, "activationSpecInfoMap"); 411 assertEquals(1, activationSpecInfoMap.size()); 412 GBeanData activationSpecInfo = (GBeanData) activationSpecInfoMap.get("javax.jms.MessageListener"); 413 assertNotNull(activationSpecInfo); 414 GBeanInfo activationSpecGBeanInfo = activationSpecInfo.getGBeanInfo(); 415 List attributes1 = activationSpecGBeanInfo.getPersistentAttributes(); 416 assertEquals(2, attributes1.size()); 417 418 Map adminObjectInfoMap = (Map ) kernel.getAttribute(moduleAbstractName, "adminObjectInfoMap"); 419 assertEquals(1, adminObjectInfoMap.size()); 420 GBeanData adminObjectInfo = (GBeanData) adminObjectInfoMap.get("org.apache.geronimo.connector.mock.MockAdminObject"); 421 assertNotNull(adminObjectInfo); 422 GBeanInfo adminObjectGBeanInfo = adminObjectInfo.getGBeanInfo(); 423 List attributes2 = adminObjectGBeanInfo.getPersistentAttributes(); 424 assertEquals(3, attributes2.size()); 425 426 AbstractName resourceAdapterObjectName = naming.createChildName(jcaResourcejsr77Name, resourceAdapterName, NameFactory.JCA_RESOURCE_ADAPTER); 428 429 assertRunning(kernel, resourceAdapterObjectName); 430 assertAttributeValue(kernel, resourceAdapterObjectName, "RAStringProperty", "NewStringValue"); 431 432 Map managedConnectionFactoryInfoMap = (Map ) kernel.getAttribute(moduleAbstractName, "managedConnectionFactoryInfoMap"); 434 assertEquals(2, managedConnectionFactoryInfoMap.size()); 435 GBeanData managedConnectionFactoryInfo = (GBeanData) managedConnectionFactoryInfoMap.get("javax.resource.cci.ConnectionFactory"); 436 assertNotNull(managedConnectionFactoryInfo); 437 GBeanInfo managedConnectionFactoryGBeanInfo = managedConnectionFactoryInfo.getGBeanInfo(); 438 List attributes3 = managedConnectionFactoryGBeanInfo.getPersistentAttributes(); 439 assertEquals(10, attributes3.size()); 440 } 441 442 AbstractName firstOutCF = naming.createChildName(jcaResourcejsr77Name, "FirstTestOutboundConnectionFactory", NameFactory.JCA_CONNECTION_FACTORY); 444 assertRunning(kernel, firstOutCF); 445 446 AbstractName firstOutMCF = naming.createChildName(firstOutCF, "FirstTestOutboundConnectionFactory", NameFactory.JCA_MANAGED_CONNECTION_FACTORY); 447 assertRunning(kernel, firstOutMCF); 448 assertAttributeValue(kernel, firstOutMCF, "OutboundStringProperty1", "newvalue1"); 449 assertAttributeValue(kernel, firstOutMCF, "OutboundStringProperty2", "originalvalue2"); 450 assertAttributeValue(kernel, firstOutMCF, "OutboundStringProperty3", "newvalue2"); 451 452 AbstractName firstConnectionManagerFactory = naming.createChildName(firstOutMCF, "FirstTestOutboundConnectionFactory", NameFactory.JCA_CONNECTION_MANAGER); 453 assertRunning(kernel, firstConnectionManagerFactory); 454 455 AbstractName secondOutCF = naming.createChildName(jcaResourcejsr77Name, "SecondTestOutboundConnectionFactory", NameFactory.JCA_CONNECTION_FACTORY); 457 assertRunning(kernel, secondOutCF); 458 459 AbstractName secondOutMCF = naming.createChildName(secondOutCF, "SecondTestOutboundConnectionFactory", NameFactory.JCA_MANAGED_CONNECTION_FACTORY); 460 assertRunning(kernel, secondOutMCF); 461 462 AbstractName secondConnectionManagerFactory = naming.createChildName(secondOutMCF, "SecondTestOutboundConnectionFactory", NameFactory.JCA_CONNECTION_MANAGER); 463 assertRunning(kernel, secondConnectionManagerFactory); 464 465 AbstractName thirdOutCF = naming.createChildName(jcaResourcejsr77Name, "ThirdTestOutboundConnectionFactory", NameFactory.JCA_CONNECTION_FACTORY); 467 assertRunning(kernel, thirdOutCF); 468 469 AbstractName thirdOutMCF = naming.createChildName(thirdOutCF, "ThirdTestOutboundConnectionFactory", NameFactory.JCA_MANAGED_CONNECTION_FACTORY); 470 assertRunning(kernel, thirdOutMCF); 471 472 AbstractName thirdConnectionManagerFactory = naming.createChildName(thirdOutMCF, "ThirdTestOutboundConnectionFactory", NameFactory.JCA_CONNECTION_MANAGER); 473 assertRunning(kernel, thirdConnectionManagerFactory); 474 475 479 if (is15) { 480 AbstractName tweedledeeAdminObject = naming.createChildName(jcaResourcejsr77Name, "tweedledee", NameFactory.JCA_ADMIN_OBJECT); 481 assertRunning(kernel, tweedledeeAdminObject); 482 483 AbstractName tweedledumAdminObject = naming.createChildName(jcaResourcejsr77Name, "tweedledum", NameFactory.JCA_ADMIN_OBJECT); 484 assertRunning(kernel, tweedledumAdminObject); 485 } 486 487 488 configurationManager.stopConfiguration(configurationId); 489 configurationManager.unloadConfiguration(configurationId); 490 } finally { 491 if (ds != null) { 492 Connection connection = null; 493 Statement statement = null; 494 try { 495 connection = ds.getConnection(); 496 statement = connection.createStatement(); 497 statement.execute("SHUTDOWN"); 498 } finally { 499 JDBCUtil.close(statement); 500 JDBCUtil.close(connection); 501 } 502 } 503 504 if (kernel != null) { 505 kernel.shutdown(); 506 } 507 Thread.currentThread().setContextClassLoader(cl); 508 } 509 } 510 511 private void assertAttributeValue(Kernel kernel, AbstractName name, String attributeName, String attributeValue) throws Exception { 512 Object value = kernel.getAttribute(name, attributeName); 513 assertEquals(attributeValue, value); 514 } 515 516 private void assertRunning(Kernel kernel, AbstractName name) throws Exception { 517 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(name)); 518 } 519 520 protected void setUp() throws Exception { 521 super.setUp(); 522 kernel = KernelFactory.newInstance().createKernel("test"); 523 kernel.boot(); 524 525 ConfigurationData bootstrap = new ConfigurationData(bootId, naming); 526 527 bootstrap.addGBean("ServerInfo", BasicServerInfo.GBEAN_INFO).setAttribute("baseDirectory", "."); 537 538 AbstractName configStoreName = bootstrap.addGBean("MockConfigurationStore", MockConfigStore.GBEAN_INFO).getAbstractName(); 539 540 GBeanData artifactManagerData = bootstrap.addGBean("ArtifactManager", DefaultArtifactManager.GBEAN_INFO); 541 542 GBeanData artifactResolverData = bootstrap.addGBean("ArtifactResolver", DefaultArtifactResolver.GBEAN_INFO); 543 artifactResolverData.setReferencePattern("ArtifactManager", artifactManagerData.getAbstractName()); 544 545 GBeanData configurationManagerData = bootstrap.addGBean("ConfigurationManager", EditableKernelConfigurationManager.GBEAN_INFO); 546 configurationManagerData.setReferencePattern("ArtifactManager", artifactManagerData.getAbstractName()); 547 configurationManagerData.setReferencePattern("ArtifactResolver", artifactResolverData.getAbstractName()); 548 configurationManagerData.setReferencePattern("Stores", configStoreName); 549 bootstrap.addGBean(configurationManagerData); 550 551 GBeanData serverData = bootstrap.addGBean("geronimo", J2EEServerImpl.GBEAN_INFO); 552 serverName = serverData.getAbstractName(); 553 bootstrap.addGBean(serverData); 554 555 556 GBeanData tm = bootstrap.addGBean("TransactionManager", GeronimoTransactionManagerGBean.GBEAN_INFO); 558 tm.setAttribute("defaultTransactionTimeoutSeconds", new Integer (10)); 559 560 ConfigurationUtil.loadBootstrapConfiguration(kernel, bootstrap, getClass().getClassLoader()); 561 562 configurationManager = ConfigurationUtil.getEditableConfigurationManager(kernel); 563 ConfigurationStore configStore = (ConfigurationStore) kernel.getGBean(configStoreName); 565 configStore.install(bootstrap); 566 567 defaultEnvironment = new Environment(); 568 defaultEnvironment.addDependency(bootstrap.getId(), ImportType.ALL); 569 570 } 571 572 protected void tearDown() throws Exception { 573 kernel.shutdown(); 574 super.tearDown(); 575 } 576 577 private abstract class InstallAction { 578 public File getVendorDD() { 579 return null; 580 } 581 582 public URL getSpecDD() throws MalformedURLException { 583 return null; 584 } 585 586 public abstract File getRARFile(); 587 588 public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module, ConfigurationStore configurationStore) throws Exception { 589 moduleBuilder.installModule(module.getModuleFile(), earContext, module, Collections.singleton(configurationStore), configurationStore, Collections.singleton(repository)); 590 } 591 } 592 593 public static class MockConfigStore extends NullConfigurationStore { 594 private Map configs = new HashMap (); 595 596 URL baseURL; 597 598 public MockConfigStore() { 599 } 600 601 public MockConfigStore(URL baseURL) { 602 this.baseURL = baseURL; 603 } 604 605 public void install(ConfigurationData configurationData) throws IOException , InvalidConfigException { 606 configs.put(configurationData.getId(), configurationData); 607 } 608 609 public void uninstall(Artifact configID) throws NoSuchConfigException, IOException { 610 configs.remove(configID); 611 } 612 613 public ConfigurationData loadConfiguration(Artifact configId) throws NoSuchConfigException, IOException , InvalidConfigException { 614 if (configs.containsKey(configId)) { 615 ConfigurationData configurationData = (ConfigurationData) configs.get(configId); 616 configurationData.setConfigurationStore(this); 617 return configurationData; 618 } else { 619 ConfigurationData configurationData = new ConfigurationData(configId, naming); 620 configurationData.setConfigurationStore(this); 621 return configurationData; 622 } 623 } 624 625 public boolean containsConfiguration(Artifact configID) { 626 return true; 627 } 628 629 public File createNewConfigurationDir(Artifact configId) { 630 try { 631 return DeploymentUtil.createTempDir(); 632 } catch (IOException e) { 633 return null; 634 } 635 } 636 637 public Set resolve(Artifact configId, String moduleName, String pattern) throws NoSuchConfigException, MalformedURLException { 638 return Collections.singleton(baseURL); 639 } 640 641 public final static GBeanInfo GBEAN_INFO; 642 643 static { 644 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(MockConfigStore.class, NameFactory.CONFIGURATION_STORE); 645 infoBuilder.addInterface(ConfigurationStore.class); 646 GBEAN_INFO = infoBuilder.getBeanInfo(); 647 } 648 } 649 } 650 | Popular Tags |