4 Replies Latest reply on Dec 8, 2014 7:04 AM by fenoloco

    Arquilian + Warp + RestEasy gives a http method required error on Wait()

    Wessel Pieterse Newbie

      Hi

       

      Im attempting to test JAX-RS RESTEasy 2.3.5 endpoints on Jboss AS 7.1.1 Final with arquilian and WARP

       

      My test looks like this:

       

       

      @WarpTest

      @RunWith(Arquillian.class)

      public class ProductEndPointTest {

       

       

          //the prefix sepcified in web.xml for the resource

          private static final String RESOURCE_PREFIX = "resource";

       

       

       

       

          //the deployment url

          @ArquillianResource

          private URL deploymentURL;

       

       

          @Context

          private UriInfo uriInfo;

       

       

       

       

          @Deployment

          @OverProtocol("Servlet 3.0")

          public static WebArchive create()

          {

              return ShrinkWrap.create(WebArchive.class, "test.war")

                      //persistance

                      .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")

                      //for logging

                      .addAsResource("log4j.properties", "log4j.properties")

                      //web.xml

                      .setWebXML("WEB-INF/test-web.xml")

                      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")

                      .addPackage(Product.class.getPackage())

                      .addPackage(Product.class.getPackage())

                      .addPackage(User.class.getPackage())

                      .addPackage(Payment.class.getPackage())

                      .addPackage(Unit.class.getPackage())

                      .addPackage(OrderItem.class.getPackage())

                      .addPackage(Transaction.class.getPackage())

                      .addPackage(GenericJPADao.class.getPackage())

                      .addClasses(OperationFailedException.class)

                      .addClasses( GenericJPADao.class, GenericDao.class, Product.class, Unit.class, Stampable.class, User.class, SoftRemovable.class)

                      .addClasses(UserUnitLinks.class)

                      .addClasses(PaymentGatewayInstance.class, ProductCustomOption.class, ProductCustomAttribute.class, ProductCustomExtra.class)

                      .addClasses(Role.class, Permission.class, Groups.class, Account.class, AssetType.class, PaymentGateway.class, NewRelicInterceptor.class, ContentTypeExceptionHandler.class)

                      .addAsLibraries(

                              Maven.resolver().resolve("org.apache.shiro:shiro-core:1.2.0",

                                      "org.apache.shiro:shiro-web:1.2.0",

                                      "com.jayway.restassured:rest-assured:1.6.2",

                                      "org.json:json:20080701").withTransitivity().asFile()

                      );

       

       

       

       

      //        DependencyResolvers.use(MavenDependencyResolver.class)

      //                                .artifact("org.apache.shiro:shiro-core:1.2.0")

      //                                .artifact("org.apache.shiro:shiro-web:1.2.0")

      //                                .artifact("com.jayway.restassured:rest-assured:1.6.2")

      //                                .artifact("org.json:json:20080701")

      //                                .resolveAsFiles());

          }

       

       

       

       

          @BeforeClass

          public static void initResteasyClient() {

              RegisterBuiltin.register(ResteasyProviderFactory.getInstance());

       

       

          }

       

       

          /**

           * The service client.

           */

          private ProductEndPoint productEndPoint;

       

       

          @Before

          public void setUp() {

       

       

              productEndPoint = ProxyFactory.create(ProductEndPoint.class, deploymentURL + "RESOURCE_PREFIX");

       

       

          }

       

       

          @Test

          @RunAsClient

          public void testFindAll() {

       

       

       

       

              // uris.getAbsolutePathBuilder().path("/{id}").build(id);

              final CreateProductDto product = createProduct();

              ClientResponse response = (ClientResponse) productEndPoint.createProduct(product,uriInfo);

              response.releaseConnection();

       

       

       

       

              Warp.initiate(new Activity() {

                  @Override

                  public void perform() {

       

       

                      List<ProductCustomDto> result = productEndPoint.findAll(1, 10);

       

       

                      Assert.assertNotNull("Product has valid id.", result.get(1).getId());

                      assertEquals("Product has invalid name", product.getName().toString(), result.get(1).getName());

                      assertEquals("Product has invalid short description", product.getPrice().toString(), result.get(1).getDescription());

                      assertEquals("Product has invalid description", product.getDescription().toString(), result.get(1).getDescription());

                      assertEquals("Product has invalid price ", product.getPrice().toString(), result.get(1).getPrice());

                      assertEquals("Product has invalid availability", product.getAvailable().toString(), result.get(1).getAvailable());

                  }

              }).inspect(new Inspection() {

       

       

                  private static final long serialVersionUID = 1L;

       

       

                  @ArquillianResource

                  private RestContext restContext;

       

       

       

       

                  @AfterServlet

                  public void testGetStock() {

       

       

                      assertEquals(HttpMethod.GET, restContext.getHttpRequest().getMethod());

                      assertEquals(200, restContext.getHttpResponse().getStatusCode());

                      assertEquals("application/json", restContext.getHttpResponse().getContentType());

                      assertNotNull(restContext.getHttpResponse().getEntity());

                  }

              });

          }

      }

       

      And my Endpoint looks like:

      @Path("/product")

      @Api(value = "/product", description = "To manage the Product")

      public class ProductEndPoint {

       

       

          @EJB

          private ProductFacade facade;

       

       

          @EJB

          private ProductDao productDao;

        

          private Logger log = LoggerFactory.getLogger(ProductEndPoint.class);

        

          @Path("/item")

          @GET

          @RequiresPermissions({"find:all"})

          @ApiOperation(value = "returns all the Product", notes = "returns all the Product", response =  Product.class, responseContainer="List")

          public List<ProductCustomDto> findAll(

          @ApiParam(value = "the current page number", required = true) @QueryParam("page") @DefaultValue("1") int page,

          @ApiParam(value = "the amount of records per page", required = true) @QueryParam("pagesize") @DefaultValue("20") int pagesize) {

       

       

              List<Product> items = productDao.findAllOnPage(page, pagesize);

       

       

              //Covert list

              DtoConverter<Product,ProductCustomDto> converter = new DtoConverter<Product, ProductCustomDto>(ProductCustomDto.class);

              List<ProductCustomDto> entity = converter.convertList(items);

       

       

              return entity;

          }

       

       

          @POST

          @Path("/item")

          @RequiresPermissions({"product:create"})

          @ApiOperation(value = "Create Product", notes = "Create Product", response =  Response.class)

       

       

          public Response createProduct(@ApiParam(value = "Information for Product to be created", required = true) CreateProductDto dto, @Context UriInfo uris) {

              try {

                  // TODO use Wessel's conversion code to convert from DTO to object

                  DtoConverter<CreateProductDto,Product> converter = new DtoConverter<CreateProductDto, Product>(Product.class);

                  Product entity = converter.convert(dto);

       

       

                  facade.create(entity);

       

       

                  final Long id = entity.getId();

                  final URI location = uris.getAbsolutePathBuilder().path("/{id}").build(id);

                  return Response.created(location).build();

              } catch (Exception ex) {

                  ServiceStatusMessage statusMessage = new ServiceStatusMessage(ServiceStatusMessage.Kind.ERROR, ex.getMessage());

                  return Response.status(Response.Status.CONFLICT).entity(statusMessage).build();

              }

          }

      }

       

      And the error

      java.lang.RuntimeException: You must use at least one, but no more than one http method annotation on: public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException

        at org.jboss.resteasy.client.ProxyFactory.createClientInvoker(ProxyFactory.java:86)

        at org.jboss.resteasy.client.ProxyBuilder.createProxy(ProxyBuilder.java:144)

        at org.jboss.resteasy.client.ProxyBuilder.now(ProxyBuilder.java:124)

        at org.jboss.resteasy.client.ProxyFactory.create(ProxyFactory.java:68)

        at org.jboss.resteasy.client.ProxyFactory.create(ProxyFactory.java:63)

        at org.jboss.resteasy.client.ProxyFactory.create(ProxyFactory.java:58)

        at org.jboss.resteasy.client.ProxyFactory.create(ProxyFactory.java:41)

        at org.jboss.resteasy.client.ProxyFactory.create(ProxyFactory.java:26)

        at com.unijunction.ordercloud.product.rest.ProductEndPointTest.setUp(ProductEndPointTest.java:136)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)

        at org.jboss.arquillian.junit.Arquillian$StatementLifecycleExecutor.invoke(Arquillian.java:351)

        at org.jboss.arquillian.container.test.impl.execution.ClientBeforeAfterLifecycleEventExecuter.execute(ClientBeforeAfterLifecycleEventExecuter.java:99)

        at org.jboss.arquillian.container.test.impl.execution.ClientBeforeAfterLifecycleEventExecuter.on(ClientBeforeAfterLifecycleEventExecuter.java:72)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)

        at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createBeforeContext(ContainerEventController.java:124)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)

        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.before(EventTestRunnerAdaptor.java:95)

        at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:222)

        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)

        at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)

        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)

        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)

       

      Any help would greatly be appreciated.