@ArquillianResource private URL baseURL; @Test private void shouldDoX(@ArquillianResource URL baseURL) { }
When dealing with multiple different environments and hidden dynamic container configuration you very soon come to a point where you need access to the backing containers ip/port/context information. This is especially useful when doing remote end point testing. So instead of trying to setup all containers on the same ip/port/context, or hard code this in your test, Arquillian provides something we call @ArquillianResource injection. Via this injection point we can expose multiple internal objects.
Note that @ArquillianResource injection of URLs is currently only supported for as-client tests, not in-container tests per ARQ-540.
When you need to get a hold of the request URI (up through the context path) your Deployment defined, e.g. "http://localhost:8080/test", you can use @ArquillianResource on a field or method argument of type URL:
@ArquillianResource private URL baseURL; @Test private void shouldDoX(@ArquillianResource URL baseURL) { }
If you are deploying an EAR with multiple WARs, and you've deployed a given servlet to just one of them, you can provide the servlet's class to get the request URI up through the context path for the WAR that contains that servlet, e.g. "http://localhost:8080/test1" vs. "http://localhost:8080/test2":
@ArquillianResource(MyServlet.class) private URL baseURL; @Test private void shouldDoX(@ArquillianResource(MyServlet.class) URL baseURL) { }
Note that this version does not return the request URI to the given servlet, e.g. "http://localhost:8080/test2/MyServlet", but again just the request URI up through the context path.