Source Code Cross Referenced for EarAssemblerTest.java in  » Portal » Pluto » org » apache » pluto » util » assemble » ear » 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 » Portal » Pluto » org.apache.pluto.util.assemble.ear 
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:         */
017:        package org.apache.pluto.util.assemble.ear;
018:
019:        import java.io.ByteArrayInputStream;
020:        import java.io.File;
021:        import java.io.FileInputStream;
022:        import java.util.jar.JarEntry;
023:        import java.util.jar.JarInputStream;
024:
025:        import org.apache.commons.io.FileUtils;
026:        import org.apache.commons.io.IOUtils;
027:        import org.apache.pluto.descriptors.portlet.PortletAppDD;
028:        import org.apache.pluto.descriptors.portlet.PortletDD;
029:        import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
030:        import org.apache.pluto.descriptors.services.WebAppDescriptorService;
031:        import org.apache.pluto.descriptors.services.castor.PortletAppDescriptorServiceImpl;
032:        import org.apache.pluto.descriptors.services.castor.WebAppDescriptorServiceImpl;
033:        import org.apache.pluto.descriptors.servlet.ServletDD;
034:        import org.apache.pluto.descriptors.servlet.WebAppDD;
035:        import org.apache.pluto.util.assemble.Assembler;
036:        import org.apache.pluto.util.assemble.AssemblerConfig;
037:        import org.apache.pluto.util.assemble.ArchiveBasedAssemblyTest;
038:
039:        /**
040:         * This test assembles an EAR file which contains a single portlet
041:         * web application for assembly.
042:         */
043:        public class EarAssemblerTest extends ArchiveBasedAssemblyTest {
044:
045:            private static final String earResource = "/org/apache/pluto/util/assemble/ear/EarDeployerTest.ear";
046:            private static final String testPortletName = "WarTestPortletName";
047:            private File earFile = null;
048:
049:            protected void setUp() throws Exception {
050:                super .setUp();
051:                this .earFile = new File(this .getClass()
052:                        .getResource(earResource).getFile());
053:            }
054:
055:            protected void tearDown() throws Exception {
056:                super .tearDown();
057:                this .earFile = null;
058:            }
059:
060:            public void testEarAssemblyToTempDir() throws Exception {
061:                AssemblerConfig config = new AssemblerConfig();
062:                config.setSource(earFile);
063:                File assembledEar = File.createTempFile(earFile.getName(),
064:                        ".ear");
065:                config.setDestination(assembledEar);
066:                EarAssembler assembler = new EarAssembler();
067:                assembler.assemble(config);
068:                validateEarAssembly(assembledEar);
069:                assembledEar.delete();
070:            }
071:
072:            public void testEarAssemblyInPlace() throws Exception {
073:                // copy the test ear file to a temp directory, so we don't overwrite the
074:                // test ear file distributed with Pluto.
075:                File inplaceEarFile = File.createTempFile(earFile.getName(),
076:                        ".ear");
077:                FileUtils.copyFile(earFile, inplaceEarFile);
078:
079:                AssemblerConfig config = new AssemblerConfig();
080:                config.setSource(inplaceEarFile);
081:                config.setDestination(inplaceEarFile);
082:                EarAssembler assembler = new EarAssembler();
083:                assembler.assemble(config);
084:                validateEarAssembly(inplaceEarFile);
085:
086:                inplaceEarFile.delete();
087:            }
088:
089:            protected void validateEarAssembly(File earFile) throws Exception {
090:                assertTrue("EAR archive [" + earFile.getAbsolutePath()
091:                        + "] cannot be found or cannot be read", earFile
092:                        .exists()
093:                        && earFile.canRead());
094:
095:                PortletAppDescriptorService portletSvc = new PortletAppDescriptorServiceImpl();
096:                WebAppDescriptorService webSvc = new WebAppDescriptorServiceImpl();
097:                PortletAppDD portletAppDD = null;
098:                WebAppDD webAppDD = null;
099:
100:                int earEntryCount = 0;
101:                int warEntryCount = 0;
102:
103:                JarInputStream earIn = new JarInputStream(new FileInputStream(
104:                        earFile));
105:
106:                JarEntry earEntry;
107:                JarEntry warEntry;
108:
109:                while ((earEntry = earIn.getNextJarEntry()) != null) {
110:                    earEntryCount++;
111:                    if (earEntry.getName().endsWith(".war")) {
112:                        warEntryCount++;
113:                        JarInputStream warIn = new JarInputStream(earIn);
114:                        while ((warEntry = warIn.getNextJarEntry()) != null) {
115:                            if (Assembler.PORTLET_XML
116:                                    .equals(warEntry.getName())) {
117:                                portletAppDD = portletSvc
118:                                        .read(new ByteArrayInputStream(IOUtils
119:                                                .toByteArray(warIn)));
120:                            }
121:                            if (Assembler.SERVLET_XML
122:                                    .equals(warEntry.getName())) {
123:                                webAppDD = webSvc
124:                                        .read(new ByteArrayInputStream(IOUtils
125:                                                .toByteArray(warIn)));
126:                            }
127:                        }
128:                    }
129:                }
130:
131:                assertTrue("EAR archive did not contain any entries",
132:                        earEntryCount > 0);
133:                assertTrue("WAR archive did not contain any entries",
134:                        warEntryCount > 0);
135:                assertNotNull("WAR archive did not contain a portlet.xml",
136:                        portletAppDD);
137:                assertNotNull("WAR archive did not contain a servlet.xml",
138:                        webAppDD);
139:                assertTrue("WAR archive did not contain any servlets", webAppDD
140:                        .getServlets().size() > 0);
141:                assertTrue("WAR archive did not contain any servlet mappings",
142:                        webAppDD.getServletMappings().size() > 0);
143:                assertTrue("WAR archive did not contain any portlets",
144:                        portletAppDD.getPortlets().size() > 0);
145:
146:                PortletDD portlet = (PortletDD) portletAppDD.getPortlets()
147:                        .iterator().next();
148:                assertEquals("Unexpected test portlet name.", testPortletName,
149:                        portlet.getPortletName());
150:
151:                ServletDD servlet = webAppDD.getServlet(testPortletName);
152:                assertNotNull(
153:                        "web.xml does not contain assembly for test portlet",
154:                        servlet);
155:                assertEquals(
156:                        "web.xml does not contain correct dispatch servet",
157:                        Assembler.DISPATCH_SERVLET_CLASS, servlet
158:                                .getServletClass());
159:
160:            }
161:
162:            protected Assembler getAssemblerUnderTest() {
163:                return new EarAssembler();
164:            }
165:
166:            protected File getFileToAssemble() {
167:                return earFile;
168:            }
169:
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.