[jboss-svn-commits] JBoss Common SVN: r4601 - shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jun 29 09:13:10 EDT 2010


Author: ALRubinger
Date: 2010-06-29 09:13:10 -0400 (Tue, 29 Jun 2010)
New Revision: 4601

Modified:
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExportTestBase.java
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/StreamExporterTestBase.java
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterStressTest.java
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java
Log:
[SHRINKWRAP-194] Refactoring to Exporters to promote extensibility

Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java	2010-06-29 13:11:36 UTC (rev 4600)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java	2010-06-29 13:13:10 UTC (rev 4601)
@@ -57,6 +57,25 @@
     * Logger
     */
    private static final Logger log = Logger.getLogger(ExplodedExporterTestCase.class.getName());
+   
+   /**
+    * Extension for exploded archives
+    */
+   private static final String EXTENSION = ".jar";
+   
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+   
+   /**
+    * {@inheritDoc
+    * @see org.jboss.shrinkwrap.impl.base.exporter.ExportTestBase#getArchiveExtension()
+    */
+   @Override
+   protected String getArchiveExtension()
+   {
+      return EXTENSION;
+   }
 
    //-------------------------------------------------------------------------------------||
    // Tests ------------------------------------------------------------------------------||
@@ -120,12 +139,12 @@
       Assert.assertEquals(expectedDirectory, explodedDirectory);
 
       // Validate nested archive entries were written out
-      ArchivePath nestedArchivePath = new BasicPath(NAME_NESTED_ARCHIVE);
+      ArchivePath nestedArchivePath = new BasicPath(NAME_NESTED_ARCHIVE + this.getArchiveExtension());
 
       assertAssetInExploded(explodedDirectory, new BasicPath(nestedArchivePath, PATH_ONE), ASSET_ONE);
       assertAssetInExploded(explodedDirectory, new BasicPath(nestedArchivePath, PATH_TWO), ASSET_TWO);
 
-      ArchivePath nestedArchivePathTwo = new BasicPath(NESTED_PATH, NAME_NESTED_ARCHIVE_2);
+      ArchivePath nestedArchivePathTwo = new BasicPath(NESTED_PATH, NAME_NESTED_ARCHIVE_2 + this.getArchiveExtension());
 
       assertAssetInExploded(explodedDirectory, new BasicPath(nestedArchivePathTwo, PATH_ONE), ASSET_ONE);
       assertAssetInExploded(explodedDirectory, new BasicPath(nestedArchivePathTwo, PATH_TWO), ASSET_TWO);
@@ -244,7 +263,7 @@
       log.info("testExportExplodedOutpuDirIsAFile");
       final File directory = createTempDirectory("testExportExplodedOutpuDirIsAFile");
       // Will cause the creation of Archive directory to fail
-      final File existingFile = new File(directory, NAME_ARCHIVE);
+      final File existingFile = new File(directory, NAME_ARCHIVE + this.getArchiveExtension());
       final boolean created = existingFile.createNewFile();
       
       IOUtil.copyWithClose(new ByteArrayInputStream("test-test".getBytes()), new FileOutputStream(existingFile));

Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExportTestBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExportTestBase.java	2010-06-29 13:11:36 UTC (rev 4600)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExportTestBase.java	2010-06-29 13:13:10 UTC (rev 4601)
@@ -56,7 +56,7 @@
    /**
     * Name of an Archive
     */
-   protected static final String NAME_ARCHIVE = "testArchive.jar";
+   protected static final String NAME_ARCHIVE = "testArchive";
 
    /**
     * Name of a properties file upon the test CP
@@ -76,12 +76,12 @@
    /**
     * Name of a nested archive
     */
-   protected static final String NAME_NESTED_ARCHIVE = "nestedArchive.jar";
+   protected static final String NAME_NESTED_ARCHIVE = "nestedArchive";
 
    /**
     * Name of another nested archive
     */
-   protected static final String NAME_NESTED_ARCHIVE_2 = "nestedArchive2.jar";
+   protected static final String NAME_NESTED_ARCHIVE_2 = "nestedArchive2";
 
    /** 
     * Asset used for testing
@@ -159,12 +159,18 @@
    protected Archive<?> createArchiveWithAssets()
    {
       // Create an archive
-      Archive<?> archive = ShrinkWrap.create(JavaArchive.class, NAME_ARCHIVE);
+      Archive<?> archive = ShrinkWrap.create(JavaArchive.class, NAME_ARCHIVE + getArchiveExtension());
       // Add some content
       addContent(archive);
       // Return archive
       return archive;
    }
+   
+   /**
+    * Obtains the extension for created archives
+    * @return
+    */
+   protected abstract String getArchiveExtension();
 
    /**
     * Create an archive instance and add some assets and some nested archives
@@ -175,7 +181,7 @@
       Archive<?> archive = createArchiveWithAssets();
 
       // Create a nested archive
-      Archive<?> nestedArchive = ShrinkWrap.create(JavaArchive.class, NAME_NESTED_ARCHIVE);
+      Archive<?> nestedArchive = ShrinkWrap.create(JavaArchive.class, NAME_NESTED_ARCHIVE+ getArchiveExtension());
 
       // Add some content
       addContent(nestedArchive);
@@ -184,7 +190,7 @@
       archive.add(nestedArchive, new BasicPath());
 
       // Add an archive nested in a directory
-      Archive<?> nestedArchiveTwo = ShrinkWrap.create(JavaArchive.class, NAME_NESTED_ARCHIVE_2);
+      Archive<?> nestedArchiveTwo = ShrinkWrap.create(JavaArchive.class, NAME_NESTED_ARCHIVE_2+ getArchiveExtension());
 
       // Add some content
       addContent(nestedArchiveTwo);

Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/StreamExporterTestBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/StreamExporterTestBase.java	2010-06-29 13:11:36 UTC (rev 4600)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/StreamExporterTestBase.java	2010-06-29 13:13:10 UTC (rev 4601)
@@ -17,7 +17,6 @@
 package org.jboss.shrinkwrap.impl.base.exporter;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -44,7 +43,6 @@
 import org.jboss.shrinkwrap.api.exporter.FileExistsException;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.jboss.shrinkwrap.impl.base.io.IOUtil;
-import org.jboss.shrinkwrap.impl.base.path.BasicPath;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -94,14 +92,6 @@
    protected abstract void exportAsFile(Archive<?> archive, File file, boolean overwrite);
 
    /**
-    * Ensures the contents of the specified {@link InputStream} are
-    * as expected
-    * @param instream
-    * @throws IOException If an I/O error occurred
-    */
-   protected abstract void ensureInExpectedForm(InputStream instream) throws IOException;
-
-   /**
     * Ensures the contents of the specified {@link File} are
     * as expected
     * @param file
@@ -138,7 +128,11 @@
       final InputStream exportStream = this.exportAsInputStream(archive);
 
       // Validate
-      ensureInExpectedForm(exportStream);
+      final File tempDirectory = createTempDirectory("testExport");
+      final File serialized = new File(tempDirectory, archive.getName());
+      final FileOutputStream out = new FileOutputStream(serialized);
+      IOUtil.copyWithClose(exportStream, out);
+      ensureInExpectedForm(serialized);
    }
 
    /**
@@ -233,8 +227,7 @@
       this.exportAsFile(archive, exported, true);
 
       // Roundtrip assertion
-      final InputStream instream = new FileInputStream(exported);
-      this.ensureInExpectedForm(instream);
+      this.ensureInExpectedForm(exported);
    }
 
    /**
@@ -320,7 +313,7 @@
       final InputStream exportStream = this.exportAsInputStream(archive);
 
       // Write out and retrieve as exported file
-      final File exported = new File(tempDirectory, NAME_ARCHIVE);
+      final File exported = new File(tempDirectory, NAME_ARCHIVE + this.getArchiveExtension());
       final OutputStream exportedOut = new FileOutputStream(exported);
       IOUtil.copyWithClose(exportStream, exportedOut);
 
@@ -329,13 +322,13 @@
       this.ensureAssetInExportedFile(exported, PATH_TWO, ASSET_TWO);
 
       // Validate nested archive entries were written out
-      final ArchivePath nestedArchivePath = ArchivePaths.create(NAME_NESTED_ARCHIVE);
+      final ArchivePath nestedArchivePath = ArchivePaths.create(NAME_NESTED_ARCHIVE+this.getArchiveExtension());
 
       // Get inputstream for entry 
       final InputStream nestedArchiveStream = this.getContentsFromExportedFile(exported, nestedArchivePath);
 
       // Write out and retrieve nested contents
-      final File nestedFile = new File(tempDirectory, NAME_NESTED_ARCHIVE);
+      final File nestedFile = new File(tempDirectory, NAME_NESTED_ARCHIVE + this.getArchiveExtension());
       final OutputStream nestedOut = new FileOutputStream(nestedFile);
       IOUtil.copyWithClose(nestedArchiveStream, nestedOut);
 
@@ -344,12 +337,13 @@
       this.ensureAssetInExportedFile(nestedFile, PATH_TWO, ASSET_TWO);
 
       // Validate nested archive entries were written out
-      final ArchivePath nestedArchiveTwoPath = new BasicPath(NESTED_PATH, NAME_NESTED_ARCHIVE_2);
+      final ArchivePath nestedArchiveTwoPath = ArchivePaths.create(NESTED_PATH, NAME_NESTED_ARCHIVE_2
+            + this.getArchiveExtension());
       this.getContentsFromExportedFile(exported, nestedArchiveTwoPath);
       final InputStream nestedArchiveTwoStream = this.getContentsFromExportedFile(exported, nestedArchiveTwoPath);
 
       // Write out and retrieve secondnested contents
-      final File nestedTwoFile = new File(tempDirectory, NAME_NESTED_ARCHIVE_2);
+      final File nestedTwoFile = new File(tempDirectory, NAME_NESTED_ARCHIVE_2 + this.getArchiveExtension());
       final OutputStream nestedTwoOut = new FileOutputStream(nestedTwoFile);
       IOUtil.copyWithClose(nestedArchiveTwoStream, nestedTwoOut);
 

Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterStressTest.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterStressTest.java	2010-06-29 13:11:36 UTC (rev 4600)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterStressTest.java	2010-06-29 13:13:10 UTC (rev 4601)
@@ -44,7 +44,7 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public class ZipExporterStressTest extends ExportTestBase
+public class ZipExporterStressTest
 {
    //-------------------------------------------------------------------------------------||
    // Class Members ----------------------------------------------------------------------||

Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java	2010-06-29 13:11:36 UTC (rev 4600)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java	2010-06-29 13:13:10 UTC (rev 4601)
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.UUID;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
@@ -47,6 +46,15 @@
 public final class ZipExporterTestCase extends StreamExporterTestBase
 {
    //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Extension for archives
+    */
+   private static final String EXTENSION = ".jar";
+
+   //-------------------------------------------------------------------------------------||
    // Required Implementations -----------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
 
@@ -63,26 +71,6 @@
 
    /**
     * {@inheritDoc}
-    * @see org.jboss.shrinkwrap.impl.base.exporter.StreamExporterTestBase#ensureInExpectedForm(java.io.InputStream)
-    */
-   @Override
-   protected void ensureInExpectedForm(final InputStream instream) throws IOException
-   {
-      // Precondition check
-      assert instream != null : "instream must be specified";
-
-      // Get a temp directory for the test
-      final File tempDirectory = createTempDirectory(UUID.randomUUID().toString());
-
-      // Write zip content to temporary file 
-      final ZipFile expectedZip = getExportedZipFile(NAME_ARCHIVE, instream, tempDirectory);
-
-      // Validate
-      ensureZipFileInExpectedForm(expectedZip);
-   }
-
-   /**
-    * {@inheritDoc}
     * @see org.jboss.shrinkwrap.impl.base.exporter.StreamExporterTestBase#exportAsFile(org.jboss.shrinkwrap.api.Archive, java.io.File, boolean)
     */
    @Override
@@ -147,6 +135,16 @@
       return new ByteArrayInputStream(actualContents);
    }
 
+   /**
+    * {@inheritDoc
+    * @see org.jboss.shrinkwrap.impl.base.exporter.ExportTestBase#getArchiveExtension()
+    */
+   @Override
+   protected String getArchiveExtension()
+   {
+      return EXTENSION;
+   }
+
    //-------------------------------------------------------------------------------------||
    // Tests ------------------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||



More information about the jboss-svn-commits mailing list