I am trying to add a resource to an Arquillian shrink-wrap archive and to load it via the classpath. However, I did not manage to make it working. I tried using addAsResource() and addAsWebInfResource(). The version below is the one I think should work, but does not. Any solutions?
import static org.junit.Assert.assertNotNull;
import java.io.InputStream;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class ResourceLoadingTest {
@Deployment
public static WebArchive createDeployment() {
WebArchive archive = ShrinkWrap.create(WebArchive.class)
.addAsWebInfResource(new StringAsset("Hello World"),
"classes/test.properties");
System.out.println(archive.toString(true));
return archive;
}
@Test
public void testLoadResource() {
InputStream stream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("/test.properties");
assertNotNull(stream);
}
}
Console output:
411ad6b1-7705-406f-ba05-d7f46ca14966.war:
/WEB-INF/
/WEB-INF/classes/
/WEB-INF/classes/test.properties