コード例 #1
0
  public static <T> T post(Object requestObject, Class<T> responseClass, String path) {
    try {

      jerseyWebTarget.path(path);

      Response response =
          jerseyWebTarget
              .request(MediaType.APPLICATION_JSON_TYPE)
              .post(Entity.entity(requestObject, MediaType.APPLICATION_JSON_TYPE));

      if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      System.out.println("Output from Service for path " + path + " .... \n");
      T output = response.readEntity(responseClass);
      System.out.println(ToStringBuilder.reflectionToString(output));

      return output;
    } catch (Exception e) {

      e.printStackTrace();
      return null;
    }
  }
コード例 #2
0
  /**
   * We can inject either proxy or a WebTarget for low level manipulations and assertions.
   *
   * @param webTarget configured resource ready for use, injected by Arquillian
   */
  @Test
  public void createCustomerBareJAXRSResource(
      @ArquillianResteasyResource("rest/customer") JerseyWebTarget webTarget) {
    //        Given
    final Invocation.Builder invocationBuilder = webTarget.request();
    final Invocation invocation =
        invocationBuilder.buildPost(Entity.entity(new Customer(), 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(200, response.getStatus());
  }