コード例 #1
0
  /* post(entity) /wishlists */
  @Test
  public void testPostCheckDuplicateID() {
    Wishlist wishlist = new Wishlist();
    wishlist.setId(UUID.randomUUID().toString());
    wishlist.setOwner(TestConstants.CUSTOMER);
    instanceList.add(wishlist.getId());
    createWishlist(wishlist);

    final Response response = createWishlist(wishlist);

    Assert.assertNotNull("Response must not be null", response);
    Assert.assertEquals(
        "Should return conflict when wishlist id is already used",
        Status.CONFLICT.getStatusCode(),
        response.getStatus());
  }
コード例 #2
0
  /**
   * This method is supposed to be used as exception mapper from <code>WebApplicationException
   * </code>, sent in REST response, to <code>AuxiliaryStorageException</code>.
   *
   * @param exception Exception to convert from.
   */
  private void handleWebException(WebApplicationException exception) {

    Response response = exception.getResponse();
    if (response == null) {
      throw new AuxiliaryStorageException("Mapping exception error: response is null");
    }

    int responseStatus = response.getStatus();

    if (Status.BAD_REQUEST.getStatusCode() == responseStatus) {
      throw new IllegalParameterException("Bad request server error");
    } else if (Status.NOT_FOUND.getStatusCode() == responseStatus) {
      throw new ObjectNotFoundException("Object not found in auxiliary storage");
    } else if (Status.CONFLICT.getStatusCode() == responseStatus) {
      throw new ObjectAlreadyExistsException("Object already exists in auxiliary storage");
    } else if (Status.INTERNAL_SERVER_ERROR.getStatusCode() == responseStatus) {
      throw new AuxiliaryStorageException("Internal server error");
    } else {
      throw new AuxiliaryStorageException("Unknown server error");
    }
  }