Deploying a helper WAR and finding its URL
rjwalker Sep 6, 2016 1:10 AMHi, I've been using Arquillian to test part of the functionality of my web application, and it has worked well for me so far. I'm using an embedded Tomcat server as my container.
Now I want to test another part of the functionality, that relies on access to a running instance of OpenRDF Sesame, now known as RDF4J Server. What that is doesn't matter; think of it as another web application for which I have a WAR file that needs to be deployed in advance to a servlet container.
So before deploying my own test archive, I want to deploy this "helper" WAR file to the embedded Tomcat server I'm already using, and I want to configure my own web app to point to the URL of the deployed RDF4J Server.
What is "best practice" for this? (Or, I guess in the first instance I'd be helpful for any way of doing this.)
The documentation seemed to point in the direction of defining another @Deployment, thus:
/** Create deployment for OpenRDF Sesame.
* @return The OpenRDF Sesame WebArchive to be deployed prior to testing.
*/
@Deployment(name = "Sesame", order = 1)
public static WebArchive getSesameWAR() {
return ShrinkWrap.create(ZipImporter.class,
"openrdf-sesame.war").
importFrom(new File(
"openrdf-sesame.war")).
as(WebArchive.class);
}
... and then to set "order = 2" on my existing deployment:
/** Create deployment for testing.
* @return The WebArchive to be deployed for testing.
*/
@Deployment(order = 2)
public static WebArchive createTestArchive() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
.addPackages(true, .... etc. ...
So far so good, but ... inside the method createTestArchive(), how do I get the URL of the already-deployed Sesame web application? I need it in order to customize a configuration file that gets deployed as part of my test archive.
I can't see how to use injection to do this. This doesn't help:
/** URL to the deployed Sesame server. */
@ArquillianResource @OperateOnDeployment("Sesame")
private URL sesameDeploymentURL;
because @Deployment methods are static, so createTestArchive() can't refer to non-static field sesameDeploymentURL. And injected parameters are not allowed for @Deployment methods either.