[jboss-svn-commits] JBoss Common SVN: r3491 - in declarchive/trunk: impl-base/src/test/java/org/jboss/declarchive/impl/base/unit and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Aug 26 09:18:55 EDT 2009
Author: aslak
Date: 2009-08-26 09:18:55 -0400 (Wed, 26 Aug 2009)
New Revision: 3491
Added:
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestUtil.java
Modified:
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestBase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/MemoryMapArchiveTestCase.java
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java
Log:
TMPARCH-22
- Fixed @author
- Removed comments + building impl test
- Moved add Content tests down to ArchiveTestBase
- Added ArchiveTestUtil, helper for asset stream compare
- Added createNewArchive to ArchiveTestBase to request new archives to add to the Archive under test (add(Archive))
Modified: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestBase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestBase.java 2009-08-26 10:36:15 UTC (rev 3490)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestBase.java 2009-08-26 13:18:55 UTC (rev 3491)
@@ -34,17 +34,33 @@
/**
* ArchiveTestBase
*
- * Base test for all Archive service providers to help
+ * Base test for all Archive service providers to help ensure consistency between implementations.
*
+ * @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 ArchiveTestBase<T extends Archive<T>>
{
-
+ /**
+ * Get the {@link Archive} to test.
+ *
+ * @return A Archive<T> instance.
+ */
protected abstract Archive<T> getArchive();
+ /**
+ * Create a new {@link Archive} instance.
+ * <br/>
+ * Used to test Archive.add(Archive) type addings.
+ *
+ * @return A new Archive<T> instance.
+ */
+ protected abstract Archive<T> createNewArchive();
+ /**
+ * Simple printout of the tested archive.
+ */
@After
public void ls()
{
@@ -291,18 +307,13 @@
Map<Path, Asset> content = archive.getContent();
- byte[] addedData = IOUtil.asByteArray(asset.getStream());
- byte[] addedDataTwo = IOUtil.asByteArray(assetTwo.getStream());
- byte[] fetchedData = IOUtil.asByteArray(content.get(location).getStream());
- byte[] fetchedDataTwo = IOUtil.asByteArray(content.get(locationTwo).getStream());
-
Assert.assertTrue(
"Asset should existing in content with key: " + location.get(),
- Arrays.equals(addedData, fetchedData));
+ ArchiveTestUtil.compareAssets(asset, content.get(location)));
Assert.assertTrue(
"Asset should existing in content with key: " + locationTwo.get(),
- Arrays.equals(addedDataTwo, fetchedDataTwo));
+ ArchiveTestUtil.compareAssets(assetTwo, content.get(locationTwo)));
}
/**
@@ -341,4 +352,129 @@
}
}
+ /**
+ * Ensure adding content requires a source archive
+ * @throws Exception
+ */
+ @Test
+ public void testAddContentsRequiresSource() throws Exception
+ {
+ Archive<T> archive = getArchive();
+ try
+ {
+ archive.addContents(null);
+ Assert.fail("Should have throw an IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expectedException)
+ {
+ }
+ }
+
+ /**
+ * Ensure adding content from another archive successfully stores all assets
+ * @throws Exception
+ */
+ @Test
+ public void testAddContents() throws Exception
+ {
+ Archive<T> archive = getArchive();
+ Archive<T> sourceArchive = createNewArchive();
+ Path location = new BasicPath("/", "test.properties");
+ Path locationTwo = new BasicPath("/", "test2.properties");
+
+ Asset asset = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test.properties");
+ Asset assetTwo = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test2.properties");
+ sourceArchive.add(location, asset).add(locationTwo, assetTwo);
+
+ archive.addContents(sourceArchive);
+ Assert.assertTrue(
+ "Asset should have been added to path: " + location.get(),
+ ArchiveTestUtil.compareAssets(archive.get(location), asset));
+
+ Assert.assertTrue(
+ "Asset should have been added to path: " + location.get(),
+ ArchiveTestUtil.compareAssets(archive.get(locationTwo), assetTwo));
+ }
+
+ /**
+ * Ensure adding content from another archive to a path successfully stores all assets to specific path
+ * @throws Exception
+ */
+ @Test
+ public void testAddContentsToPath() throws Exception
+ {
+ Archive<T> archive = getArchive();
+ Archive<T> sourceArchive = createNewArchive();
+ Path location = new BasicPath("/", "test.properties");
+ Path locationTwo = new BasicPath("/", "test2.properties");
+
+ Asset asset = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test.properties");
+ Asset assetTwo = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test2.properties");
+ sourceArchive.add(location, asset).add(locationTwo, assetTwo);
+
+ Path baseLocation = new BasicPath("somewhere");
+
+ archive.addContents(baseLocation, sourceArchive);
+
+ Path expectedPath = new BasicPath(baseLocation, location);
+ Path expectedPathTwo = new BasicPath(baseLocation, locationTwo);
+
+ Assert.assertTrue(
+ "Asset should have been added to path: " + expectedPath.get(),
+ ArchiveTestUtil.compareAssets(archive.get(expectedPath), asset));
+
+ Assert.assertTrue(
+ "Asset should have been added to path: " + expectedPathTwo.getClass(),
+ ArchiveTestUtil.compareAssets(archive.get(expectedPathTwo), assetTwo));
+ }
+
+ /**
+ * Ensure adding content from another archive requires a path
+ * @throws Exception
+ */
+ @Test
+ public void testAddContentsToPathRequiresPath() throws Exception
+ {
+ Archive<T> archive = getArchive();
+ try
+ {
+ archive.addContents(null, createNewArchive());
+ Assert.fail("Should have throw an IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expectedException)
+ {
+ }
+ }
+
+ /**
+ * Ensure adding an archive to a path successfully stores all assets to specific path including the archive name
+ * @throws Exception
+ */
+ @Test
+ public void testAddArchiveToPath() throws Exception
+ {
+ Archive<T> archive = getArchive();
+ Archive<T> sourceArchive = createNewArchive();
+ Path location = new BasicPath("/", "test.properties");
+ Path locationTwo = new BasicPath("/", "test2.properties");
+ Asset asset = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test.properties");
+ Asset assetTwo = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test2.properties");
+ sourceArchive.add(location, asset).add(locationTwo, assetTwo);
+
+ Path baseLocation = new BasicPath("somewhere");
+
+ archive.add(baseLocation, sourceArchive);
+
+ Path expectedPath = new BasicPath(new BasicPath(baseLocation, sourceArchive.getName()), location);
+ Path expectedPathTwo = new BasicPath(new BasicPath(baseLocation, sourceArchive.getName()), locationTwo);
+
+ Assert.assertTrue(
+ "Asset should have been added to path: " + expectedPath.get(),
+ ArchiveTestUtil.compareAssets(archive.get(expectedPath), asset));
+
+ Assert.assertTrue(
+ "Asset should have been added to path: " + expectedPathTwo.get(),
+ ArchiveTestUtil.compareAssets(archive.get(expectedPathTwo), assetTwo));
+ }
+
}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestUtil.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestUtil.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestUtil.java 2009-08-26 13:18:55 UTC (rev 3491)
@@ -0,0 +1,70 @@
+/*
+ * 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.declarchive.impl.base.test;
+
+import java.util.Arrays;
+
+import org.jboss.declarchive.api.Asset;
+import org.jboss.declarchive.impl.base.io.IOUtil;
+
+/**
+ * ArchiveTestUtil
+ *
+ * Helper to compare Assets.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+class ArchiveTestUtil
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Internal constructor; should not be called
+ */
+ private ArchiveTestUtil()
+ {
+ throw new UnsupportedOperationException("No instances should be created; stateless class");
+ }
+
+ /**
+ * Compare two Asset with each other.
+ * <br/>
+ * Does not check instances but content.
+ *
+ * @param one Asset to compare
+ * @param two Asset to compare
+ * @return true if they are equal
+ */
+ static boolean compareAssets(Asset one, Asset two)
+ {
+ byte[] oneData = IOUtil.asByteArray(one.getStream());
+ byte[] twoData = IOUtil.asByteArray(two.getStream());
+
+ return Arrays.equals(oneData, twoData);
+ }
+}
Modified: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/MemoryMapArchiveTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/MemoryMapArchiveTestCase.java 2009-08-26 10:36:15 UTC (rev 3490)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/MemoryMapArchiveTestCase.java 2009-08-26 13:18:55 UTC (rev 3491)
@@ -19,11 +19,7 @@
import junit.framework.Assert;
import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.api.Path;
import org.jboss.declarchive.impl.base.MemoryMapArchiveImpl;
-import org.jboss.declarchive.impl.base.asset.ClassLoaderAsset;
-import org.jboss.declarchive.impl.base.path.BasicPath;
import org.jboss.declarchive.impl.base.test.ArchiveTestBase;
import org.jboss.declarchive.spi.MemoryMapArchive;
import org.junit.Before;
@@ -35,19 +31,34 @@
* TestCase to ensure that the MemoryMapArchive works as expected.
*
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
- * * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
public class MemoryMapArchiveTestCase extends ArchiveTestBase<MemoryMapArchive>
{
private MemoryMapArchive archive;
+ /**
+ * Create a new Archive instance pr Test.
+ *
+ * @throws Exception
+ */
@Before
public void createArchive() throws Exception
{
- archive = new MemoryMapArchiveImpl();
+ archive = createNewArchive();
}
+
+ @Override
+ protected MemoryMapArchive createNewArchive()
+ {
+ return new MemoryMapArchiveImpl();
+ }
+ /**
+ * Return the created instance to the super class
+ * so it can perform the common test cases.
+ */
@Override
protected Archive<MemoryMapArchive> getArchive()
{
@@ -82,113 +93,4 @@
{
}
}
-
-
- /**
- * Ensure adding content from another archive successfully stores all assets
- * @throws Exception
- */
- @Test
- public void testAddContents() throws Exception
- {
- MemoryMapArchive sourceArchive = new MemoryMapArchiveImpl();
- Path location = new BasicPath("/", "test.properties");
- Path locationTwo = new BasicPath("/", "test2.properties");
-
- Asset asset = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test.properties");
- Asset assetTwo = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test2.properties");
- sourceArchive.add(location, asset).add(locationTwo, assetTwo);
-
- archive.addContents(sourceArchive);
- Assert.assertEquals("Asset should have been added to path: " + location.get(), archive.get(location), asset);
- Assert.assertEquals("Asset should have been added to path: " + location.get(), archive.get(locationTwo), assetTwo);
- }
-
- /**
- * Ensure adding content requires a source archive
- * @throws Exception
- */
- @Test
- public void testAddContentsRequiresSource() throws Exception
- {
- try
- {
- archive.addContents(null);
- Assert.fail("Should have throw an IllegalArgumentException");
- }
- catch (IllegalArgumentException expectedException)
- {
- }
- }
-
- /**
- * Ensure adding content from another archive to a path successfully stores all assets to specific path
- * @throws Exception
- */
- @Test
- public void testAddContentsToPath() throws Exception
- {
- MemoryMapArchive sourceArchive = new MemoryMapArchiveImpl();
- Path location = new BasicPath("/", "test.properties");
- Path locationTwo = new BasicPath("/", "test2.properties");
-
- Asset asset = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test.properties");
- Asset assetTwo = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test2.properties");
- sourceArchive.add(location, asset).add(locationTwo, assetTwo);
-
- Path baseLocation = new BasicPath("somewhere");
-
- archive.addContents(baseLocation, sourceArchive);
-
- Path expectedPath = new BasicPath(baseLocation, location);
- Path expectedPathTwo = new BasicPath(baseLocation, locationTwo);
-
- Assert.assertEquals("Asset should have been added to path: " + expectedPath.get(), archive.get(expectedPath), asset);
- Assert.assertEquals("Asset should have been added to path: " + expectedPathTwo.getClass(), archive
- .get(expectedPathTwo), assetTwo);
- }
-
- /**
- * Ensure adding content from another archive requires a path
- * @throws Exception
- */
- @Test
- public void testAddContentsToPathRequiresPath() throws Exception
- {
- try
- {
- archive.addContents(null, new MemoryMapArchiveImpl());
- Assert.fail("Should have throw an IllegalArgumentException");
- }
- catch (IllegalArgumentException expectedException)
- {
- }
- }
-
- /**
- * Ensure adding an archive to a path successfully stores all assets to specific path including the archive name
- * @throws Exception
- */
- @Test
- public void testAddArchiveToPath() throws Exception
- {
- MemoryMapArchive sourceArchive = new MemoryMapArchiveImpl("test.jar");
- Path location = new BasicPath("/", "test.properties");
- Path locationTwo = new BasicPath("/", "test2.properties");
- Asset asset = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test.properties");
- Asset assetTwo = new ClassLoaderAsset("org/jboss/declarchive/impl/base/asset/Test2.properties");
- sourceArchive.add(location, asset).add(locationTwo, assetTwo);
-
- Path baseLocation = new BasicPath("somewhere");
-
- archive.add(baseLocation, sourceArchive);
-
- Path expectedPath = new BasicPath(new BasicPath(baseLocation, "test.jar"), location);
- Path expectedPathTwo = new BasicPath(new BasicPath(baseLocation, "test.jar"), locationTwo);
-
- Assert.assertEquals("Asset should have been added to path: " + expectedPath.get(), archive.get(expectedPath), asset);
- Assert.assertEquals("Asset should have been added to path: " + expectedPathTwo.get(), archive.get(expectedPathTwo),
- assetTwo);
- }
-
}
Modified: declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java
===================================================================
--- declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java 2009-08-26 10:36:15 UTC (rev 3490)
+++ declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java 2009-08-26 13:18:55 UTC (rev 3491)
@@ -25,10 +25,6 @@
import java.util.logging.Logger;
import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.api.Path;
-import org.jboss.declarchive.impl.base.asset.ClassAsset;
-import org.jboss.declarchive.impl.base.path.BasicPath;
import org.jboss.declarchive.impl.base.test.ArchiveTestBase;
import org.jboss.declarchive.spi.vfs.VfsArchive;
import org.jboss.virtual.VFS;
@@ -42,10 +38,9 @@
* working as expected
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
-//TODO Build upon a common test base just as the MemoryMap impl uses,
-// and swap in a method to get the VFS Memory Archive impl
public class VfsMemoryArchiveTestCase extends ArchiveTestBase<VfsArchive>
{
@@ -80,7 +75,7 @@
@Before
public void createArchive() throws Exception
{
- archive = new VfsMemoryArchiveImpl("test-" + UUID.randomUUID().toString() + ".jar");
+ archive = createNewArchive();
}
//-------------------------------------------------------------------------------------||
@@ -88,41 +83,13 @@
//-------------------------------------------------------------------------------------||
@Override
+ protected VfsArchive createNewArchive() {
+ return new VfsMemoryArchiveImpl("test-" + UUID.randomUUID().toString() + ".jar");
+ }
+
+ @Override
protected Archive<VfsArchive> getArchive()
{
return archive;
}
-
- //-------------------------------------------------------------------------------------||
- // Tests ------------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Used in building the impl, not a true test yet
- */
- //@Test
- //TODO Implement this test
- public void testMuckingAroundPrototypesNotARealTestYet() throws Exception
- {
- // Log
- log.info("testMuckingAroundPrototypesNotARealTestYet");
-
-
- // Make a virtual archive
- final VfsArchive archive = new VfsMemoryArchiveImpl("something.jar");
- final Path path = new BasicPath("something");
- archive.add(path, new ClassAsset(this.getClass()));
- final Path elsePath = new BasicPath("somethingelse");
- archive.add(elsePath, new ClassAsset(VfsMemoryArchiveImpl.class));
- log.info(archive.toString(true));
- archive.delete(elsePath);
- log.info(archive.toString(true));
- final Asset retrieved = archive.get(path);
- final boolean exists = archive.contains(path);
- log.info(path + " exists: " + exists);
- final Path fakePath = new BasicPath("shouldntexist");
- log.info(fakePath + " exists: " + archive.contains(fakePath));
- log.info(retrieved.toString());
- log.info("Contents: "+ archive.getContent());
- }
}
More information about the jboss-svn-commits
mailing list