3 Replies Latest reply on Apr 26, 2018 1:40 PM by pitchblack1408

    Arquillian REST Extension webtarget

    Seb Alkhan Newbie

      Hi,

       

      I try to use 'ArquillianResteasyResource' to inject WebTarget in my test, but WebTarget's variable remains null.

      @Test
      @Consumes(MediaType.APPLICATION_JSON)
      public void testWithWT(@ArquillianResteasyResource WebTarget webTarget) {
      ......}
      

       

      When I directly injects my class service, everything works fine!

       

      @Test
      @Consumes(MediaType.APPLICATION_JSON)
      public void testWithWT(@ArquillianResteasyResource MyService sv) {
      ......}
      

       

      my pom dependences

          <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.12</version>
         <scope>test</scope>
         </dependency>
         <dependency>
         <groupId>org.eu.ingwar.tools</groupId>
         <artifactId>arquillian-suite-extension</artifactId>
         <version>1.1.2</version>
         <scope>test</scope>
         </dependency>
         <dependency>
         <groupId>org.jboss.arquillian.junit</groupId>
         <artifactId>arquillian-junit-container</artifactId>
         <scope>test</scope>
         </dependency>
         <dependency>
         <groupId>org.wildfly.arquillian</groupId>
         <artifactId>wildfly-arquillian-container-embedded</artifactId>
         <version>1.0.1.Final</version>
         <scope>test</scope>
         </dependency>
         <dependency>
         <groupId>org.jboss.arquillian.extension</groupId>
         <artifactId>arquillian-rest-client-api</artifactId>
         <version>1.0.0.Alpha3</version>
         <scope>test</scope>
         </dependency>
         <dependency>
         <groupId>org.jboss.arquillian.extension</groupId>
         <artifactId>arquillian-rest-client-impl-3x</artifactId>
         <version>1.0.0.Alpha3</version>
         <scope>test</scope>
         </dependency>
         <dependency>
         <groupId>org.wildfly</groupId>
         <artifactId>wildfly-embedded</artifactId>
         <version>9.0.0.Final</version>
         <scope>test</scope>
         </dependency>

      what is the problem with the WebTarget ?

      any ideas ?

      Best regards

        • 1. Re: Arquillian REST Extension webtarget
          Rafael Neves Newbie

          Hi,

           

          myabe you need use ResteasyWebTarget class.

          like that:

          @Test

          public void createPackageBareRsource(@ArquillianResteasyResource("rest/customer") ResteasyWebTarget webTarget)

          {

              //        Given

              final Invocation.Builder invocationBuilder = webTarget.request();

              invocationBuilder.acceptEncoding("UTF-8");

              invocationBuilder.accept(MediaType.APPLICATION_ATOM_XML_TYPE);

              final Invocation invocation = invocationBuilder.buildPost(Entity.entity("{\"biskupa\":\"?upa\"}", MediaType.APPLICATION_JSON_TYPE));

           

              //        When

              final Response response = invocation.invoke();

           

              //        Then

              assertEquals(deploymentURL + "rest/customer", webTarget.getUri().toASCIIString());

              assertEquals(MediaType.APPLICATION_JSON, response.getMediaType().toString());

              assertEquals(HttpStatus.SC_OK, response.getStatus());

          }

           

          And your dependencies:

          <dependency>

              <groupId>org.jboss.arquillian.extension</groupId>

              <artifactId>arquillian-rest-client-api</artifactId>

              <version>1.0.0.Final-SNAPSHOT</version>

              <scope>test</scope>

          </dependency>

          <dependency>

              <groupId>org.jboss.arquillian.extension</groupId>

              <artifactId>arquillian-rest-client-impl-3x</artifactId>

              <version>1.0.0.Final-SNAPSHOT</version>

              <scope>test</scope>

          </dependency>

          <dependency>

              <groupId>org.jboss.resteasy</groupId>

              <artifactId>resteasy-jackson-provider</artifactId>

              <version>${version.resteasy}</version>

              <scope>test</scope>

          </dependency>

           

          see more here Arquillian REST Extension - Client - IT Crowd Blog

          • 2. Re: Arquillian REST Extension webtarget
            Seb Alkhan Newbie

            This changes nothing, I have the same problem with ResteasyWebTarget!

             

            • 3. Re: Arquillian REST Extension webtarget
              pitchblack1408 Newbie

              I know this is an old post and may sound silly, but I was having the same issue.  At first fixing the pom dependencies didn't seem to do anything , so I manually made NetBeans reload all dependencies from maven repo.  Then the project was able to resolve the dependencies and I was able to use the ArquillianResteasyResource annotaion.

               

               

               

                      <dependency>

                          <groupId>org.jboss.arquillian.extension</groupId>

                          <artifactId>arquillian-rest-client-api</artifactId>

                          <version>${version.arquillian.rest}</version>

                          <scope>test</scope>

                      </dependency>

                      <dependency>

                          <groupId>org.jboss.arquillian.extension</groupId>

                          <artifactId>arquillian-rest-client-impl-3x</artifactId>

                          <version>${version.arquillian.rest}</version>

                          <scope>test</scope>

                      </dependency>

                      <dependency>

                          <groupId>org.jboss.resteasy</groupId>

                          <artifactId>resteasy-jackson-provider</artifactId>

                          <version>${version.resteasy}</version>

                          <scope>test</scope>

                      </dependency>