KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > deployment > ConnectorModuleBuilderTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.connector.deployment;
19
20 import java.io.File JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.net.URLClassLoader JavaDoc;
25 import java.sql.Connection JavaDoc;
26 import java.sql.Statement JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.LinkedHashSet JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.Set JavaDoc;
34 import java.util.jar.JarFile JavaDoc;
35
36 import javax.naming.Reference JavaDoc;
37 import javax.sql.DataSource JavaDoc;
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 /**
84  * @version $Rev:385232 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
85  */

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 JavaDoc getLocation(Artifact artifact) {
102             return null;
103         }
104
105         public LinkedHashSet JavaDoc getDependencies(Artifact artifact) {
106             return new LinkedHashSet JavaDoc();
107         }
108     };
109
110     private ActivationSpecInfoLocator activationSpecInfoLocator = new ActivationSpecInfoLocator() {
111
112         public Reference JavaDoc createResourceRef(AbstractNameQuery containerId, Class JavaDoc iface, Configuration configuration) {
113             return null;
114         }
115
116         public Reference JavaDoc createAdminObjectRef(AbstractNameQuery containerId, Class JavaDoc iface, Configuration configuration) {
117             return null;
118         }
119
120         public GBeanData locateActivationSpecInfo(AbstractNameQuery nameQuery, String JavaDoc 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 JavaDoc {
136         JarFile JavaDoc rarFile = null;
137         try {
138             rarFile = DeploymentUtil.createJarFile(new File JavaDoc(BASEDIR, "target/test-ear-noger.ear"));
139             GBeanBuilder serviceBuilder = new GBeanBuilder(null, null);
140 // EARConfigBuilder configBuilder = new EARConfigBuilder(defaultEnvironment, transactionContextManagerName, connectionTrackerName, null, null, null, new AbstractNameQuery(serverName, J2EEServerImpl.GBEAN_INFO.getInterfaces()), null, null, ejbReferenceBuilder, null,
141
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 JavaDoc planFile = new File JavaDoc(BASEDIR, "src/test/data/data/external-application-plan.xml");
164                 ModuleIDBuilder idBuilder = new ModuleIDBuilder();
165                 Object JavaDoc 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                 // add the a j2ee server so the application context reference can be resolved
169
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 JavaDoc {
186         InstallAction action = new InstallAction() {
187             public File JavaDoc getRARFile() {
188                 return new File JavaDoc(BASEDIR, "target/test-rar-10");
189             }
190         };
191         executeTestBuildModule(action, false);
192     }
193
194     public void testBuildUnpackedAltSpecDDModule() throws Exception JavaDoc {
195         InstallAction action = new InstallAction() {
196             public File JavaDoc getVendorDD() {
197                 return new File JavaDoc(BASEDIR, "target/test-rar-10/META-INF/geronimo-ra.xml");
198             }
199
200             public URL JavaDoc getSpecDD() throws MalformedURLException JavaDoc {
201                 return new File JavaDoc(BASEDIR, "target/test-rar-10/dummy.xml").toURL();
202             }
203
204             public File JavaDoc getRARFile() {
205                 return new File JavaDoc(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 JavaDoc {
216         InstallAction action = new InstallAction() {
217             public File JavaDoc getVendorDD() {
218                 // this file does not exist, one expects a DeploymentException.
219
return new File JavaDoc(BASEDIR, "target/test-rar-10/dummy.xml");
220             }
221
222             public URL JavaDoc getSpecDD() throws MalformedURLException JavaDoc {
223                 return new File JavaDoc(BASEDIR, "target/test-rar-10/META-INF/ra.xml").toURL();
224             }
225
226             public File JavaDoc getRARFile() {
227                 return new File JavaDoc(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 JavaDoc {
238         InstallAction action = new InstallAction() {
239             public File JavaDoc getVendorDD() {
240                 // this file exists
241
return new File JavaDoc(BASEDIR, "target/test-rar-10/META-INF/geronimo-ra.xml");
242             }
243
244             public URL JavaDoc getSpecDD() throws MalformedURLException JavaDoc {
245                 return new File JavaDoc(BASEDIR, "target/test-rar-10/META-INF/ra.xml").toURL();
246             }
247
248             public File JavaDoc getRARFile() {
249                 return new File JavaDoc(BASEDIR, "target/test-rar-10");
250             }
251         };
252         executeTestBuildModule(action, false);
253     }
254
255     public void testBuildPackedModule() throws Exception JavaDoc {
256         InstallAction action = new InstallAction() {
257             public File JavaDoc getRARFile() {
258                 return new File JavaDoc(BASEDIR, "target/test-rar-10.rar");
259             }
260         };
261         executeTestBuildModule(action, false);
262     }
263
264     //1.5 tests
265
public void testBuildUnpackedModule15() throws Exception JavaDoc {
266         InstallAction action = new InstallAction() {
267             private File JavaDoc rarFile = new File JavaDoc(BASEDIR, "target/test-rar-15");
268
269             public File JavaDoc getRARFile() {
270                 return rarFile;
271             }
272
273         };
274         executeTestBuildModule(action, true);
275     }
276
277
278     public void testBuildPackedModule15() throws Exception JavaDoc {
279         InstallAction action = new InstallAction() {
280             private File JavaDoc rarFile = new File JavaDoc(BASEDIR, "target/test-rar-15.rar");
281
282             public File JavaDoc getRARFile() {
283                 return rarFile;
284             }
285
286         };
287         executeTestBuildModule(action, true);
288     }
289     
290     public void testBuildPackedModule15LocalTx() throws Exception JavaDoc {
291         InstallAction action = new InstallAction() {
292             private File JavaDoc rarFile = new File JavaDoc(BASEDIR, "target/test-rar-15-localtx.rar");
293
294             public File JavaDoc 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 JavaDoc {
308         InstallAction action = new InstallAction() {
309             private File JavaDoc rarFile = new File JavaDoc(BASEDIR, "target/test-rar-15-notx.rar");
310
311             public File JavaDoc 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 JavaDoc {
326         String JavaDoc 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 JavaDoc rarFile = action.getRARFile();
331
332             ClassLoader JavaDoc oldCl = Thread.currentThread().getContextClassLoader();
333             ClassLoader JavaDoc cl = new URLClassLoader JavaDoc(new URL JavaDoc[]{rarFile.toURL()}, oldCl);
334
335             Thread.currentThread().setContextClassLoader(cl);
336
337             JarFile JavaDoc rarJarFile = DeploymentUtil.createJarFile(rarFile);
338             AbstractName earName = null;
339             String JavaDoc 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 JavaDoc 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(), //hardcode standalone here.
358
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 JavaDoc cl, AbstractName moduleAbstractName, String JavaDoc resourceAdapterName, boolean is15, String JavaDoc moduleName) throws Exception JavaDoc {
385         DataSource JavaDoc ds = null;
386         try {
387
388             Artifact configurationId = configurationData.getId();
389
390             // load the configuration
391
configurationManager.loadConfiguration(configurationData);
392             Configuration configuration = configurationManager.getConfiguration(configurationId);
393             configurationManager.startConfiguration(configurationId);
394             Set JavaDoc gb = configuration.getGBeans().keySet();
395             for (Iterator JavaDoc 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             //1.5 only
409
if (is15) {
410                 Map JavaDoc activationSpecInfoMap = (Map JavaDoc) 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 JavaDoc attributes1 = activationSpecGBeanInfo.getPersistentAttributes();
416                 assertEquals(2, attributes1.size());
417
418                 Map JavaDoc adminObjectInfoMap = (Map JavaDoc) 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 JavaDoc attributes2 = adminObjectGBeanInfo.getPersistentAttributes();
424                 assertEquals(3, attributes2.size());
425
426                 // ResourceAdapter
427
AbstractName resourceAdapterObjectName = naming.createChildName(jcaResourcejsr77Name, resourceAdapterName, NameFactory.JCA_RESOURCE_ADAPTER);
428
429                 assertRunning(kernel, resourceAdapterObjectName);
430                 assertAttributeValue(kernel, resourceAdapterObjectName, "RAStringProperty", "NewStringValue");
431
432                 //both, except 1.0 has only one mcf type
433
Map JavaDoc managedConnectionFactoryInfoMap = (Map JavaDoc) 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 JavaDoc attributes3 = managedConnectionFactoryGBeanInfo.getPersistentAttributes();
439                 assertEquals(10, attributes3.size());
440             }
441
442             // FirstTestOutboundConnectionFactory
443
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             // SecondTestOutboundConnectionFactory
456
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             // ThirdTestOutboundConnectionFactory
466
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             // 1.5 only
476
// Admin objects
477
//
478

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 JavaDoc connection = null;
493                 Statement JavaDoc 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 JavaDoc attributeName, String JavaDoc attributeValue) throws Exception JavaDoc {
512         Object JavaDoc value = kernel.getAttribute(name, attributeName);
513         assertEquals(attributeValue, value);
514     }
515
516     private void assertRunning(Kernel kernel, AbstractName name) throws Exception JavaDoc {
517         assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(name));
518     }
519
520     protected void setUp() throws Exception JavaDoc {
521         super.setUp();
522         kernel = KernelFactory.newInstance().createKernel("test");
523         kernel.boot();
524
525         ConfigurationData bootstrap = new ConfigurationData(bootId, naming);
526
527 // GBeanData artifactManagerData = bootstrap.addGBean("ArtifactManager", DefaultArtifactManager.GBEAN_INFO);
528
//
529
// GBeanData artifactResolverData = bootstrap.addGBean("ArtifactResolver", DefaultArtifactResolver.GBEAN_INFO);
530
// artifactResolverData.setReferencePattern("ArtifactManager", artifactManagerData.getAbstractName());
531
//
532
// GBeanData configurationManagerData = bootstrap.addGBean("ConfigurationManager", EditableKernelConfigurationManager.GBEAN_INFO);
533
// configurationManagerData.setReferencePattern("ArtifactManager", artifactManagerData.getAbstractName());
534
// configurationManagerData.setReferencePattern("ArtifactResolver", artifactResolverData.getAbstractName());
535
// bootstrap.addGBean(configurationManagerData);
536
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         // add fake TransactionManager so refs will resolve
557
GBeanData tm = bootstrap.addGBean("TransactionManager", GeronimoTransactionManagerGBean.GBEAN_INFO);
558         tm.setAttribute("defaultTransactionTimeoutSeconds", new Integer JavaDoc(10));
559
560         ConfigurationUtil.loadBootstrapConfiguration(kernel, bootstrap, getClass().getClassLoader());
561
562         configurationManager = ConfigurationUtil.getEditableConfigurationManager(kernel);
563 // configurationManager.getConfiguration(bootstrap.getId());
564
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 JavaDoc {
573         kernel.shutdown();
574         super.tearDown();
575     }
576
577     private abstract class InstallAction {
578         public File JavaDoc getVendorDD() {
579             return null;
580         }
581
582         public URL JavaDoc getSpecDD() throws MalformedURLException JavaDoc {
583             return null;
584         }
585
586         public abstract File JavaDoc getRARFile();
587
588         public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module, ConfigurationStore configurationStore) throws Exception JavaDoc {
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 JavaDoc configs = new HashMap JavaDoc();
595
596         URL JavaDoc baseURL;
597
598         public MockConfigStore() {
599         }
600
601         public MockConfigStore(URL JavaDoc baseURL) {
602             this.baseURL = baseURL;
603         }
604
605         public void install(ConfigurationData configurationData) throws IOException JavaDoc, InvalidConfigException {
606             configs.put(configurationData.getId(), configurationData);
607         }
608
609         public void uninstall(Artifact configID) throws NoSuchConfigException, IOException JavaDoc {
610             configs.remove(configID);
611         }
612
613         public ConfigurationData loadConfiguration(Artifact configId) throws NoSuchConfigException, IOException JavaDoc, 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 JavaDoc createNewConfigurationDir(Artifact configId) {
630             try {
631                 return DeploymentUtil.createTempDir();
632             } catch (IOException JavaDoc e) {
633                 return null;
634             }
635         }
636
637         public Set JavaDoc resolve(Artifact configId, String JavaDoc moduleName, String JavaDoc pattern) throws NoSuchConfigException, MalformedURLException JavaDoc {
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