-
Bug
-
Resolution: Duplicate
-
Critical
-
None
-
1.0.0-cr-3
-
None
When trying to include a Asset to already existing Archive path simply does nothing. Also if user does merge of two archives, it makes the operation order dependent.
Solutions:
1. Trying to include an Asset to already existing path should fail. For merge, there might be an optional override property
2. Override and make this behavior documented. Probably log a warning.
Test case:
import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import junit.framework.Assert; import org.apache.commons.io.IOUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ArchivePath; import org.jboss.shrinkwrap.api.ArchivePaths; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; public class SimpleTest { @Test // fails public void simple() throws Exception { JavaArchive jar = ShrinkWrap.create(JavaArchive.class) .add(new StringAsset("foo"), ArchivePaths.create("resources/foo")) .add(new StringAsset("bar"), ArchivePaths.create("resources/foo")); // here it should either fail fast before or contain bar Assert.assertEquals("Expecting bar", "bar", getContent(jar, ArchivePaths.create("resources/foo"))); } @Test // fails public void mergeJar1Jar2() throws Exception { JavaArchive jar1 = ShrinkWrap.create(JavaArchive.class).add(new StringAsset("foo"), ArchivePaths.create("resources/foo")); JavaArchive jar2 = ShrinkWrap.create(JavaArchive.class).add(new StringAsset("bar"), ArchivePaths.create("resources/foo")); JavaArchive jar = jar1.merge(jar2); // here it should either fail or contain bar Assert.assertEquals("Expecting bar", "bar", getContent(jar, ArchivePaths.create("resources/foo"))); } @Test // passes public void mergeJar2Jar1() throws Exception { JavaArchive jar1 = ShrinkWrap.create(JavaArchive.class).add(new StringAsset("foo"), ArchivePaths.create("resources/foo")); JavaArchive jar2 = ShrinkWrap.create(JavaArchive.class).add(new StringAsset("bar"), ArchivePaths.create("resources/foo")); JavaArchive jar = jar2.merge(jar1); // here it should either fail or contain bar Assert.assertEquals("Expecting bar", "bar", getContent(jar, ArchivePaths.create("resources/foo"))); } private String getContent(Archive<?> archive, ArchivePath path) throws IOException { InputStream is = archive.get(path).getAsset().openStream(); StringWriter w = new StringWriter(); IOUtils.copy(is, w); IOUtils.closeQuietly(is); IOUtils.closeQuietly(w); return w.toString(); } }
- duplicates
-
SHRINKWRAP-329 Arquillian should fail-fast when adding the same resource twice to an archive made with ExplodedImporter.class
- Closed