portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r535741 [2/2] - in /portals/pluto/trunk: maven-pluto-plugin/src/main/java/org/apache/pluto/maven/ pluto-ant-tasks/src/main/java/org/apache/pluto/ant/ pluto-util/src/main/java/org/apache/pluto/util/assemble/ pluto-util/src/main/java/org/apac...
Date Mon, 07 May 2007 04:55:40 GMT
Modified: portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/assemble/war/WarAssembler.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/assemble/war/WarAssembler.java?view=diff&rev=535741&r1=535740&r2=535741
==============================================================================
--- portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/assemble/war/WarAssembler.java
(original)
+++ portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/assemble/war/WarAssembler.java
Sun May  6 21:55:37 2007
@@ -16,33 +16,25 @@
  */
 package org.apache.pluto.util.assemble.war;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
-import java.util.zip.CRC32;
-import java.util.zip.ZipEntry;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.pluto.util.UtilityException;
+import org.apache.pluto.util.assemble.AbstractArchiveAssembler;
 import org.apache.pluto.util.assemble.AssemblerConfig;
-import org.apache.pluto.util.assemble.WebXmlRewritingAssembler;
+import org.apache.pluto.util.assemble.io.JarStreamingAssembly;
 
 /**
  *
  * @version 1.0
  * @since Nov 8, 2004
  */
-public class WarAssembler extends WebXmlRewritingAssembler {
+public class WarAssembler extends AbstractArchiveAssembler {
     // Constructor -------------------------------------------------------------
 
     /**
@@ -55,28 +47,11 @@
 
     // Assembler Impl ----------------------------------------------------------
 
-    public void assemble(AssemblerConfig config) throws UtilityException {
-        try {
-            final File sourceArchive = config.getWarSource();
-            final File destinationFolder = config.getDestination();
-            final File destinationArchive = new File(destinationFolder, sourceArchive.getName());
-
-            //If the source and dest are the same a temp location is needed
-            if (sourceArchive.equals(destinationArchive)) {
-                final File tempArchive = File.createTempFile(sourceArchive.getName() + ".",
".tmp");
-                this.assembleWar(sourceArchive, tempArchive, config.getDispatchServletClass());
-
-                //Move the temp file to the destination location
-                destinationArchive.delete();
-                tempArchive.renameTo(destinationArchive);
-            }
-            else {
-                this.assembleWar(sourceArchive, destinationArchive, config.getDispatchServletClass());
-            }
-
-        } catch (IOException ex) {
-            throw new UtilityException(ex.getMessage(), ex, null);
-        }
+    public void assembleInternal(AssemblerConfig config) 
+        throws UtilityException, IOException {
+        
+        this.assembleWar(config.getSource(), config.getDestination(), config.getDispatchServletClass());
+        
     }
 
     /**
@@ -86,98 +61,18 @@
      */
     protected void assembleWar(File source, File dest, String dispatchServletClass) throws
IOException {
         final JarInputStream jarIn = new JarInputStream(new FileInputStream(source));
-
-        try {
-            //Create the output JAR stream, copying the Manifest
-            final Manifest manifest = jarIn.getManifest();
-            //TODO add pluto notes to the Manifest?
-            FileUtils.forceMkdir(dest.getParentFile());
-            final JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(dest),
manifest);
-
-            try {
-                //Need to buffer the web.xml and portlet.xml files for the rewritting
-                JarEntry servletXmlEntry = null;
-                byte[] servletXmlBuffer = null;
-                byte[] portletXmlBuffer = null;
-
-                //Read the source archive entry by entry
-                JarEntry originalJarEntry;
-                while ((originalJarEntry = jarIn.getNextJarEntry()) != null) {
-                    final JarEntry newJarEntry = this.smartClone(originalJarEntry);
-
-                    //Capture the web.xml JarEntry and contents as a byte[], don't write
it out now
-                    if (SERVLET_XML.equals(newJarEntry.getName())) {
-                        servletXmlEntry = newJarEntry;
-                        servletXmlBuffer = IOUtils.toByteArray(jarIn);
-                    }
-                    //Capture the portlet.xml contents as a byte[]
-                    else if (PORTLET_XML.equals(newJarEntry.getName())) {
-                        portletXmlBuffer = IOUtils.toByteArray(jarIn);
-                        jarOut.putNextEntry(newJarEntry);
-                        IOUtils.write(portletXmlBuffer, jarOut);
-                    }
-                    //Copy all other entries directly to the output archive
-                    else {
-                        jarOut.putNextEntry(newJarEntry);
-                        IOUtils.copy(jarIn, jarOut);
-                    }
-                }
-
-                //Checks to make sure the web.xml and portlet.xml were found
-                if (servletXmlBuffer == null) {
-                    throw new FileNotFoundException("File '" + SERVLET_XML + "' could not
be found in the archive '" + source + "'");
-                }
-                if (portletXmlBuffer == null) {
-                    throw new FileNotFoundException("File '" + PORTLET_XML + "' could not
be found in the archive '" + source + "'");
-                }
-
-                //Create streams of the byte[] data for the updater method
-                final InputStream webXmlIn = new ByteArrayInputStream(servletXmlBuffer);
-                final InputStream portletXmlIn = new ByteArrayInputStream(portletXmlBuffer);
-                final ByteArrayOutputStream webXmlOut = new ByteArrayOutputStream(servletXmlBuffer.length);
-
-                //Update the web.xml
-                this.updateWebappDescriptor(webXmlIn, portletXmlIn, webXmlOut, dispatchServletClass);
-                final byte[] webXmlBytes = webXmlOut.toByteArray();
-
-                //If no compression is being used (STORED) we have to manually update the
size and crc
-                if (servletXmlEntry.getMethod() == ZipEntry.STORED) {
-                    servletXmlEntry.setSize(webXmlBytes.length);
-
-                    final CRC32 webXmlCrc = new CRC32();
-                    webXmlCrc.update(webXmlBytes);
-                    servletXmlEntry.setCrc(webXmlCrc.getValue());
-                }
-
-                //write out the web.xml entry and contents
-                jarOut.putNextEntry(servletXmlEntry);
-                IOUtils.write(webXmlBytes, jarOut);
-            }
-            finally {
-                jarOut.flush();
-                jarOut.close();
-            }
-        }
-        finally {
+        //Create the output JAR stream, copying the Manifest
+        final Manifest manifest = jarIn.getManifest();
+        //TODO add pluto notes to the Manifest?
+        final JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(dest), manifest);
+        
+        try {            
+            JarStreamingAssembly.assembleStream(jarIn, jarOut, dispatchServletClass);
+        } finally {
             jarIn.close();
+            jarOut.close();
         }
     }
 
-
-    private JarEntry smartClone(JarEntry originalJarEntry) {
-        final JarEntry newJarEntry = new JarEntry(originalJarEntry.getName());
-        newJarEntry.setComment(originalJarEntry.getComment());
-        newJarEntry.setExtra(originalJarEntry.getExtra());
-        newJarEntry.setMethod(originalJarEntry.getMethod());
-        newJarEntry.setTime(originalJarEntry.getTime());
-
-        //Must set size and CRC for STORED entries
-        if (newJarEntry.getMethod() == ZipEntry.STORED) {
-            newJarEntry.setSize(originalJarEntry.getSize());
-            newJarEntry.setCrc(originalJarEntry.getCrc());
-        }
-
-        return newJarEntry;
-    }
 }
 

Added: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java?view=auto&rev=535741
==============================================================================
--- portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java
(added)
+++ portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java
Sun May  6 21:55:37 2007
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.util.assemble;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Common base test class that should be used by assembler implementations that
+ * work with files using jar packaging (war, ear, etc.).
+ * 
+ * This test ensures consistent behaviour across assembler implementations.
+ */
+public abstract class ArchiveBasedAssemblyTest extends TestCase {
+
+    private static final Log LOG = LogFactory.getLog( ArchiveBasedAssemblyTest.class );
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+    
+    /**
+     * Obtain the Assembler implementation from the subclass used
+     * to assemble the archive.
+     * @return the Assembler
+     */
+    protected abstract Assembler getAssemblerUnderTest();
+    
+    /**
+     * Obtain the archive (war, ear) to assemble from the subclass.
+     * @return the archive to assemble.
+     */
+    protected abstract File getFileToAssemble();
+    
+    public void testAssembleToNonExistantFile() throws Exception {
+        File fileToAssemble = getFileToAssemble();
+        Assembler underTest = getAssemblerUnderTest();        
+        File destFile = File.createTempFile( "jarAssemblyTest", ".tmp" );
+        destFile.delete();
+
+        assertFalse( "Destination file [" + destFile.getAbsolutePath() + "] already exists.",

+                destFile.exists() );
+        
+        AssemblerConfig config = prepareConfig( fileToAssemble, destFile );
+        
+        LOG.debug( "Assembling [" + fileToAssemble.getAbsolutePath() + 
+                "] to file [" + destFile.getAbsolutePath() + "]" );
+        
+        underTest.assemble( config );
+        
+        assertTrue( "Source archive [" + fileToAssemble.getAbsolutePath() + "] doesn't exist!
" +  
+                "Assembly may have deleted it by accident.", fileToAssemble.exists() );
+        assertTrue( "Destination directory [" + destFile.getParentFile().getAbsolutePath()
+ "] does not exist, " +
+                "assembly did not complete properly.", destFile.getParentFile().exists()
);
+        assertTrue( "Assembled war file [" + destFile + "] does not exist, " +
+                "assembly did not complete properly.", destFile.exists() );
+        
+        destFile.delete();
+    }
+    
+    public void testAssembleToDirectory() throws Exception {
+        File fileToAssemble = getFileToAssemble();
+        Assembler underTest = getAssemblerUnderTest();
+        
+        File tmpFile = File.createTempFile( "jarAssemblyTest", ".tmp" );
+        File destDir = new File( tmpFile.getParent(), tmpFile.getName() + ".dir" );
+        destDir.mkdir();
+        
+        assertTrue( "Destination directory [" + destDir.getAbsolutePath() + "] doesn't exist.",

+                destDir.exists() );
+        
+        AssemblerConfig config = prepareConfig( fileToAssemble, destDir );
+        
+        LOG.debug( "Assembling [" + fileToAssemble.getAbsolutePath() + 
+                "] to directory [" + destDir.getAbsolutePath() + "]" );
+        
+        underTest.assemble( config );
+        
+        File destFile = new File( destDir, fileToAssemble.getName() );
+        
+        assertTrue( "Source archive doesn't exist!  Assembly may have deleted it by accident.",
fileToAssemble.exists() );
+        assertTrue( "Destination directory does not exist, assembly did not complete properly.",
destDir.exists() );
+        assertTrue( "Assembled war file does not exist, assembly did not complete properly.",
destFile.exists() );
+        
+        destFile.delete();
+        destDir.delete();
+    }
+    
+    public void testAssembleToExistingFile() throws Exception {
+        File fileToAssemble = getFileToAssemble();
+        Assembler underTest = getAssemblerUnderTest();
+        
+        File destFile = File.createTempFile( "jarAssemblyTest", ".tmp" );
+        
+        assertTrue( "Destination file [" + destFile.getAbsolutePath() + "] should already
exist.", 
+                destFile.exists() );
+        
+        AssemblerConfig config = prepareConfig( fileToAssemble, destFile );
+        
+        LOG.debug( "Assembling [" + fileToAssemble.getAbsolutePath() + "] to file [" + destFile.getAbsolutePath()
+ "]" );
+        
+        underTest.assemble( config );
+        
+        assertTrue( "Source archive doesn't exist!  Assembly may have deleted it by accident.",
fileToAssemble.exists() );
+        assertTrue( "Assembled war file does not exist, assembly did not complete properly.",
destFile.exists() );
+        
+        destFile.delete();        
+    }
+    
+    public void testAssembleToExistingFileInSubDirectory() throws Exception {
+        File fileToAssemble = getFileToAssemble();
+        Assembler underTest = getAssemblerUnderTest();
+        
+        File tmpFile = File.createTempFile( "jarAssemblyTest", ".tmp" );
+        File destDir = new File( tmpFile.getName() + ".dir" );
+        destDir.mkdirs();
+        File destFile = new File( destDir, fileToAssemble.getName() );
+        destFile.createNewFile();
+        
+        assertTrue( "Destination file [" + destFile.getAbsolutePath() + "] should already
exist.", 
+                destFile.exists() );
+        
+        AssemblerConfig config = prepareConfig( fileToAssemble, destFile );
+        
+        LOG.debug( "Assembling [" + fileToAssemble.getAbsolutePath() + "] to file [" + destFile.getAbsolutePath()
+ "]" );
+        
+        underTest.assemble( config );
+        
+        assertTrue( "Source archive doesn't exist!  Assembly may have deleted it by accident.",
fileToAssemble.exists() );
+        assertTrue( "Assembled war file does not exist, assembly did not complete properly.",
destFile.exists() );
+        
+        destFile.delete();
+        destDir.delete();
+        tmpFile.delete();
+    }
+    
+    private AssemblerConfig prepareConfig( File source, File dest ) {
+        AssemblerConfig config = new AssemblerConfig();
+        config.setDestination( dest );
+        config.setSource( source );
+        return config;
+    }
+    
+}

Propchange: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java?view=auto&rev=535741
==============================================================================
--- portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java
(added)
+++ portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java
Sun May  6 21:55:37 2007
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.util.assemble.ear;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.descriptors.portlet.PortletDD;
+import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
+import org.apache.pluto.descriptors.services.WebAppDescriptorService;
+import org.apache.pluto.descriptors.services.castor.PortletAppDescriptorServiceImpl;
+import org.apache.pluto.descriptors.services.castor.WebAppDescriptorServiceImpl;
+import org.apache.pluto.descriptors.servlet.ServletDD;
+import org.apache.pluto.descriptors.servlet.WebAppDD;
+import org.apache.pluto.util.assemble.Assembler;
+import org.apache.pluto.util.assemble.AssemblerConfig;
+import org.apache.pluto.util.assemble.ArchiveBasedAssemblyTest;
+
+/**
+ * This test assembles an EAR file which contains two portlet
+ * web applications for assembly.  There is a third war file
+ * which is not a portlet, and therefore shouldn't be assembled, 
+ * just copied.
+ */
+public class ComplexEarAssemblerTest extends ArchiveBasedAssemblyTest {
+    
+    private static final String earResource = 
+        "/org/apache/pluto/util/assemble/ear/ComplexEarDeployerTest.ear";
+    
+    private static final String[] testPortletNames;
+    private static final String[] testWarEntryNames;
+    private static final String[] unassembledWarEntryName;
+    static {
+        testPortletNames = new String[] { "WarTestPortletName", "SecondWarTestPortletName"
};
+        testWarEntryNames = new String[] { "WarDeployerTestPortlet.war", "SecondWarDeployerTestPortlet.war"
};
+        unassembledWarEntryName = new String[] { "WarWithNoPortlet.war" };
+    }
+    
+    private File earFile = null;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        earFile = new File( getClass().getResource( earResource ).getFile() );
+    }
+    
+    public void testMultipleWarFileAssembly() throws Exception {
+        File tmpFile = File.createTempFile( "earTest", "tmp" );
+        File destDir = new File( tmpFile.getName() + ".dir" );
+        destDir.mkdirs();
+        
+        assertTrue( "Source ear file doesn't exist! [" + earFile + "]", earFile.exists()
);
+        assertTrue( "Destination directory doesn't exist! [" + destDir + "]", 
+                destDir.exists() && destDir.isDirectory() );
+        
+        AssemblerConfig config = new AssemblerConfig();
+        config.setSource( earFile );
+        config.setDestination( destDir );
+        EarAssembler assembler = new EarAssembler();
+        
+        assembler.assemble( config );
+        
+        File destFile = new File( destDir, earFile.getName() );
+        
+        assertTrue( "Assembled ear file doesn't exist, assembly failed", destFile.exists()
);
+        
+        validateEarAssembly( destFile );
+        
+        tmpFile.delete();
+        destFile.delete();
+        destDir.delete();
+    }
+    
+    protected void validateEarAssembly( File earFile ) throws Exception {
+        assertTrue( "EAR archive [" + earFile.getAbsolutePath() + "] cannot be found or cannot
be read", 
+                earFile.exists() && earFile.canRead() );
+        
+        PortletAppDescriptorService portletSvc = new PortletAppDescriptorServiceImpl();
+        WebAppDescriptorService webSvc = new WebAppDescriptorServiceImpl();
+        PortletAppDD portletAppDD = null;
+        WebAppDD webAppDD = null;
+        
+        List portletWarEntries = Arrays.asList( testWarEntryNames );
+        List unassembledWarEntries = Arrays.asList( unassembledWarEntryName );
+        List testPortlets = Arrays.asList( testPortletNames );
+        
+        int earEntryCount = 0;
+        int totalWarEntryCount = 0;
+        int portletWarEntryCount = 0;
+        
+        JarInputStream earIn = new JarInputStream( new FileInputStream( earFile ) );
+        
+        JarEntry earEntry;
+        JarEntry warEntry;
+        
+        
+        while ( ( earEntry = earIn.getNextJarEntry() ) != null ) {            
+            earEntryCount++;
+            
+            if ( earEntry.getName().endsWith( ".war" ) ) {
+                totalWarEntryCount++;
+                JarInputStream warIn = new JarInputStream( earIn );
+                
+                while ( ( warEntry = warIn.getNextJarEntry() ) != null ) {
+                    if ( Assembler.PORTLET_XML.equals( warEntry.getName() ) ) {
+                        portletAppDD = portletSvc.read( 
+                                new ByteArrayInputStream( IOUtils.toByteArray( warIn ) )
);
+                    }
+                    if ( Assembler.SERVLET_XML.equals( warEntry.getName() ) ) {
+                        webAppDD = webSvc.read( 
+                                new ByteArrayInputStream( IOUtils.toByteArray( warIn ) )
);
+                    }
+                }
+                
+                if ( portletWarEntries.contains( earEntry.getName() ) ) {
+                    portletWarEntryCount++;
+                    assertNotNull( "WAR archive did not contain a portlet.xml", portletAppDD
);
+                    assertNotNull( "WAR archive did not contain a servlet.xml", webAppDD
);
+                    assertTrue( "WAR archive did not contain any servlets", webAppDD.getServlets().size()
> 0 );
+                    assertTrue( "WAR archive did not contain any servlet mappings", webAppDD.getServletMappings().size()
> 0 );
+                    assertTrue( "WAR archive did not contain any portlets", portletAppDD.getPortlets().size()
> 0 );
+                    
+                    for ( Iterator iter = portletAppDD.getPortlets().iterator(); iter.hasNext();
) {
+                        PortletDD portlet = (PortletDD) iter.next();
+                        if (! testPortlets.contains( portlet.getPortletName() ) ) {
+                            fail( "Unexpected test portlet name encountered: [" + portlet.getPortletName()
+ "]" );
+                        }
+                        ServletDD servlet = webAppDD.getServlet( portlet.getPortletName()
);
+                        assertNotNull( "web.xml does not contain assembly for test portlet",
servlet );
+                        assertEquals( "web.xml does not contain correct dispatch servet",
Assembler.DISPATCH_SERVLET_CLASS, 
+                                servlet.getServletClass() );
+                    } 
+                    
+                }
+                
+                webAppDD = null;
+                portletAppDD = null;
+                                
+            }
+            
+        }
+        
+        assertTrue( "EAR archive did not contain any entries", earEntryCount > 0 );
+        assertEquals( "EAR archive did not contain the expected test war entries.", portletWarEntries.size(),
portletWarEntryCount );
+        assertEquals( "WAR archive did not contain the correct number of entries",
+                portletWarEntries.size() + unassembledWarEntries.size(), totalWarEntryCount
);
+                            
+    }
+
+    protected Assembler getAssemblerUnderTest() {
+        return new EarAssembler();
+    }
+
+    protected File getFileToAssemble() {
+        return earFile;
+    }
+
+}

Propchange: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java?view=auto&rev=535741
==============================================================================
--- portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java
(added)
+++ portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java
Sun May  6 21:55:37 2007
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.util.assemble.ear;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.descriptors.portlet.PortletDD;
+import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
+import org.apache.pluto.descriptors.services.WebAppDescriptorService;
+import org.apache.pluto.descriptors.services.castor.PortletAppDescriptorServiceImpl;
+import org.apache.pluto.descriptors.services.castor.WebAppDescriptorServiceImpl;
+import org.apache.pluto.descriptors.servlet.ServletDD;
+import org.apache.pluto.descriptors.servlet.WebAppDD;
+import org.apache.pluto.util.assemble.Assembler;
+import org.apache.pluto.util.assemble.AssemblerConfig;
+import org.apache.pluto.util.assemble.ArchiveBasedAssemblyTest;
+
+/**
+ * This test assembles an EAR file which contains a single portlet
+ * web application for assembly.
+ */
+public class EarAssemblerTest extends ArchiveBasedAssemblyTest {
+
+    private static final String earResource = "/org/apache/pluto/util/assemble/ear/EarDeployerTest.ear";
+    private static final String testPortletName = "WarTestPortletName";
+    private File earFile = null;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        this.earFile = new File( this.getClass().getResource( earResource ).getFile() );
+    }
+    
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        this.earFile = null;
+    }
+    
+    public void testEarAssemblyToTempDir() throws Exception {
+        AssemblerConfig config = new AssemblerConfig();
+        config.setSource( earFile );
+        File assembledEar = File.createTempFile( earFile.getName(), ".ear" ); 
+        config.setDestination( assembledEar );
+        EarAssembler assembler = new EarAssembler();
+        assembler.assemble( config );
+        validateEarAssembly( assembledEar );
+        assembledEar.delete();
+    }
+    
+    public void testEarAssemblyInPlace() throws Exception {
+        // copy the test ear file to a temp directory, so we don't overwrite the
+        // test ear file distributed with Pluto.
+        File inplaceEarFile = File.createTempFile( earFile.getName(), ".ear" );
+        FileUtils.copyFile( earFile, inplaceEarFile );
+        
+        AssemblerConfig config = new AssemblerConfig();
+        config.setSource( inplaceEarFile );
+        config.setDestination( inplaceEarFile );
+        EarAssembler assembler = new EarAssembler();
+        assembler.assemble( config );
+        validateEarAssembly( inplaceEarFile );
+        
+        inplaceEarFile.delete();        
+    }
+    
+    protected void validateEarAssembly( File earFile ) throws Exception {
+        assertTrue( "EAR archive [" + earFile.getAbsolutePath() + "] cannot be found or cannot
be read", 
+                earFile.exists() && earFile.canRead() );
+        
+        PortletAppDescriptorService portletSvc = new PortletAppDescriptorServiceImpl();
+        WebAppDescriptorService webSvc = new WebAppDescriptorServiceImpl();
+        PortletAppDD portletAppDD = null;
+        WebAppDD webAppDD = null;
+        
+        int earEntryCount = 0;
+        int warEntryCount = 0;
+        
+        JarInputStream earIn = new JarInputStream( new FileInputStream( earFile ) );
+        
+        JarEntry earEntry;
+        JarEntry warEntry;
+        
+        while ( ( earEntry = earIn.getNextJarEntry() ) != null ) {
+            earEntryCount++;
+            if ( earEntry.getName().endsWith( ".war" ) ) {
+                warEntryCount++;
+                JarInputStream warIn = new JarInputStream( earIn );
+                while ( ( warEntry = warIn.getNextJarEntry() ) != null ) {
+                    if ( Assembler.PORTLET_XML.equals( warEntry.getName() ) ) {
+                        portletAppDD = portletSvc.read( 
+                                new ByteArrayInputStream( IOUtils.toByteArray( warIn ) )
);
+                    }
+                    if ( Assembler.SERVLET_XML.equals( warEntry.getName() ) ) {
+                        webAppDD = webSvc.read( 
+                                new ByteArrayInputStream( IOUtils.toByteArray( warIn ) )
);
+                    }
+                }                
+            }
+        }
+        
+        assertTrue( "EAR archive did not contain any entries", earEntryCount > 0 );
+        assertTrue( "WAR archive did not contain any entries", warEntryCount > 0 );
+        assertNotNull( "WAR archive did not contain a portlet.xml", portletAppDD );
+        assertNotNull( "WAR archive did not contain a servlet.xml", webAppDD );
+        assertTrue( "WAR archive did not contain any servlets", webAppDD.getServlets().size()
> 0 );
+        assertTrue( "WAR archive did not contain any servlet mappings", webAppDD.getServletMappings().size()
> 0 );
+        assertTrue( "WAR archive did not contain any portlets", portletAppDD.getPortlets().size()
> 0 );
+        
+        PortletDD portlet = (PortletDD) portletAppDD.getPortlets().iterator().next();
+        assertEquals( "Unexpected test portlet name.", testPortletName, portlet.getPortletName()
);
+        
+        ServletDD servlet = webAppDD.getServlet( testPortletName );
+        assertNotNull( "web.xml does not contain assembly for test portlet", servlet );
+        assertEquals( "web.xml does not contain correct dispatch servet", Assembler.DISPATCH_SERVLET_CLASS,

+                servlet.getServletClass() );
+                
+    }
+
+    protected Assembler getAssemblerUnderTest() {
+        return new EarAssembler();
+    }
+
+    protected File getFileToAssemble() {
+        return earFile;
+    }
+    
+}

Propchange: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java?view=auto&rev=535741
==============================================================================
--- portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java
(added)
+++ portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java
Sun May  6 21:55:37 2007
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.util.assemble.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.descriptors.portlet.PortletDD;
+import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
+import org.apache.pluto.descriptors.services.WebAppDescriptorService;
+import org.apache.pluto.descriptors.services.castor.PortletAppDescriptorServiceImpl;
+import org.apache.pluto.descriptors.services.castor.WebAppDescriptorServiceImpl;
+import org.apache.pluto.descriptors.servlet.ServletDD;
+import org.apache.pluto.descriptors.servlet.WebAppDD;
+import org.apache.pluto.util.assemble.Assembler;
+
+/**
+ * This test class directly tests the Jar streaming assembly,
+ * bypassing the file assemblers (EarAssembler, WarAssembler).
+ */
+public class AssemblyStreamTest extends TestCase {
+    
+    private InputStream webXmlIn = null;
+    private InputStream portletXmlIn = null;    
+    private InputStream warIn = null;
+    private JarStreamingAssembly jarAssemblerUnderTest = null;
+    private WebXmlStreamingAssembly webXmlAssemblerUnderTest = null;
+    
+    private static final String webXmlToAssembleResource = "/org/apache/pluto/util/assemble/file/web.xml";
+    private static final String portletXmlResource = "/org/apache/pluto/util/assemble/file/portlet.xml";
+    private static final String warToAssembleResource = "/org/apache/pluto/util/assemble/war/WarDeployerTestPortlet.war";
+    
+    private static final String testPortletName = "WarTestPortletName";    
+    
+    protected void setUp() throws Exception {
+        webXmlIn = getClass().getResourceAsStream( webXmlToAssembleResource );
+        portletXmlIn = getClass().getResourceAsStream( portletXmlResource );
+        warIn = getClass().getResourceAsStream( warToAssembleResource );
+        jarAssemblerUnderTest = new JarStreamingAssembly();
+        webXmlAssemblerUnderTest = new WebXmlStreamingAssembly();
+    }
+    
+    public void testJarStreamingAssembly() throws Exception {
+        File warFileOut = File.createTempFile( "streamingAssemblyWarTest", ".war" );
+        JarInputStream jarIn = new JarInputStream( warIn );
+        JarOutputStream warOut = new JarOutputStream( new FileOutputStream( warFileOut )
);
+        jarAssemblerUnderTest.assembleStream( jarIn, warOut, Assembler.DISPATCH_SERVLET_CLASS
);
+        assertTrue( "Assembled WAR file was not created.", warFileOut.exists() );
+        verifyAssembly( warFileOut );
+        warFileOut.delete();
+    }
+    
+    public void testWebXmlStreamingAssembly() throws Exception {
+        File assembledWebXml = File.createTempFile( "streamingWebXmlTest", ".xml" );
+        OutputStream assembledWebXmlOut = new FileOutputStream( assembledWebXml );
+        webXmlAssemblerUnderTest.assembleStream(webXmlIn, portletXmlIn, assembledWebXmlOut,
Assembler.DISPATCH_SERVLET_CLASS);
+        verifyAssembly( new FileInputStream( assembledWebXml ), 
+                getClass().getResourceAsStream( portletXmlResource ) );
+        assembledWebXml.delete();
+    }
+    
+    protected void verifyAssembly( InputStream webXml, InputStream portletXml ) throws Exception
{
+        WebAppDescriptorService webSvc = new WebAppDescriptorServiceImpl();
+        PortletAppDescriptorService portletSvc = new PortletAppDescriptorServiceImpl();
+        WebAppDD webApp = webSvc.read( webXml ) ;
+        PortletAppDD portletApp = portletSvc.read( portletXml );
+        
+        assertNotNull( "Web Application Descripter was null.", webApp );
+        assertNotNull( "Portlet Application Descriptor was null.", portletApp );
+        assertTrue( "Portlet Application Descriptor doesn't define any portlets.", portletApp.getPortlets().size()
> 0 );
+        assertTrue( "Web Application Descriptor doesn't define any servlets.", webApp.getServlets().size()
> 0 );
+        assertTrue( "Web Application Descriptor doesn't define any servlet mappings.", webApp.getServletMappings().size()
> 0 );
+        
+        PortletDD portlet = (PortletDD) portletApp.getPortlets().iterator().next();
+        assertTrue( "Unable to retrieve test portlet named [" + testPortletName + "]", portlet.getPortletName().equals(
testPortletName ) );
+        
+        ServletDD servlet = webApp.getServlet( testPortletName );
+        assertNotNull( "Unable to retrieve portlet dispatch for portlet named [" + testPortletName
+ "]", servlet );        
+        assertEquals( "Dispatcher servlet incorrect for test portlet [" + testPortletName
+ "]",  Assembler.DISPATCH_SERVLET_CLASS, servlet.getServletClass() );        
+    }
+
+    protected void verifyAssembly( File warFile ) throws Exception {
+        WebAppDescriptorService webSvc = new WebAppDescriptorServiceImpl();
+        PortletAppDescriptorService portletSvc = new PortletAppDescriptorServiceImpl();
+        int entryCount = 0;
+        ByteArrayOutputStream portletXmlBytes = new ByteArrayOutputStream();
+        ByteArrayOutputStream webXmlBytes = new ByteArrayOutputStream();
+        WebAppDD webApp = null;
+        PortletAppDD portletApp = null;        
+                
+        JarInputStream assembledWarIn = new JarInputStream( new FileInputStream( warFile
) );
+        JarEntry tempEntry;
+        
+        while ( ( tempEntry = assembledWarIn.getNextJarEntry() ) != null  ) {
+            entryCount++;
+            
+            if ( Assembler.PORTLET_XML.equals( tempEntry.getName() ) ) {
+                IOUtils.copy( assembledWarIn, portletXmlBytes );
+                portletApp = portletSvc.read( new ByteArrayInputStream( portletXmlBytes.toByteArray()
) );
+            }
+            if ( Assembler.SERVLET_XML.equals( tempEntry.getName() ) ) {
+                IOUtils.copy( assembledWarIn, webXmlBytes );
+                webApp = webSvc.read( new ByteArrayInputStream( webXmlBytes.toByteArray()
) );
+            }
+        }
+        
+        assertTrue( "Assembled WAR file was empty.", entryCount > 0 );
+        assertNotNull( "Web Application Descripter was null.", webApp );
+        assertNotNull( "Portlet Application Descriptor was null.", portletApp );
+        assertTrue( "Portlet Application Descriptor doesn't define any portlets.", portletApp.getPortlets().size()
> 0 );
+        assertTrue( "Web Application Descriptor doesn't define any servlets.", webApp.getServlets().size()
> 0 );
+        assertTrue( "Web Application Descriptor doesn't define any servlet mappings.", webApp.getServletMappings().size()
> 0 );
+
+        PortletDD portlet = (PortletDD) portletApp.getPortlets().iterator().next();
+        assertTrue( "Unable to retrieve test portlet named [" + testPortletName + "]", portlet.getPortletName().equals(
testPortletName ) );
+
+        ServletDD servlet = webApp.getServlet( testPortletName );
+        assertNotNull( "Unable to retrieve portlet dispatch for portlet named [" + testPortletName
+ "]", servlet );        
+        assertEquals( "Dispatcher servlet incorrect for test portlet [" + testPortletName
+ "]",  Assembler.DISPATCH_SERVLET_CLASS, servlet.getServletClass() );
+    }
+}

Propchange: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/war/WarAssemblerTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/war/WarAssemblerTest.java?view=diff&rev=535741&r1=535740&r2=535741
==============================================================================
--- portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/war/WarAssemblerTest.java
(original)
+++ portals/pluto/trunk/pluto-util/src/test/java/org/apache/pluto/util/assemble/war/WarAssemblerTest.java
Sun May  6 21:55:37 2007
@@ -20,20 +20,22 @@
 import java.io.IOException;
 import java.net.URL;
 
-import junit.framework.TestCase;
-
 import org.apache.commons.io.FileUtils;
+import org.apache.pluto.util.assemble.Assembler;
 import org.apache.pluto.util.assemble.AssemblerConfig;
+import org.apache.pluto.util.assemble.ArchiveBasedAssemblyTest;
 
 /**
  * @version $Revision$
  */
-public class WarAssemblerTest extends TestCase {
+public class WarAssemblerTest extends ArchiveBasedAssemblyTest {
 
-    private File portletFile;
+    private static final String portletResource = "/org/apache/pluto/util/assemble/war/WarDeployerTestPortlet.war";
+    private File portletFile = null;
+        
 
     protected void setUp() throws Exception {
-        final URL portletUrl = this.getClass().getResource("/org/apache/pluto/util/assemble/war/WarDeployerTestPortlet.war");
+        final URL portletUrl = this.getClass().getResource(portletResource);
         this.portletFile = new File(portletUrl.getFile());
     }
 
@@ -44,7 +46,7 @@
     public void testAssembleToNewDirectory() throws Exception {
         AssemblerConfig config = new AssemblerConfig();
 
-        config.setWarSource(this.portletFile);
+        config.setSource(this.portletFile);
 
         final File tempDir = getTempDir();
         config.setDestination(tempDir);
@@ -62,7 +64,7 @@
         portletCopy.deleteOnExit();
         FileUtils.copyFile(this.portletFile, portletCopy);
 
-        config.setWarSource(portletCopy);
+        config.setSource(portletCopy);
         config.setDestination(portletCopy.getParentFile());
 
         WarAssembler assembler = new WarAssembler();
@@ -76,5 +78,13 @@
         tempFile.delete();
         final File tempDir = tempFile.getParentFile();
         return tempDir;
+    }
+
+    protected Assembler getAssemblerUnderTest() {
+        return new WarAssembler();
+    }
+
+    protected File getFileToAssemble() {
+        return portletFile;
     }
 }

Added: portals/pluto/trunk/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/ComplexEarDeployerTest.ear
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/ComplexEarDeployerTest.ear?view=auto&rev=535741
==============================================================================
Binary file - no diff available.

Propchange: portals/pluto/trunk/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/ComplexEarDeployerTest.ear
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: portals/pluto/trunk/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/EarDeployerTest.ear
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/EarDeployerTest.ear?view=auto&rev=535741
==============================================================================
Binary file - no diff available.

Propchange: portals/pluto/trunk/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/EarDeployerTest.ear
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: portals/pluto/trunk/pluto-util/src/test/resources/org/apache/pluto/util/assemble/war/WarDeployerTestPortlet.war
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/test/resources/org/apache/pluto/util/assemble/war/WarDeployerTestPortlet.war?view=diff&rev=535741&r1=535740&r2=535741
==============================================================================
Binary files - no diff available.



Mime
View raw message