Inject webapp URL into arquillian integration tests
I really like arquillian for testing my jee projects.
Until now, when I needed to test webapp REST endpoints, I used arquillian-rest-client-api
plus one of its implementation (jersey or resteasy) and my tests were being injected with a WebTarget pointing to the webapp under test like that:
@Test
public void some_test(@ArquillianResteasyResource("endpoint") WebTarget target) {
...
}
Recently in xhub4j project, to test JAX-RS components (a ClientRequestFilter & a WriterInterceptor), I needed only the webapp URL under test to build the WebTarget by myself.
Arquillian is smart enought to also provide such injection via @ArquillianResource
:
@ArquillianResource URL deploymentURLAsClassAttribute;
@Test
public void a_test(@ArquillianResource URL deploymentURLAsParameter) {
assertNotNull(deploymentURLAsClassAttribute);
assertNotNull(deploymentURLAsParameter);
assertThat(deploymentURLAsParameter, is(deploymentURLAsClassAttribute));
assertThat(deploymentURLAsParameter.toString(), startsWith("http://"));
}