My REST API works fine when deployed but my tests are failing using Jersey Arquillian extension:
@Test
@RunAsClient
public void postTest(@ArquillianResteasyResource final WebTarget webTarget) {
MyRequest request = new MyRequest();
String response = webTarget.path("/demo").request(MediaType.APPLICATION_JSON)
.post(Entity.json(request)).readEntity(String.class);
Assert.assertEquals("OK", response);
}
I get the error:
Error HTTP method POST is not supported by this URL
My JAX-RS programs look OK:
@ApplicationPath("api")
public class JaxRsActivator extends Application {
}
@Path("/demo")
@Stateless
public class DemoResource extends BaseResource {
@POST
public Response demo(MyRequest request) {
return Response.ok().entity("OK").build();
}
}
The default value for @ArquillianResteasyResource
is rest
, but my JaxRsActivator is set to api
.
To solve it I used:
@ArquillianResteasyResource("api")
To get the complete URI: webTarget.getUri()