Source Code Cross Referenced for DeploymentTestCase.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » 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 JBoss 4.2.1 » testsuite » org.jboss.test.deployment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.deployment;
023:
024:        import org.jboss.deployment.spi.DeploymentManagerImpl;
025:        import org.jboss.deployment.spi.DeploymentMetaData;
026:        import org.jboss.deployment.spi.JarUtils;
027:        import org.jboss.deployment.spi.TargetModuleIDImpl;
028:        import org.jboss.test.JBossTestCase;
029:        import org.jboss.util.UnreachableStatementException;
030:
031:        import javax.ejb.CreateException;
032:        import javax.enterprise.deploy.shared.ModuleType;
033:        import javax.enterprise.deploy.shared.StateType;
034:        import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
035:        import javax.enterprise.deploy.spi.DeploymentManager;
036:        import javax.enterprise.deploy.spi.Target;
037:        import javax.enterprise.deploy.spi.TargetModuleID;
038:        import javax.enterprise.deploy.spi.factories.DeploymentFactory;
039:        import javax.enterprise.deploy.spi.status.DeploymentStatus;
040:        import javax.enterprise.deploy.spi.status.ProgressObject;
041:        import javax.naming.InitialContext;
042:        import javax.naming.NamingException;
043:        import javax.rmi.PortableRemoteObject;
044:
045:        import java.io.BufferedReader;
046:        import java.io.ByteArrayInputStream;
047:        import java.io.File;
048:        import java.io.FileInputStream;
049:        import java.io.FileOutputStream;
050:        import java.io.IOException;
051:        import java.io.InputStreamReader;
052:        import java.net.URI;
053:        import java.net.URL;
054:        import java.rmi.RemoteException;
055:        import java.util.jar.JarOutputStream;
056:
057:        /** 
058:         * Deployment API JSR-88 tests
059:         *
060:         * @author Thomas.Diesler@jboss.org
061:         * @author Fabiano C. de Oliveira (JBAS-1995)
062:         * @version $Revision: 57211 $
063:         */
064:        public class DeploymentTestCase extends JBossTestCase {
065:            private static final String WAR_JBOSS_FILE = "WEB-INF/jboss-web.xml";
066:
067:            private static final String JAR_JBOSS_FILE = "META-INF/jboss.xml";
068:
069:            private static final String EAR_JBOSS_FILE = "META-INF/jboss-app.xml";
070:
071:            private DeploymentFactory factory;
072:
073:            public DeploymentTestCase(String name) {
074:                super (name);
075:            }
076:
077:            /** Get the DeploymentManager
078:             */
079:            protected void setUp() throws Exception {
080:                super .setUp();
081:                DeploymentFactoryManager dfManager = DeploymentFactoryManager
082:                        .getInstance();
083:                DeploymentFactory[] factories = dfManager
084:                        .getDeploymentFactories();
085:                assertTrue("No DeploymentFactory available",
086:                        factories.length > 0);
087:                factory = factories[0];
088:            }
089:
090:            /** Check DeploymentManager
091:             */
092:            public void testDeploymentManager() throws Exception {
093:                String uri = DeploymentManagerImpl.DEPLOYER_URI;
094:                DeploymentManager manager = factory.getDeploymentManager(uri,
095:                        null, null);
096:                assertNotNull("No deployment manager", manager);
097:
098:                Target target = manager.getTargets()[0];
099:                assertEquals("JBoss JMX deployment target", target
100:                        .getDescription());
101:            }
102:
103:            /** Distribute a web app
104:             */
105:            public void testDistributeWebApp() throws Exception {
106:                ProgressObject progress = jsr88Deployment("deployment-web.war");
107:                try {
108:                    assertServletAccess("custom-context");
109:                } finally {
110:                    jsr88Undeploy(progress.getResultTargetModuleIDs());
111:                }
112:                try {
113:                    assertServletAccess("custom-context");
114:                    fail("Test deployment not undeployed");
115:                } catch (IOException e) {
116:                    // ignore
117:                }
118:            }
119:
120:            /** 
121:             * Distribute a EJB app
122:             */
123:            public void testDistributeEjbApp() throws Exception {
124:                ProgressObject progress = jsr88Deployment("deployment-ejb.jar");
125:                try {
126:                    assertEjbEchoAccess();
127:                } finally {
128:                    jsr88Undeploy(progress.getResultTargetModuleIDs());
129:                }
130:                try {
131:                    assertEjbEchoAccess();
132:                    fail("Test deployment not undeployed");
133:                } catch (Exception e) {
134:                    // ignore
135:                }
136:            }
137:
138:            public void testDistributeEARApp() throws Exception {
139:                ProgressObject progress = jsr88Deployment("deployment-ear.ear");
140:                try {
141:                    assertServletAccess("custom-context");
142:                    assertEjbEchoAccess();
143:                } finally {
144:                    jsr88Undeploy(progress.getResultTargetModuleIDs());
145:                }
146:                try {
147:                    assertServletAccess("custom-context");
148:                    fail("Test deployment not undeployed");
149:                } catch (Exception e) {
150:                    // ignore
151:                }
152:
153:                try {
154:                    assertEjbEchoAccess();
155:                    fail("Test deployment not undeployed");
156:                } catch (Exception e) {
157:                    // ignore
158:                }
159:            }
160:
161:            /**
162:             * 
163:             * @throws Exception
164:             */
165:            public void testListStartStopModules() throws Exception {
166:                TargetModuleIDImpl child = null;
167:                TargetModuleIDImpl parent = null;
168:
169:                // Get the deployment manager and the distribution targets
170:                DeploymentManager manager = factory.getDeploymentManager(
171:                        DeploymentManagerImpl.DEPLOYER_URI, null, null);
172:                Target[] targets = manager.getTargets();
173:                assertEquals(1, targets.length);
174:
175:                TargetModuleID[] modules = manager.getRunningModules(
176:                        ModuleType.EAR, manager.getTargets());
177:                assertNull("no modules Available", modules);
178:
179:                ProgressObject parentProgress = jsr88Deployment("deployment-ear.ear");
180:                assertServletAccess("custom-context");
181:                assertEjbEchoAccess();
182:
183:                modules = manager.getRunningModules(ModuleType.EAR, manager
184:                        .getTargets());
185:                assertNotNull(modules);
186:                assertEquals("one EAR module in the server", modules.length, 1);
187:
188:                parent = (TargetModuleIDImpl) modules[0];
189:                assertTrue("wrong state", parent.isRunning());
190:                assertEquals("wrong type", parent.getModuleType(),
191:                        ModuleType.EAR);
192:                assertEquals("EAR module have a jar and a war", parent
193:                        .getChildTargetModuleID().length, 2);
194:
195:                child = (TargetModuleIDImpl) parent.getChildTargetModuleID()[0];
196:                assertTrue("wrong state", child.isRunning());
197:                assertTrue("wrong type", child.getModuleType().equals(
198:                        ModuleType.EJB)
199:                        || child.getModuleType().equals(ModuleType.WAR));
200:                assertEquals("child have no child", child
201:                        .getChildTargetModuleID().length, 0);
202:
203:                child = (TargetModuleIDImpl) parent.getChildTargetModuleID()[1];
204:                assertTrue("wrong state", child.isRunning());
205:                assertTrue("wrong type " + child.getModuleType(), child
206:                        .getModuleType().equals(ModuleType.EJB)
207:                        || child.getModuleType().equals(ModuleType.WAR));
208:                assertEquals("child have no child", child
209:                        .getChildTargetModuleID().length, 0);
210:
211:                parentProgress = manager.stop(new TargetModuleID[] { parent });
212:                waitForCompletion(parentProgress.getDeploymentStatus());
213:
214:                modules = manager.getNonRunningModules(ModuleType.EAR, manager
215:                        .getTargets());
216:                assertNotNull(modules);
217:                assertEquals("one EAR module in the server", modules.length, 1);
218:
219:                parent = (TargetModuleIDImpl) modules[0];
220:                assertFalse("wrong state", parent.isRunning());
221:                assertEquals("wrong type", parent.getModuleType(),
222:                        ModuleType.EAR);
223:                assertEquals("EAR module have a jar and a war", parent
224:                        .getChildTargetModuleID().length, 2);
225:
226:                parentProgress = manager.start(new TargetModuleID[] { parent });
227:                waitForCompletion(parentProgress.getDeploymentStatus());
228:
229:                modules = manager.getRunningModules(ModuleType.EAR, manager
230:                        .getTargets());
231:                assertNotNull(modules);
232:                assertEquals("one EAR module in the server", modules.length, 1);
233:
234:                parent = (TargetModuleIDImpl) modules[0];
235:                assertTrue("wrong state", parent.isRunning());
236:                assertEquals("wrong type", parent.getModuleType(),
237:                        ModuleType.EAR);
238:                assertEquals("EAR module have a jar and a war", parent
239:                        .getChildTargetModuleID().length, 2);
240:                parentProgress = manager
241:                        .undeploy(new TargetModuleID[] { parent });
242:                waitForCompletion(parentProgress.getDeploymentStatus());
243:
244:                modules = manager.getAvailableModules(ModuleType.EAR, manager
245:                        .getTargets());
246:                assertNull("EAR must not be available", modules);
247:
248:                try {
249:                    assertServletAccess("custom-context");
250:                    fail("Test deployment not undeployed");
251:                } catch (Exception e) {
252:                    // ignore
253:                }
254:
255:                try {
256:                    assertEjbEchoAccess();
257:                    fail("Test deployment not undeployed");
258:                } catch (Exception e) {
259:                    // ignore
260:                }
261:            }
262:
263:            private void jsr88Undeploy(TargetModuleID[] resultTargetModuleIDs)
264:                    throws Exception {
265:                // Get the deployment manager and the distribution targets
266:                DeploymentManager manager = factory.getDeploymentManager(
267:                        DeploymentManagerImpl.DEPLOYER_URI, null, null);
268:                Target[] targets = manager.getTargets();
269:                assertEquals(1, targets.length);
270:
271:                ProgressObject progress = manager.stop(resultTargetModuleIDs);
272:                DeploymentStatus status = progress.getDeploymentStatus();
273:                waitForCompletion(status);
274:
275:                // Check the webapp is undeployed
276:                assertEquals(status.getMessage(), StateType.COMPLETED, status
277:                        .getState());
278:
279:                progress = manager.undeploy(resultTargetModuleIDs);
280:                status = progress.getDeploymentStatus();
281:                waitForCompletion(status);
282:                assertEquals(status.getMessage(), StateType.COMPLETED, status
283:                        .getState());
284:            }
285:
286:            private ProgressObject jsr88Deployment(String module)
287:                    throws Exception {
288:                // Get the deployment manager and the distribution targets
289:                DeploymentManager manager = factory.getDeploymentManager(
290:                        DeploymentManagerImpl.DEPLOYER_URI, null, null);
291:                Target[] targets = manager.getTargets();
292:                assertEquals(1, targets.length);
293:
294:                File deploymentPlan = createDeploymentPlan(module);
295:
296:                // Get a pointer to the plain web archive
297:                log.debug("module=" + module);
298:                File moduleArchive = new File(new URI(getDeployURL(module)
299:                        .toString()));
300:                assertTrue(moduleArchive.exists());
301:
302:                // Deploy the test war
303:                ProgressObject progress = manager.distribute(targets,
304:                        moduleArchive, deploymentPlan);
305:                DeploymentStatus status = progress.getDeploymentStatus();
306:                waitForCompletion(status);
307:
308:                assertEquals(status.getMessage(), StateType.COMPLETED, status
309:                        .getState());
310:
311:                TargetModuleID[] moduleIDs = progress
312:                        .getResultTargetModuleIDs();
313:                progress = manager.start(moduleIDs);
314:                status = progress.getDeploymentStatus();
315:                waitForCompletion(status);
316:
317:                return progress;
318:            }
319:
320:            private void assertEjbEchoAccess() throws NamingException,
321:                    RemoteException, CreateException {
322:                InitialContext initial = new InitialContext();
323:                Object obj = initial.lookup("deployment/test/Echo");
324:                EchoHome home = (EchoHome) PortableRemoteObject.narrow(obj,
325:                        EchoHome.class);
326:                Echo echo = home.create();
327:
328:                assertEquals("Wrong EJB return", "Hello!", echo.echo("Hello!"));
329:            }
330:
331:            private void waitForCompletion(DeploymentStatus status)
332:                    throws InterruptedException {
333:                // wait for the deployment to finish
334:                while (StateType.RUNNING == status.getState())
335:                    Thread.sleep(100);
336:            }
337:
338:            private void assertServletAccess(String context) throws IOException {
339:                // Check that we can access the servlet
340:                URL servletURL = new URL("http://" + getServerHost() + ":8080/"
341:                        + context);
342:                BufferedReader br = new BufferedReader(new InputStreamReader(
343:                        servletURL.openStream()));
344:                String message = br.readLine();
345:                assertEquals("Hello World!", message);
346:            }
347:
348:            private File createDeploymentPlan(String deploymentFile)
349:                    throws Exception {
350:                String[] strs = null;
351:
352:                // Create temp file for deployment plan
353:                File deploymentPlan = File.createTempFile("deploymentplan",
354:                        ".zip");
355:                deploymentPlan.deleteOnExit();
356:
357:                String jbossFile = getJBossFile(deploymentFile);
358:                String resourcedir = getResourceURL("deployment/" + jbossFile);
359:                File jbossDescriptor = new File(new URI(resourcedir));
360:                assertTrue(jbossDescriptor.exists());
361:
362:                JarOutputStream jos = new JarOutputStream(new FileOutputStream(
363:                        deploymentPlan));
364:                JarUtils.addJarEntry(jos, "!/" + jbossFile,
365:                        new FileInputStream(jbossDescriptor));
366:
367:                // Setup deployment plan meta data with propriatary descriptor
368:                DeploymentMetaData metaData = new DeploymentMetaData(
369:                        deploymentFile);
370:
371:                strs = jbossFile.split("/");
372:                metaData.addEntry(deploymentFile, strs[strs.length - 1]);
373:
374:                // Add the meta data to the deployment plan
375:                String metaStr = metaData.toXMLString();
376:
377:                JarUtils.addJarEntry(jos, DeploymentMetaData.ENTRY_NAME,
378:                        new ByteArrayInputStream(metaStr.getBytes()));
379:                jos.flush();
380:                jos.close();
381:
382:                return deploymentPlan;
383:            }
384:
385:            private String getJBossFile(String deploymentFile) {
386:                if (deploymentFile.endsWith(".war"))
387:                    return WAR_JBOSS_FILE;
388:                else if (deploymentFile.endsWith(".jar"))
389:                    return JAR_JBOSS_FILE;
390:                else if (deploymentFile.endsWith(".ear"))
391:                    return EAR_JBOSS_FILE;
392:                else
393:                    fail("Wrong J2EE Module found...");
394:                throw new UnreachableStatementException();
395:            }
396:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.