[jboss-svn-commits] JBoss Common SVN: r3667 - in shrinkwrap/trunk: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 11 09:47:18 EST 2009
Author: aslak
Date: 2009-11-11 09:47:18 -0500 (Wed, 11 Nov 2009)
New Revision: 3667
Added:
shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.export.ExplodedExporter
shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.export.ZipExporter
Removed:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/FactoryUtil.java
Modified:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/ExplodedExporter.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/ZipExporter.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterDelegate.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterImpl.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipArchiveInputStreamFactory.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterImpl.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java
Log:
SHRINKWRAP-67 Changed Exporters to follow the Specialized API
Modified: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/ExplodedExporter.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/ExplodedExporter.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/ExplodedExporter.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -18,7 +18,7 @@
import java.io.File;
-import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Specializer;
/**
* ExplodedExporter
@@ -26,30 +26,17 @@
* Exporter used to export an Archive as an exploded directory structure.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
-public abstract class ExplodedExporter
+public interface ExplodedExporter extends Specializer
{
//-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
/**
- * Implementation type as a FQN to avoid direct compile-time dependency
- */
- private static final String IMPL_TYPE = "org.jboss.shrinkwrap.impl.base.export.ExplodedExporterImpl";
-
- /**
- * Instance of ExplodedExporter implementation
- */
- private static ExplodedExporter instance;
-
- //-------------------------------------------------------------------------------------||
- // Class Methods ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
* Exports provided archive as an exploded directory structure.
*
* @param archive
@@ -58,46 +45,5 @@
* @throws IllegalArgumentException if the archive or parent directory not valid
* @throws ArchiveExportException if the export process fails
*/
- public static File exportExploded(Archive<?> archive, File parentDirectory)
- {
- return getInstance().doExportExploded(archive, parentDirectory);
- }
-
- /**
- * Get an instance of the ExplodedExporter implementation
- *
- * @return
- */
- private synchronized static ExplodedExporter getInstance()
- {
- if (instance == null)
- {
- instance = createInstance();
- }
- return instance;
- }
-
- /**
- * Create an instance of the ExplodedEporter implementation
- *
- * @return
- */
- private static ExplodedExporter createInstance()
- {
- return FactoryUtil.createInstance(IMPL_TYPE, ExplodedExporter.class);
- }
-
- //-------------------------------------------------------------------------------------||
- // Contracts --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Template export method for concrete implementations
- *
- * @param archive
- * @param parentDirectory
- * @return File for exploded archive contents
- */
- protected abstract File doExportExploded(Archive<?> archive, File parentDirectory);
-
+ File exportExploded(File parentDirectory);
}
Deleted: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/FactoryUtil.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/FactoryUtil.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/FactoryUtil.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -1,106 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.shrinkwrap.api.export;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.logging.Logger;
-
-/**
- * FactoryUtil
- *
- * Package-private factory utilities
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-class FactoryUtil
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(FactoryUtil.class.getName());
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Prohibit instantiation
- */
- private FactoryUtil()
- {
- throw new UnsupportedOperationException("No instances should be created; stateless utility class");
- }
-
- //-------------------------------------------------------------------------------------||
- // Functional Methods -----------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Create an instance of the Class with the specified FQN, of the expected
- * type
- *
- * @throws IllegalArgumentException If the specified type is not assignable to the instance
- * of the class created from the specified class name, or if either argument is not
- * supplied
- */
- static <T> T createInstance(final String className, final Class<T> type) throws IllegalArgumentException
- {
- // Precondition checks
- if (className == null || className.length() == 0)
- {
- throw new IllegalArgumentException("className must be specified");
- }
- if (type == null)
- {
- throw new IllegalArgumentException("type must be specified");
- }
-
- return AccessController.doPrivileged(new PrivilegedAction<T>()
- {
- public T run()
- {
- try
- {
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- final Class<?> clazz = Class.forName(className, false, classLoader);
- final Object obj = clazz.newInstance();
- try
- {
- return type.cast(obj);
- }
- catch (final ClassCastException cee)
- {
- throw new IllegalArgumentException("Specified type " + type.getName() + " is not assignable to "
- + obj);
- }
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("Unable to create implemenation: " + className, e);
- }
- }
- });
- }
-
-}
Modified: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/ZipExporter.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/ZipExporter.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/export/ZipExporter.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -18,7 +18,7 @@
import java.io.InputStream;
-import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Specializer;
/**
* ZipExporter
@@ -26,30 +26,16 @@
* Exporter used to export an Archive as a Zip format.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
-public abstract class ZipExporter
+public interface ZipExporter extends Specializer
{
-
//-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
/**
- * Implementation type as a FQN to avoid direct compile-time dependency
- */
- private static final String IMPL_TYPE = "org.jboss.shrinkwrap.impl.base.export.ZipExporterImpl";
-
- /**
- * Instance of ZipExporter implementation
- */
- private static ZipExporter instance;
-
- //-------------------------------------------------------------------------------------||
- // Class Methods ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
* Exports provided archive as a Zip archive.
*
* @param archive
@@ -57,44 +43,5 @@
* @throws IllegalArgumentException if the archive is not valid
* @throws ArchiveExportException if the export process fails
*/
- public static InputStream exportZip(Archive<?> archive)
- {
- return getInstance().doExportZip(archive);
- }
-
- /**
- * Get an instance of the ZipExporter implementation
- * @return
- */
- private synchronized static ZipExporter getInstance()
- {
- if (instance == null)
- {
- instance = createInstance();
- }
- return instance;
- }
-
- /**
- * Create an instance of the ZipExporter implementation
- *
- * @return
- */
- private static ZipExporter createInstance()
- {
- return FactoryUtil.createInstance(IMPL_TYPE, ZipExporter.class);
- }
-
- //-------------------------------------------------------------------------------------||
- // Contracts --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Template export method for concrete implementations
- *
- * @param archive
- * @return InputStream for exported Zip
- */
- protected abstract InputStream doExportZip(Archive<?> archive);
-
+ InputStream exportZip();
}
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterDelegate.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterDelegate.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterDelegate.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -36,6 +36,7 @@
* Delegate used to export an archive into an exploded directory structure.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
public class ExplodedExporterDelegate extends AbstractExporterDelegate<File>
@@ -148,8 +149,7 @@
{
// Get the nested archive
Archive<?> nestedArchive = nestedArchiveAsset.getArchive();
-
- ExplodedExporter.exportExploded(nestedArchive, parentDirectory);
+ nestedArchive.as(ExplodedExporter.class).exportExploded(parentDirectory);
}
/**
@@ -160,7 +160,6 @@
*/
private File initializeOutputDirectory(File baseDirectory)
{
-
// Get archive
Archive<?> archive = getArchive();
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterImpl.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterImpl.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterImpl.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -22,6 +22,7 @@
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.export.ExplodedExporter;
+import org.jboss.shrinkwrap.impl.base.SpecializedBase;
import org.jboss.shrinkwrap.impl.base.Validate;
/**
@@ -30,9 +31,10 @@
* Implementation of ExplodedExporter used to export an Archive as an exploded directory structure.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
-public class ExplodedExporterImpl extends ExplodedExporter
+public class ExplodedExporterImpl extends SpecializedBase implements ExplodedExporter
{
//-------------------------------------------------------------------------------------||
@@ -44,17 +46,43 @@
*/
private static final Logger log = Logger.getLogger(ExplodedExporterImpl.class.getName());
+ /**
+ * Archive to import into.
+ */
+ private Archive<?> archive;
+
//-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public ExplodedExporterImpl(Archive<?> archive)
+ {
+ Validate.notNull(archive, "Archive must be specified");
+ this.archive = archive;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.shrinkwrap.impl.base.SpecializedBase#getArchive()
+ */
+ @Override
+ protected Archive<?> getArchive()
+ {
+ return archive;
+ }
+
+ //-------------------------------------------------------------------------------------||
// Required Implementations - ExplodedExporter ----------------------------------------||
//-------------------------------------------------------------------------------------||
-
- /**
- * {@inheritDoc}
- * @see ExplodedExporter#doExportExploded(Archive, File)
+ /* (non-Javadoc)
+ * @see org.jboss.shrinkwrap.api.export.ExplodedExporter#exportExploded(java.io.File)
*/
@Override
- protected File doExportExploded(Archive<?> archive, File baseDirectory)
+ public File exportExploded(File baseDirectory)
{
Validate.notNull(archive, "No archive provided");
Validate.notNull(baseDirectory, "No baseDirectory provided");
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipArchiveInputStreamFactory.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipArchiveInputStreamFactory.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipArchiveInputStreamFactory.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -28,6 +28,7 @@
* Factory used create an InputStream from an Archive by exporting the archive as a Zip.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
public class ZipArchiveInputStreamFactory extends ArchiveInputStreamFactory
@@ -44,7 +45,7 @@
protected InputStream doGetInputStream(Archive<?> archive)
{
// Get InputStream from the ZipExporter
- final InputStream inputStream = ZipExporter.exportZip(archive);
+ final InputStream inputStream = archive.as(ZipExporter.class).exportZip();
// Return input stream
return inputStream;
}
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterImpl.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterImpl.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterImpl.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -21,6 +21,7 @@
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.export.ZipExporter;
+import org.jboss.shrinkwrap.impl.base.SpecializedBase;
import org.jboss.shrinkwrap.impl.base.Validate;
/**
@@ -29,9 +30,10 @@
* Implementation of ZipExporter used to export an Archive as a Zip format.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
-public class ZipExporterImpl extends ZipExporter
+public class ZipExporterImpl extends SpecializedBase implements ZipExporter
{
//-------------------------------------------------------------------------------------||
@@ -43,7 +45,35 @@
*/
private static final Logger log = Logger.getLogger(ZipExporterImpl.class.getName());
+ /**
+ * Archive to import into.
+ */
+ private Archive<?> archive;
+
//-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public ZipExporterImpl(Archive<?> archive)
+ {
+ Validate.notNull(archive, "Archive must be specified");
+ this.archive = archive;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.shrinkwrap.impl.base.SpecializedBase#getArchive()
+ */
+ @Override
+ protected Archive<?> getArchive()
+ {
+ return archive;
+ }
+
+ //-------------------------------------------------------------------------------------||
// Required Implementations - ZipExporter ---------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -52,10 +82,8 @@
* @see org.jboss.shrinkwrap.api.export.ZipExporter#doExportZip(org.jboss.shrinkwrap.api.Archive)
*/
@Override
- protected InputStream doExportZip(Archive<?> archive)
+ public InputStream exportZip()
{
- Validate.notNull(archive, "No archive provided");
-
// Create export delegate
ZipExportDelegate exportDelegate = new ZipExportDelegate(archive);
Added: shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.export.ExplodedExporter
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.export.ExplodedExporter (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.export.ExplodedExporter 2009-11-11 14:47:18 UTC (rev 3667)
@@ -0,0 +1 @@
+org.jboss.shrinkwrap.impl.base.export.ExplodedExporterImpl
\ No newline at end of file
Added: shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.export.ZipExporter
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.export.ZipExporter (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.export.ZipExporter 2009-11-11 14:47:18 UTC (rev 3667)
@@ -0,0 +1 @@
+org.jboss.shrinkwrap.impl.base.export.ZipExporterImpl
\ No newline at end of file
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterTestCase.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ExplodedExporterTestCase.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -40,6 +40,7 @@
* TestCase to ensure that the {@link ExplodedExporter} correctly exports archive.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
public class ExplodedExporterTestCase extends ExportTestBase
@@ -75,7 +76,7 @@
Archive<?> archive = createArchiveWithAssets();
// Export as Exploded directory
- File explodedDirectory = ExplodedExporter.exportExploded(archive, tempDirectory);
+ File explodedDirectory = archive.as(ExplodedExporter.class).exportExploded(tempDirectory);
// Validate the exploded directory was created
Assert.assertNotNull(explodedDirectory);
@@ -106,7 +107,7 @@
Archive<?> archive = createArchiveWithNestedArchives();
// Export as Exploded directory
- File explodedDirectory = ExplodedExporter.exportExploded(archive, tempDirectory);
+ File explodedDirectory = archive.as(ExplodedExporter.class).exportExploded(tempDirectory);
// Validate the exploded directory was created
Assert.assertNotNull(explodedDirectory);
@@ -128,43 +129,16 @@
}
/**
- * Ensure an archive is required to export.
- *
- * @throws Exception
- */
- @Test
- public void testExportExplodedRequiresArchive() throws Exception
- {
- log.info("testExportExplodedRequiresArchive");
-
- try
- {
- ExplodedExporter.exportExploded(null, getNonexistantDirectory());
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (IllegalArgumentException expected)
- {
- }
- }
-
- /**
* Ensure an baseDirectory is required to export.
*
* @throws Exception
*/
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testExportExplodedRequiresBaseDirectroy() throws Exception
{
log.info("testExportExplodedRequiresBaseDirectroy");
- try
- {
- ExplodedExporter.exportExploded(new MemoryMapArchiveImpl(), null);
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (IllegalArgumentException expected)
- {
- }
+ new MemoryMapArchiveImpl().as(ExplodedExporter.class).exportExploded(null);
}
/**
@@ -172,110 +146,62 @@
*
* @throws Exception
*/
- @Test
- public void testExportExplodedRequiresExisitingDirectroy() throws Exception
+ @Test(expected = IllegalArgumentException.class)
+ public void testExportExplodedRequiresExistingDirectory() throws Exception
{
log.info("testExportExplodedRequiresExisitingDirectroy");
- try
- {
- final File directory = this.getNonexistantDirectory();
- ExplodedExporter.exportExploded(new MemoryMapArchiveImpl(), directory);
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (IllegalArgumentException expected)
- {
- }
+ final File directory = this.getNonexistantDirectory();
+ new MemoryMapArchiveImpl().as(ExplodedExporter.class).exportExploded(directory);
}
/**
- * Ensure an baseDirectory must be a directory.
- *
- * @throws Exception
- */
- @Test
- public void testExportExplodedRequiresExistingDirectory() throws Exception
- {
- log.info("testExportExplodedRequiresExistingDirectory");
- try
- {
- final File directory = this.getNonexistantDirectory();
- ExplodedExporter.exportExploded(new MemoryMapArchiveImpl(), directory);
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (IllegalArgumentException expected)
- {
- }
- }
-
- /**
* Ensure ExpolodedExporter requires a directory
*/
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testExportExplodedRequiresValidDirectory() throws Exception
{
log.info("testExportExplodedRequiresValidDirectory");
- try
- {
- final File nonDirectory = new File(this.getTarget(), "tempFile.txt");
- nonDirectory.createNewFile();
- ExplodedExporter.exportExploded(new MemoryMapArchiveImpl(), nonDirectory);
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (IllegalArgumentException expected)
- {
- }
+ final File nonDirectory = new File(this.getTarget(), "tempFile.txt");
+ nonDirectory.createNewFile();
+ new MemoryMapArchiveImpl().as(ExplodedExporter.class).exportExploded(nonDirectory);
}
/**
* Ensure an ArchiveExportException is thrown when output directory can not be created
*/
- @Test
+ @Test(expected = ArchiveExportException.class)
public void testExportExplodedOutpuDirCreationFails() throws Exception
{
log.info("testExportExplodedOutpuDirCreationFails");
- try
- {
- final File directory = createTempDirectory("testExportExplodedOutpuDirCreationFails");
- // Will cause the creation of Archive directory to fail
- final File existingFile = new File(directory, NAME_ARCHIVE);
- existingFile.createNewFile();
- ExplodedExporter.exportExploded(new MemoryMapArchiveImpl(NAME_ARCHIVE), directory);
- Assert.fail("Should have thrown ArchiveExportException");
- }
- catch (ArchiveExportException expected)
- {
- }
+ final File directory = createTempDirectory("testExportExplodedOutpuDirCreationFails");
+ // Will cause the creation of Archive directory to fail
+ final File existingFile = new File(directory, NAME_ARCHIVE);
+ existingFile.createNewFile();
+ new MemoryMapArchiveImpl(NAME_ARCHIVE).as(ExplodedExporter.class).exportExploded(directory);
}
/**
* Ensure ArchiveException is thrown if Asset can not be written
*/
- @Test
+ @Test(expected = ArchiveExportException.class)
public void testExportExplodedThrowsExceptionOnAssetWrite() throws Exception
{
log.info("testExportExplodedThrowsExceptionOnAssetWrite");
- try
+ Archive<?> archive = createArchiveWithAssets();
+ archive.add(new Asset()
{
- Archive<?> archive = createArchiveWithAssets();
- archive.add(new Asset()
+
+ @Override
+ public InputStream openStream()
{
+ throw new RuntimeException("Mock Esception getting Stream");
+ }
- @Override
- public InputStream openStream()
- {
- throw new RuntimeException("Mock Esception getting Stream");
- }
+ }, new BasicPath("badAsset"));
+ final File directory = createTempDirectory("testExportExplodedThrowsExceptionOnAssetWrite");
- }, new BasicPath("badAsset"));
- final File directory = createTempDirectory("testExportExplodedThrowsExceptionOnAssetWrite");
-
- ExplodedExporter.exportExploded(archive, directory);
- Assert.fail("Should have thrown ArchiveExportException");
- }
- catch (ArchiveExportException expected)
- {
- }
+ archive.as(ExplodedExporter.class).exportExploded(directory);
}
//-------------------------------------------------------------------------------------||
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterTestCase.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterTestCase.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -41,6 +41,7 @@
* TestCase to ensure that the {@link ZipExporter} correctly exports archives to Zip format.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
public class ZipExporterTestCase extends ExportTestBase
@@ -74,7 +75,7 @@
Archive<?> archive = createArchiveWithAssets();
// Export as Zip InputStream
- InputStream zipStream = ZipExporter.exportZip(archive);
+ InputStream zipStream = archive.as(ZipExporter.class).exportZip();
// Write zip content to temporary file
ZipFile expectedZip = getExportedZipFile(NAME_ARCHIVE, zipStream, tempDirectory);
@@ -101,7 +102,7 @@
Archive<?> archive = createArchiveWithNestedArchives();
// Export as Zip InputStream
- InputStream zipStream = ZipExporter.exportZip(archive);
+ InputStream zipStream = archive.as(ZipExporter.class).exportZip();
// Write out and retrieve Zip
ZipFile expectedZip = getExportedZipFile(NAME_ARCHIVE, zipStream, tempDirectory);
@@ -148,50 +149,24 @@
}
- /**
- * Ensure an archive is required to export.
- *
- * @throws Exception
- */
- @Test
- public void testExportZipRequiresArchive() throws Exception
- {
- log.info("testExportZipRequiresArchive");
- try
- {
- ZipExporter.exportZip(null);
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (IllegalArgumentException expected)
- {
- }
- }
-
- @Test
+ @Test(expected = ArchiveExportException.class)
public void testExportThrowsArchiveExcepitonOnAssetWriteFailure()
{
log.info("testExportThrowsArchiveExcepitonOnAssetWriteFailure");
- try
+ Archive<?> archive = createArchiveWithAssets();
+
+ archive.add(new Asset()
{
- Archive<?> archive = createArchiveWithAssets();
- archive.add(new Asset()
+ @Override
+ public InputStream openStream()
{
+ throw new RuntimeException("Mock Exception from an Asset write");
+ }
- @Override
- public InputStream openStream()
- {
- throw new RuntimeException("Mock Exception from an Asset write");
- }
+ }, PATH_ONE);
- }, PATH_ONE);
-
- ZipExporter.exportZip(archive);
- Assert.fail("Should have thrown ArchiveExportException");
- }
- catch (ArchiveExportException expected)
- {
- }
+ archive.as(ZipExporter.class).exportZip();
}
//-------------------------------------------------------------------------------------||
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java 2009-11-11 13:57:51 UTC (rev 3666)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java 2009-11-11 14:47:18 UTC (rev 3667)
@@ -104,7 +104,7 @@
File tempFile = new File("target/test.zip");
tempFile.deleteOnExit();
- InputStream zipStream = ZipExporter.exportZip(archive);
+ InputStream zipStream = archive.as(ZipExporter.class).exportZip();
IOUtil.copyWithClose(zipStream, new FileOutputStream(tempFile));
assertContent(archive, tempFile.toURI());
More information about the jboss-svn-commits
mailing list