You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by es...@apache.org on 2007/05/17 19:07:02 UTC
svn commit: r539020 [2/2] - in /portals/pluto/branches/pluto-1.1.x:
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/mai...
Added: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java?view=auto&rev=539020
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java (added)
+++ portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ArchiveBasedAssemblyTest.java Thu May 17 10:07:00 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;
+ }
+
+}
Added: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java?view=auto&rev=539020
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java (added)
+++ portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/ComplexEarAssemblerTest.java Thu May 17 10:07:00 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;
+ }
+
+}
Added: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java?view=auto&rev=539020
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java (added)
+++ portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/ear/EarAssemblerTest.java Thu May 17 10:07:00 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;
+ }
+
+}
Added: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java?view=auto&rev=539020
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java (added)
+++ portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/io/AssemblyStreamTest.java Thu May 17 10:07:00 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() );
+ }
+}
Modified: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/war/WarAssemblerTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/war/WarAssemblerTest.java?view=diff&rev=539020&r1=539019&r2=539020
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/war/WarAssemblerTest.java (original)
+++ portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/java/org/apache/pluto/util/assemble/war/WarAssemblerTest.java Thu May 17 10:07:00 2007
@@ -20,20 +20,21 @@
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 {
-
- private File portletFile;
+public class WarAssemblerTest extends ArchiveBasedAssemblyTest {
+ 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 +45,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 +63,7 @@
portletCopy.deleteOnExit();
FileUtils.copyFile(this.portletFile, portletCopy);
- config.setWarSource(portletCopy);
+ config.setSource(portletCopy);
config.setDestination(portletCopy.getParentFile());
WarAssembler assembler = new WarAssembler();
@@ -77,4 +78,13 @@
final File tempDir = tempFile.getParentFile();
return tempDir;
}
+
+ protected Assembler getAssemblerUnderTest() {
+ return new WarAssembler();
+ }
+
+ protected File getFileToAssemble() {
+ return portletFile;
+ }
}
+
Added: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/ComplexEarDeployerTest.ear
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/ComplexEarDeployerTest.ear?view=auto&rev=539020
==============================================================================
Binary file - no diff available.
Propchange: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/ComplexEarDeployerTest.ear
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/EarDeployerTest.ear
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/EarDeployerTest.ear?view=auto&rev=539020
==============================================================================
Binary file - no diff available.
Propchange: portals/pluto/branches/pluto-1.1.x/pluto-util/src/test/resources/org/apache/pluto/util/assemble/ear/EarDeployerTest.ear
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream