[jboss-as7-dev] Integration Testsuite - HttpRequest.put problem with JAX-RS (RESTEasy)
Pavel Janousek
Pavel.Janousek at redhat.com
Mon Sep 5 11:01:27 EDT 2011
After further investigation it seems enough in put(...) method of HttpRequest class to call conn.setRequestMethod("PUT") after sequence conn.setDoInput(true);conn.setDoOutput(true);
Am I right? Does this modification break some already implemented calling of put() method as a result of changed implementation/behavior?
--
Pavel Janousek
Senior JBoss QA Engineer
----- Original Message -----
> From: "Carlo de Wolf" <cdewolf at redhat.com>
> To: "Pavel Janousek" <Pavel.Janousek at redhat.com>
> Cc: jboss-as7-dev at lists.jboss.org
> Sent: Monday, September 5, 2011 4:41:16 PM
> Subject: Re: [jboss-as7-dev] Integration Testsuite - HttpRequest.put problem with JAX-RS (RESTEasy)
> I didn't actually implement using the PUT method. It's a get with
> output.
> But yes, that is badly constructed, so using PUT should be
> implemented.
>
> Carlo
>
> On 09/05/2011 04:14 PM, Pavel Janousek wrote:
> > 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
> >
> >
> > _______________________________________________
> > jboss-as7-dev mailing list
> > jboss-as7-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
More information about the jboss-as7-dev
mailing list