package org.jboss.resteasy.test;

import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import static org.jboss.resteasy.test.TestPortProvider.generateURL;

/**
 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
 * @version $Revision: 1 $
 */
public class NettyTest
{
   @Path("/")
   public static class Resource
   {
      @GET
      @Path("/test")
      @Produces("text/plain")
      public String hello()
      {
         return "hello world";
      }

      @GET
      @Path("/exception")
      @Produces("text/plain")
      public String exception() {
         throw new RuntimeException();
      }
   }

   @BeforeClass
   public static void setup() throws Exception
   {
      NettyContainer.start().getRegistry().addPerRequestResource(Resource.class);
   }

   @AfterClass
   public static void end() throws Exception
   {
      NettyContainer.stop();
   }

   @Test
   public void testBasic() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateURL("/test"));
      String val = target.request().get(String.class);
      Assert.assertEquals("hello world", val);
   }

   @Test
   public void testUnhandledException() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateURL("/exception"));
      Response resp = target.request().get();
      Assert.assertEquals(500, resp.getStatus());
   }
}

@@ -25,24 +25,79 @@
 sy.test;%0D%0A%0D%0A
+import org.jboss.netty.channel.ChannelHandlerContext;%0D%0A
 import org.j
@@ -136,24 +136,24 @@
 asyClient;%0D%0A
-
 import org.j
@@ -452,24 +452,58 @@
 .Produces;%0D%0A
+import javax.ws.rs.core.Context;%0D%0A
 import javax
@@ -1082,16 +1082,217 @@
       %7D%0D
+%0A%0D%0A      @GET%0D%0A      @Path(%22/context%22)%0D%0A      @Produces(%22text/plain%22)%0D%0A      public String context(@Context ChannelHandlerContext context) %7B%0D%0A          return context.getChannel().toString();%0D%0A      %7D%0D
 %0A   %7D%0D%0A%0D
@@ -2193,12 +2193,363 @@
 ;%0D%0A   %7D%0D
+%0A%0D%0A    @Test%0D%0A    public void testChannelContext() throws Exception %7B%0D%0A      ResteasyClient client = new ResteasyClientBuilder().build();%0D%0A      ResteasyWebTarget target = client.target(generateURL(%22/context%22));%0D%0A      String val = target.request().get(String.class);%0D%0A      Assert.assertNotNull(val);%0D%0A      Assert.assertFalse(val.isEmpty());%0D%0A    %7D%0D
 %0A%7D%0D%0A

Add a test for @Context with netty