title: How to test Rest API with Arquillian and Mock
body: <p>I would like to test following class implements JAX-RS with CDI Injects inside.    </p>
  
  <pre><code>@Path("area")
  public class AreaService {
  
      @Inject
      @SuppressWarnings("unused")
      private Logger logger;
  
      @Context
      private SecurityContext context;
  
      @Inject
      private AreaGateway areaGateway;
  
      @GET
      @Path("{area-name}/team-project/{tp-id}")
      @Produces(MediaType.APPLICATION_JSON)
      public Response getAreaByTeamProjectAndName(@PathParam("tp-id") long tpId, @PathParam("area-name") String areaName)
              throws WebApplicationException {
  
          Area area = areaGateway.getAreaByTeamProjectAndName(tpId, areaName);
  
          return Response.status(Response.Status.OK).entity(area).build();
      }
  
      @POST
      @Path("team-project/{tp-id}")
      @Auditable
      @Consumes(MediaType.APPLICATION_JSON)
      public Response createArea(@PathParam("tp-id") long tpId, @Payload Area area) throws WebApplicationException {
          long areaId = areaGateway.createArea(tpId, area, context);
          return Response.status(Response.Status.CREATED).entity(areaId).build();
      }
  }
  </code></pre>
  
  <p>I have choosen Arquillian as test framework and I have used <a href="https://github.com/arquillian/arquillian-extension-rest" rel="nofollow noreferrer">the extension</a> for the REST APIs.</p>
  
  <p>In particular i have tried to follow the Warp REST example, but i can't find a clean and clear sample to test my REST API with mocking inject dependency like AreaGateway with any mocking framework like Mockito.</p>
  
  <p>I would like to do something like this:</p>
  
  <pre><code>@RunWith(Arquillian.class)
  public class RestClientTestCase {
  
      @ArquillianResource
      public URL contextPath;
  
  
      private AreaService areaService;
      private AreaGateway areaGateway;
  
      @Deployment(testable = false)
      public static WebArchive create() {
          WebArchive war = ShrinkWrap.create(WebArchive.class)
                  .addClasses(SLF4JProducer.class, AreaGateway.class, JAXRSActivator.class)
                  .addAsManifestResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
  
          MavenResolverSystem resolver = Maven.resolver();
          war.addAsLibraries(resolver.loadPomFromFile("pom.xml").resolve("org.mockito:mockito-all:1.10.8").withTransitivity().asSingleFile());
          return war;
      }
  
      @BeforeClass
      public static void setUpClass() {
          // initializes the rest easy client framework
          RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
      }
  
      @Before
      public void setUp() {
          areaGateway = Mockito.mock(AreaGateway.class);//real bean replaced by mocked one
          Mockito.when(areaGateway.getAreaByTeamProjectAndName(0, "areaName")).thenReturn(new Area());
  
          ResteasyClient client = new ResteasyClientBuilder().build();
          ResteasyWebTarget  target = client.target("" + "rest");
          areaService = target.proxy(AreaService.class);
      }
  
      @Test
      @RunAsClient
      public void testStockGetWarp() {
  
          Response response = areaService.getAreaByTeamProject(0);
          assertEquals("The service returned status code.", 201, response.getStatus());
          response.close();
      }
  }
  </code></pre>
  
  <p>Could someone help me to develop minimal test sample with exact Maven dependencies? Is it possible to mock CDI dependency with some framework according to Arquillian?</p>