Hello,
I'm trying to develop simple integration JAX-RS TestCase (RESTEasy) based on widely
used template class
org.jboss.as.testsuite.integration.jaxrs.packaging.war.NoApplicationIntegrationTestCase.
The main difference is that I'm trying to invoke PUT HTTP method (via put(...) method
later added to org.jboss.as.testsuite.integration.common.HttpRequest object).
Always I got error on test testPutBasic() - HTTP Status 405 (The specified HTTP method is
not allowed for the requested resource ().), test testGetBasic() passed.
Where I'm doing mistake?
Source code is like this above...
BasicPutTestCase:
import java.util.concurrent.TimeUnit;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.testsuite.integration.common.HttpRequest;
import org.jboss.as.testsuite.integration.jaxrs.packaging.war.WebXml;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
@RunAsClient
public class BasicPutTestCase {
@Deployment(testable = false)
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "jaxrsnoap.war");
war.addPackage(HttpRequest.class.getPackage());
war.addClasses(BasicPutTestCase.class, TestResource.class);
war.addAsWebInfResource(
WebXml.get(" <servlet-mapping>\n"
+ "
<servlet-name>javax.ws.rs.core.Application</servlet-name>\n"
+ " <url-pattern>/myjaxrs/*</url-pattern>\n"
+ " </servlet-mapping>\n"
+ "\n"
), "web.xml");
return war;
}
private static String performCallGet(String urlPattern) throws Exception {
return HttpRequest.get("http://localhost:8080/jaxrsnoap/" + urlPattern,
5, TimeUnit.SECONDS);
}
private static String performCallPut(String urlPattern, String message) throws Exception
{
return HttpRequest.put("http://localhost:8080/jaxrsnoap/" + urlPattern,
message,
5, TimeUnit.SECONDS);
}
@Test
public void testGetBasic() throws Exception {
String result = performCallGet("myjaxrs/basic");
Assert.assertEquals("basic", result);
}
@Test
public void testPutBasic() throws Exception {
String result = performCallPut("myjaxrs/basic", "basic");
Assert.assertEquals("", result);
}
}
TestResource:
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("basic")
public class TestResource {
private static String str = "basic1";
@GET
@Produces("text/plain")
public String get() {
return str;
}
@PUT
@Consumes("text/plain")
public void put() {
str = new String("basic2");
}
}
Cheers,
--
Pavel Janousek
Senior JBoss QA Engineer