Source Code Cross Referenced for ConnectorModuleBuilderTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » connector » deployment » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.connector.deployment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.connector.deployment;
017:
018:        import java.io.File;
019:        import java.net.MalformedURLException;
020:        import java.net.URL;
021:        import java.net.URLClassLoader;
022:        import java.sql.Connection;
023:        import java.sql.Statement;
024:        import java.util.Collections;
025:        import java.util.HashSet;
026:        import java.util.List;
027:        import java.util.Map;
028:        import java.util.Set;
029:        import java.util.jar.JarFile;
030:
031:        import javax.naming.Reference;
032:        import javax.sql.DataSource;
033:
034:        import org.apache.geronimo.common.DeploymentException;
035:        import org.apache.geronimo.deployment.DeploymentContext;
036:        import org.apache.geronimo.deployment.ModuleIDBuilder;
037:        import org.apache.geronimo.deployment.service.GBeanBuilder;
038:        import org.apache.geronimo.deployment.util.DeploymentUtil;
039:        import org.apache.geronimo.gbean.AbstractName;
040:        import org.apache.geronimo.gbean.AbstractNameQuery;
041:        import org.apache.geronimo.gbean.GBeanData;
042:        import org.apache.geronimo.gbean.GBeanInfo;
043:        import org.apache.geronimo.j2ee.deployment.ActivationSpecInfoLocator;
044:        import org.apache.geronimo.j2ee.deployment.EARConfigBuilder;
045:        import org.apache.geronimo.j2ee.deployment.EARContext;
046:        import org.apache.geronimo.j2ee.deployment.Module;
047:        import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
048:        import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
049:        import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl;
050:        import org.apache.geronimo.kernel.Jsr77Naming;
051:        import org.apache.geronimo.kernel.Kernel;
052:        import org.apache.geronimo.kernel.KernelFactory;
053:        import org.apache.geronimo.kernel.Naming;
054:        import org.apache.geronimo.kernel.config.Configuration;
055:        import org.apache.geronimo.kernel.config.ConfigurationData;
056:        import org.apache.geronimo.kernel.config.ConfigurationStore;
057:        import org.apache.geronimo.kernel.config.ConfigurationUtil;
058:        import org.apache.geronimo.kernel.config.EditableConfigurationManager;
059:        import org.apache.geronimo.kernel.config.EditableKernelConfigurationManager;
060:        import org.apache.geronimo.kernel.management.State;
061:        import org.apache.geronimo.kernel.mock.MockConfigStore;
062:        import org.apache.geronimo.kernel.mock.MockRepository;
063:        import org.apache.geronimo.kernel.repository.Artifact;
064:        import org.apache.geronimo.kernel.repository.ArtifactManager;
065:        import org.apache.geronimo.kernel.repository.ArtifactResolver;
066:        import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
067:        import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
068:        import org.apache.geronimo.kernel.repository.Environment;
069:        import org.apache.geronimo.kernel.repository.ImportType;
070:        import org.apache.geronimo.kernel.repository.ListableRepository;
071:        import org.apache.geronimo.system.serverinfo.BasicServerInfo;
072:        import org.apache.geronimo.testsupport.TestSupport;
073:        import org.apache.geronimo.transaction.manager.GeronimoTransactionManagerGBean;
074:
075:        /**
076:         * @version $Rev:385232 $ $Date: 2008-01-17 23:54:14 -0800 (Thu, 17 Jan 2008) $
077:         */
078:        public class ConnectorModuleBuilderTest extends TestSupport {
079:
080:            private boolean defaultXATransactionCaching = true;
081:            private boolean defaultXAThreadCaching = false;
082:            private int defaultMaxSize = 10;
083:            private int defaultMinSize = 0;
084:            private int defaultBlockingTimeoutMilliseconds = 5000;
085:            private int defaultidleTimeoutMinutes = 15;
086:            private Environment defaultEnvironment;
087:            private ConfigurationStore configurationStore = new MockConfigStore();
088:            private MockRepository repository;
089:
090:            private ActivationSpecInfoLocator activationSpecInfoLocator = new ActivationSpecInfoLocator() {
091:
092:                public Reference createResourceRef(
093:                        AbstractNameQuery containerId, Class iface,
094:                        Configuration configuration) {
095:                    return null;
096:                }
097:
098:                public Reference createAdminObjectRef(
099:                        AbstractNameQuery containerId, Class iface,
100:                        Configuration configuration) {
101:                    return null;
102:                }
103:
104:                public GBeanData locateActivationSpecInfo(
105:                        AbstractNameQuery nameQuery,
106:                        String messageListenerInterface,
107:                        Configuration configuration) {
108:                    return null;
109:                }
110:            };
111:
112:            private Kernel kernel;
113:            private EditableConfigurationManager configurationManager;
114:            private static final Naming naming = new Jsr77Naming();
115:            private static final Artifact bootId = new Artifact("test", "test",
116:                    "42", "car");
117:
118:            private static final AbstractNameQuery connectionTrackerName = new AbstractNameQuery(
119:                    null, Collections.singletonMap("name", "ConnectionTracker"));
120:            private AbstractName serverName;
121:            private static final AbstractNameQuery transactionManagerName = new AbstractNameQuery(
122:                    null, Collections
123:                            .singletonMap("name", "TransactionManager"));
124:
125:            public void testBuildEar() throws Exception {
126:                JarFile rarFile = null;
127:                try {
128:                    rarFile = DeploymentUtil.createJarFile(new File(BASEDIR,
129:                            "target/test-ear-noger.ear"));
130:                    GBeanBuilder serviceBuilder = new GBeanBuilder(null, null);
131:                    //            EARConfigBuilder configBuilder = new EARConfigBuilder(defaultEnvironment, transactionContextManagerName, connectionTrackerName, null, null, null, new AbstractNameQuery(serverName, J2EEServerImpl.GBEAN_INFO.getInterfaces()), null, null, ejbReferenceBuilder, null,
132:                    EARConfigBuilder configBuilder = new EARConfigBuilder(
133:                            defaultEnvironment, transactionManagerName,
134:                            connectionTrackerName, null, null, null,
135:                            new AbstractNameQuery(serverName,
136:                                    J2EEServerImpl.GBEAN_INFO.getInterfaces()),
137:                            Collections.singleton(repository), null, null,
138:                            new ConnectorModuleBuilder(defaultEnvironment,
139:                                    defaultMaxSize, defaultMinSize,
140:                                    defaultBlockingTimeoutMilliseconds,
141:                                    defaultidleTimeoutMinutes,
142:                                    defaultXATransactionCaching,
143:                                    defaultXAThreadCaching, Collections
144:                                            .singleton(serviceBuilder)),
145:                            activationSpecInfoLocator, null, null,
146:                            serviceBuilder, null, kernel.getNaming(), null);
147:                    configBuilder.doStart();
148:                    ConfigurationData configData = null;
149:                    DeploymentContext context = null;
150:                    ArtifactManager artifactManager = new DefaultArtifactManager();
151:                    ArtifactResolver artifactResolver = new DefaultArtifactResolver(
152:                            artifactManager, Collections.singleton(repository),
153:                            null);
154:
155:                    try {
156:                        File planFile = new File(BASEDIR,
157:                                "src/test/data/data/external-application-plan.xml");
158:                        ModuleIDBuilder idBuilder = new ModuleIDBuilder();
159:                        Object plan = configBuilder.getDeploymentPlan(planFile,
160:                                rarFile, idBuilder);
161:                        context = configBuilder.buildConfiguration(false,
162:                                configBuilder.getConfigurationID(plan, rarFile,
163:                                        idBuilder), plan, rarFile, Collections
164:                                        .singleton(configurationStore),
165:                                artifactResolver, configurationStore);
166:
167:                        // add the a j2ee server so the application context reference can be resolved
168:                        context.addGBean("geronimo", J2EEServerImpl.GBEAN_INFO);
169:
170:                        configData = context.getConfigurationData();
171:                    } finally {
172:                        if (context != null) {
173:                            context.close();
174:                        }
175:                        if (configData != null) {
176:                            DeploymentUtil.recursiveDelete(configData
177:                                    .getConfigurationDir());
178:                        }
179:                    }
180:                    configBuilder.doStop();
181:                } finally {
182:                    DeploymentUtil.close(rarFile);
183:
184:                }
185:            }
186:
187:            public void testBuildUnpackedModule() throws Exception {
188:                InstallAction action = new InstallAction() {
189:                    public File getRARFile() {
190:                        return new File(BASEDIR, "target/test-rar-10");
191:                    }
192:                };
193:                executeTestBuildModule(action, false);
194:            }
195:
196:            public void testBuildUnpackedAltSpecDDModule() throws Exception {
197:                InstallAction action = new InstallAction() {
198:                    public File getVendorDD() {
199:                        return new File(BASEDIR,
200:                                "target/test-rar-10/META-INF/geronimo-ra.xml");
201:                    }
202:
203:                    public URL getSpecDD() throws MalformedURLException {
204:                        return new File(BASEDIR, "target/test-rar-10/dummy.xml")
205:                                .toURL();
206:                    }
207:
208:                    public File getRARFile() {
209:                        return new File(BASEDIR, "target/test-rar-10");
210:                    }
211:                };
212:                try {
213:                    executeTestBuildModule(action, false);
214:                    fail("Spec alt-dd does not exist.");
215:                } catch (DeploymentException e) {
216:                }
217:            }
218:
219:            public void testBuildUnpackedAltVendorDDModule() throws Exception {
220:                InstallAction action = new InstallAction() {
221:                    public File getVendorDD() {
222:                        // this file does not exist, one expects a DeploymentException.
223:                        return new File(BASEDIR, "target/test-rar-10/dummy.xml");
224:                    }
225:
226:                    public URL getSpecDD() throws MalformedURLException {
227:                        return new File(BASEDIR,
228:                                "target/test-rar-10/META-INF/ra.xml").toURL();
229:                    }
230:
231:                    public File getRARFile() {
232:                        return new File(BASEDIR, "target/test-rar-10");
233:                    }
234:                };
235:                try {
236:                    executeTestBuildModule(action, false);
237:                    fail("Vendor alt-dd does not exist.");
238:                } catch (DeploymentException e) {
239:                }
240:            }
241:
242:            public void testBuildUnpackedAltSpecVendorDDModule()
243:                    throws Exception {
244:                InstallAction action = new InstallAction() {
245:                    public File getVendorDD() {
246:                        // this file exists
247:                        return new File(BASEDIR,
248:                                "target/test-rar-10/META-INF/geronimo-ra.xml");
249:                    }
250:
251:                    public URL getSpecDD() throws MalformedURLException {
252:                        return new File(BASEDIR,
253:                                "target/test-rar-10/META-INF/ra.xml").toURL();
254:                    }
255:
256:                    public File getRARFile() {
257:                        return new File(BASEDIR, "target/test-rar-10");
258:                    }
259:                };
260:                executeTestBuildModule(action, false);
261:            }
262:
263:            public void testBuildPackedModule() throws Exception {
264:                InstallAction action = new InstallAction() {
265:                    public File getRARFile() {
266:                        return new File(BASEDIR, "target/test-rar-10.rar");
267:                    }
268:                };
269:                executeTestBuildModule(action, false);
270:            }
271:
272:            //1.5 tests
273:            public void testBuildUnpackedModule15() throws Exception {
274:                InstallAction action = new InstallAction() {
275:                    private File rarFile = new File(BASEDIR,
276:                            "target/test-rar-15");
277:
278:                    public File getRARFile() {
279:                        return rarFile;
280:                    }
281:
282:                };
283:                executeTestBuildModule(action, true);
284:            }
285:
286:            public void testBuildPackedModule15() throws Exception {
287:                InstallAction action = new InstallAction() {
288:                    private File rarFile = new File(BASEDIR,
289:                            "target/test-rar-15.rar");
290:
291:                    public File getRARFile() {
292:                        return rarFile;
293:                    }
294:
295:                };
296:                executeTestBuildModule(action, true);
297:            }
298:
299:            public void testBuildPackedModule15LocalTx() throws Exception {
300:                InstallAction action = new InstallAction() {
301:                    private File rarFile = new File(BASEDIR,
302:                            "target/test-rar-15-localtx.rar");
303:
304:                    public File getRARFile() {
305:                        return rarFile;
306:                    }
307:
308:                };
309:                try {
310:                    executeTestBuildModule(action, true);
311:                    fail("transaction setting mismatch not detected");
312:                } catch (DeploymentException e) {
313:
314:                }
315:            }
316:
317:            public void testBuildPackedModule15NoTx() throws Exception {
318:                InstallAction action = new InstallAction() {
319:                    private File rarFile = new File(BASEDIR,
320:                            "target/test-rar-15-notx.rar");
321:
322:                    public File getRARFile() {
323:                        return rarFile;
324:                    }
325:
326:                };
327:                try {
328:                    executeTestBuildModule(action, true);
329:                    fail("transaction setting mismatch not detected");
330:                } catch (DeploymentException e) {
331:
332:                }
333:            }
334:
335:            private void executeTestBuildModule(InstallAction action,
336:                    boolean is15) throws Exception {
337:                String resourceAdapterName = "testRA";
338:
339:                try {
340:                    ConnectorModuleBuilder moduleBuilder = new ConnectorModuleBuilder(
341:                            defaultEnvironment, defaultMaxSize, defaultMinSize,
342:                            defaultBlockingTimeoutMilliseconds,
343:                            defaultidleTimeoutMinutes,
344:                            defaultXATransactionCaching,
345:                            defaultXAThreadCaching, Collections
346:                                    .singleton(new GBeanBuilder(null, null)));
347:                    File rarFile = action.getRARFile();
348:
349:                    ClassLoader oldCl = Thread.currentThread()
350:                            .getContextClassLoader();
351:                    ClassLoader cl = new URLClassLoader(new URL[] { rarFile
352:                            .toURL() }, oldCl);
353:
354:                    Thread.currentThread().setContextClassLoader(cl);
355:
356:                    JarFile rarJarFile = DeploymentUtil.createJarFile(rarFile);
357:                    AbstractName earName = null;
358:                    String moduleName = "geronimo/test-ear/1.0/car";
359:                    Module module = moduleBuilder.createModule(action
360:                            .getVendorDD(), rarJarFile, moduleName, action
361:                            .getSpecDD(), null, null, earName, naming,
362:                            new ModuleIDBuilder());
363:                    if (module == null) {
364:                        throw new DeploymentException(
365:                                "Was not a connector module");
366:                    }
367:                    assertEquals(moduleName, module.getEnvironment()
368:                            .getConfigId().toString());
369:
370:                    File tempDir = null;
371:                    try {
372:                        tempDir = DeploymentUtil.createTempDir();
373:                        EARContext earContext = new EARContext(tempDir, null,
374:                                module.getEnvironment(), module.getType(),
375:                                naming, configurationManager,
376:                                Collections.EMPTY_SET, new AbstractNameQuery(
377:                                        serverName, J2EEServerImpl.GBEAN_INFO
378:                                                .getInterfaces()),
379:                                module.getModuleName(), //hardcode standalone here.
380:                                transactionManagerName, connectionTrackerName,
381:                                null, null, null);
382:
383:                        action.install(moduleBuilder, earContext, module,
384:                                configurationStore);
385:                        earContext.getClassLoader();
386:                        moduleBuilder.initContext(earContext, module, cl);
387:                        moduleBuilder.addGBeans(earContext, module, cl,
388:                                Collections.singleton(repository));
389:
390:                        ConfigurationData configurationData = earContext
391:                                .getConfigurationData();
392:                        AbstractName moduleAbstractName = earContext
393:                                .getModuleName();
394:                        earContext.close();
395:
396:                        verifyDeployment(configurationData, oldCl,
397:                                moduleAbstractName, resourceAdapterName, is15,
398:                                moduleName);
399:                    } finally {
400:                        module.close();
401:                        DeploymentUtil.recursiveDelete(tempDir);
402:                    }
403:                } finally {
404:                    kernel.shutdown();
405:                }
406:            }
407:
408:            private void verifyDeployment(ConfigurationData configurationData,
409:                    ClassLoader cl, AbstractName moduleAbstractName,
410:                    String resourceAdapterName, boolean is15, String moduleName)
411:                    throws Exception {
412:                DataSource ds = null;
413:                try {
414:
415:                    Artifact configurationId = configurationData.getId();
416:
417:                    // load the configuration
418:                    configurationManager.loadConfiguration(configurationData);
419:                    Configuration configuration = configurationManager
420:                            .getConfiguration(configurationId);
421:                    configurationManager.startConfiguration(configurationId);
422:                    Set<AbstractName> gb = configuration.getGBeans().keySet();
423:                    for (AbstractName name : gb) {
424:                        if (State.RUNNING_INDEX != kernel.getGBeanState(name)) {
425:                            log.debug("Not running: " + name);
426:                        }
427:                    }
428:
429:                    assertRunning(kernel, moduleAbstractName);
430:                    AbstractName resourceAdapterjsr77Name = naming
431:                            .createChildName(moduleAbstractName, moduleName,
432:                                    NameFactory.RESOURCE_ADAPTER);
433:                    assertRunning(kernel, resourceAdapterjsr77Name);
434:                    AbstractName jcaResourcejsr77Name = naming.createChildName(
435:                            resourceAdapterjsr77Name, moduleName,
436:                            NameFactory.JCA_RESOURCE);
437:                    assertRunning(kernel, jcaResourcejsr77Name);
438:
439:                    //1.5 only
440:                    if (is15) {
441:                        Map activationSpecInfoMap = (Map) kernel.getAttribute(
442:                                moduleAbstractName, "activationSpecInfoMap");
443:                        assertEquals(1, activationSpecInfoMap.size());
444:                        GBeanData activationSpecInfo = (GBeanData) activationSpecInfoMap
445:                                .get("javax.jms.MessageListener");
446:                        assertNotNull(activationSpecInfo);
447:                        GBeanInfo activationSpecGBeanInfo = activationSpecInfo
448:                                .getGBeanInfo();
449:                        List attributes1 = activationSpecGBeanInfo
450:                                .getPersistentAttributes();
451:                        assertEquals(2, attributes1.size());
452:
453:                        Map adminObjectInfoMap = (Map) kernel.getAttribute(
454:                                moduleAbstractName, "adminObjectInfoMap");
455:                        assertEquals(1, adminObjectInfoMap.size());
456:                        GBeanData adminObjectInfo = (GBeanData) adminObjectInfoMap
457:                                .get("org.apache.geronimo.connector.mock.MockAdminObject");
458:                        assertNotNull(adminObjectInfo);
459:                        GBeanInfo adminObjectGBeanInfo = adminObjectInfo
460:                                .getGBeanInfo();
461:                        List attributes2 = adminObjectGBeanInfo
462:                                .getPersistentAttributes();
463:                        assertEquals(3, attributes2.size());
464:
465:                        // ResourceAdapter
466:                        AbstractName resourceAdapterObjectName = naming
467:                                .createChildName(jcaResourcejsr77Name,
468:                                        resourceAdapterName,
469:                                        NameFactory.JCA_RESOURCE_ADAPTER);
470:
471:                        assertRunning(kernel, resourceAdapterObjectName);
472:                        assertAttributeValue(kernel, resourceAdapterObjectName,
473:                                "RAStringProperty", "NewStringValue");
474:
475:                        //both, except 1.0 has only one mcf type
476:                        Map managedConnectionFactoryInfoMap = (Map) kernel
477:                                .getAttribute(moduleAbstractName,
478:                                        "managedConnectionFactoryInfoMap");
479:                        assertEquals(2, managedConnectionFactoryInfoMap.size());
480:                        GBeanData managedConnectionFactoryInfo = (GBeanData) managedConnectionFactoryInfoMap
481:                                .get("javax.resource.cci.ConnectionFactory");
482:                        assertNotNull(managedConnectionFactoryInfo);
483:                        GBeanInfo managedConnectionFactoryGBeanInfo = managedConnectionFactoryInfo
484:                                .getGBeanInfo();
485:                        List attributes3 = managedConnectionFactoryGBeanInfo
486:                                .getPersistentAttributes();
487:                        assertEquals(11, attributes3.size());
488:                    }
489:
490:                    // FirstTestOutboundConnectionFactory
491:                    AbstractName firstOutCF = naming.createChildName(
492:                            jcaResourcejsr77Name,
493:                            "FirstTestOutboundConnectionFactory",
494:                            NameFactory.JCA_CONNECTION_FACTORY);
495:                    assertRunning(kernel, firstOutCF);
496:
497:                    AbstractName firstOutMCF = naming.createChildName(
498:                            firstOutCF, "FirstTestOutboundConnectionFactory",
499:                            NameFactory.JCA_MANAGED_CONNECTION_FACTORY);
500:                    assertRunning(kernel, firstOutMCF);
501:                    assertAttributeValue(kernel, firstOutMCF,
502:                            "OutboundStringProperty1", "newvalue1");
503:                    assertAttributeValue(kernel, firstOutMCF,
504:                            "OutboundStringProperty2", "originalvalue2");
505:                    assertAttributeValue(kernel, firstOutMCF,
506:                            "OutboundStringProperty3", "newvalue2");
507:
508:                    AbstractName firstConnectionManagerFactory = naming
509:                            .createChildName(firstOutMCF,
510:                                    "FirstTestOutboundConnectionFactory",
511:                                    NameFactory.JCA_CONNECTION_MANAGER);
512:                    assertRunning(kernel, firstConnectionManagerFactory);
513:
514:                    // SecondTestOutboundConnectionFactory
515:                    AbstractName secondOutCF = naming.createChildName(
516:                            jcaResourcejsr77Name,
517:                            "SecondTestOutboundConnectionFactory",
518:                            NameFactory.JCA_CONNECTION_FACTORY);
519:                    assertRunning(kernel, secondOutCF);
520:
521:                    AbstractName secondOutMCF = naming.createChildName(
522:                            secondOutCF, "SecondTestOutboundConnectionFactory",
523:                            NameFactory.JCA_MANAGED_CONNECTION_FACTORY);
524:                    assertRunning(kernel, secondOutMCF);
525:
526:                    AbstractName secondConnectionManagerFactory = naming
527:                            .createChildName(secondOutMCF,
528:                                    "SecondTestOutboundConnectionFactory",
529:                                    NameFactory.JCA_CONNECTION_MANAGER);
530:                    assertRunning(kernel, secondConnectionManagerFactory);
531:
532:                    // ThirdTestOutboundConnectionFactory
533:                    AbstractName thirdOutCF = naming.createChildName(
534:                            jcaResourcejsr77Name,
535:                            "ThirdTestOutboundConnectionFactory",
536:                            NameFactory.JCA_CONNECTION_FACTORY);
537:                    assertRunning(kernel, thirdOutCF);
538:
539:                    AbstractName thirdOutMCF = naming.createChildName(
540:                            thirdOutCF, "ThirdTestOutboundConnectionFactory",
541:                            NameFactory.JCA_MANAGED_CONNECTION_FACTORY);
542:                    assertRunning(kernel, thirdOutMCF);
543:
544:                    AbstractName thirdConnectionManagerFactory = naming
545:                            .createChildName(thirdOutMCF,
546:                                    "ThirdTestOutboundConnectionFactory",
547:                                    NameFactory.JCA_CONNECTION_MANAGER);
548:                    assertRunning(kernel, thirdConnectionManagerFactory);
549:
550:                    // 1.5 only
551:                    //  Admin objects
552:                    //
553:
554:                    if (is15) {
555:                        AbstractName tweedledeeAdminObject = naming
556:                                .createChildName(jcaResourcejsr77Name,
557:                                        "tweedledee",
558:                                        NameFactory.JCA_ADMIN_OBJECT);
559:                        assertRunning(kernel, tweedledeeAdminObject);
560:
561:                        AbstractName tweedledumAdminObject = naming
562:                                .createChildName(jcaResourcejsr77Name,
563:                                        "tweedledum",
564:                                        NameFactory.JCA_ADMIN_OBJECT);
565:                        assertRunning(kernel, tweedledumAdminObject);
566:                    }
567:
568:                    configurationManager.stopConfiguration(configurationId);
569:                    configurationManager.unloadConfiguration(configurationId);
570:                } finally {
571:                    if (ds != null) {
572:                        Connection connection = ds.getConnection();
573:                        try {
574:                            Statement statement = connection.createStatement();
575:                            try {
576:                                statement.execute("SHUTDOWN");
577:                            } finally {
578:                                statement.close();
579:                            }
580:                        } finally {
581:                            connection.close();
582:                        }
583:                    }
584:
585:                    if (kernel != null) {
586:                        kernel.shutdown();
587:                    }
588:                    Thread.currentThread().setContextClassLoader(cl);
589:                }
590:            }
591:
592:            private void assertAttributeValue(Kernel kernel, AbstractName name,
593:                    String attributeName, String attributeValue)
594:                    throws Exception {
595:                Object value = kernel.getAttribute(name, attributeName);
596:                assertEquals(attributeValue, value);
597:            }
598:
599:            private void assertRunning(Kernel kernel, AbstractName name)
600:                    throws Exception {
601:                assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(name));
602:            }
603:
604:            protected void setUp() throws Exception {
605:                super .setUp();
606:                kernel = KernelFactory.newInstance().createKernel("test");
607:                kernel.boot();
608:
609:                ConfigurationData bootstrap = new ConfigurationData(bootId,
610:                        naming);
611:
612:                //        GBeanData artifactManagerData = bootstrap.addGBean("ArtifactManager", DefaultArtifactManager.GBEAN_INFO);
613:                //
614:                //        GBeanData artifactResolverData = bootstrap.addGBean("ArtifactResolver", DefaultArtifactResolver.GBEAN_INFO);
615:                //        artifactResolverData.setReferencePattern("ArtifactManager", artifactManagerData.getAbstractName());
616:                //
617:                //        GBeanData configurationManagerData = bootstrap.addGBean("ConfigurationManager", EditableKernelConfigurationManager.GBEAN_INFO);
618:                //        configurationManagerData.setReferencePattern("ArtifactManager", artifactManagerData.getAbstractName());
619:                //        configurationManagerData.setReferencePattern("ArtifactResolver", artifactResolverData.getAbstractName());
620:                //        bootstrap.addGBean(configurationManagerData);
621:                bootstrap.addGBean("ServerInfo", BasicServerInfo.GBEAN_INFO)
622:                        .setAttribute("baseDirectory", ".");
623:
624:                AbstractName repositoryName = bootstrap.addGBean("Repository",
625:                        MockRepository.GBEAN_INFO).getAbstractName();
626:
627:                AbstractName configStoreName = bootstrap.addGBean(
628:                        "MockConfigurationStore", MockConfigStore.GBEAN_INFO)
629:                        .getAbstractName();
630:
631:                GBeanData artifactManagerData = bootstrap.addGBean(
632:                        "ArtifactManager", DefaultArtifactManager.GBEAN_INFO);
633:
634:                GBeanData artifactResolverData = bootstrap.addGBean(
635:                        "ArtifactResolver", DefaultArtifactResolver.GBEAN_INFO);
636:                artifactResolverData.setReferencePattern("ArtifactManager",
637:                        artifactManagerData.getAbstractName());
638:
639:                GBeanData configurationManagerData = bootstrap.addGBean(
640:                        "ConfigurationManager",
641:                        EditableKernelConfigurationManager.GBEAN_INFO);
642:                configurationManagerData.setReferencePattern("ArtifactManager",
643:                        artifactManagerData.getAbstractName());
644:                configurationManagerData.setReferencePattern(
645:                        "ArtifactResolver", artifactResolverData
646:                                .getAbstractName());
647:                configurationManagerData.setReferencePattern("Stores",
648:                        configStoreName);
649:                configurationManagerData.setReferencePattern("Repositories",
650:                        repositoryName);
651:                bootstrap.addGBean(configurationManagerData);
652:
653:                GBeanData serverData = bootstrap.addGBean("geronimo",
654:                        J2EEServerImpl.GBEAN_INFO);
655:                serverName = serverData.getAbstractName();
656:                bootstrap.addGBean(serverData);
657:
658:                // add fake TransactionManager so refs will resolve
659:                GBeanData tm = bootstrap.addGBean("TransactionManager",
660:                        GeronimoTransactionManagerGBean.GBEAN_INFO);
661:                tm.setAttribute("defaultTransactionTimeoutSeconds", 10);
662:
663:                ConfigurationUtil.loadBootstrapConfiguration(kernel, bootstrap,
664:                        getClass().getClassLoader());
665:
666:                repository = (MockRepository) kernel.getGBean(repositoryName);
667:                Set<Artifact> repo = repository.getRepo();
668:                repo.add(Artifact
669:                        .create("org.apache.geronimo.tests/test/1/car"));
670:                repo.add(bootId);
671:
672:                configurationManager = ConfigurationUtil
673:                        .getEditableConfigurationManager(kernel);
674:                //        configurationManager.getConfiguration(bootstrap.getId());
675:                ConfigurationStore configStore = (ConfigurationStore) kernel
676:                        .getGBean(configStoreName);
677:                configStore.install(bootstrap);
678:
679:                defaultEnvironment = new Environment();
680:                defaultEnvironment.addDependency(bootstrap.getId(),
681:                        ImportType.ALL);
682:
683:            }
684:
685:            protected void tearDown() throws Exception {
686:                kernel.shutdown();
687:                super .tearDown();
688:            }
689:
690:            private abstract class InstallAction {
691:                public File getVendorDD() {
692:                    return null;
693:                }
694:
695:                public URL getSpecDD() throws MalformedURLException {
696:                    return null;
697:                }
698:
699:                public abstract File getRARFile();
700:
701:                public void install(ModuleBuilder moduleBuilder,
702:                        EARContext earContext, Module module,
703:                        ConfigurationStore configurationStore) throws Exception {
704:                    moduleBuilder.installModule(module.getModuleFile(),
705:                            earContext, module, Collections
706:                                    .singleton(configurationStore),
707:                            configurationStore, Collections
708:                                    .singleton(repository));
709:                }
710:            }
711:
712:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.