/** Creates a new Account, setting its URL as the Location header on the response. */
  @RequestMapping(value = "/accounts", method = RequestMethod.POST)
  @ResponseStatus(HttpStatus.CREATED)
  public HttpEntity<String> createAccount(
      @RequestBody Account newAccount, @Value("#{request.requestURL}") StringBuffer url) {
    Account account = accountManager.save(newAccount);

    return entityWithLocation(url, account.getEntityId());
  }
  @Test
  public void testCreateReward() throws SQLException {
    Dining dining = Dining.createDining("100.00", "1234123412341234", "0123456789");

    Account account = new Account("1", "Keith and Keri Donald");
    account.setEntityId(0L);
    account.addBeneficiary("Annabelle", Percentage.valueOf("50%"));
    account.addBeneficiary("Corgan", Percentage.valueOf("50%"));

    AccountContribution contribution = account.makeContribution(MonetaryAmount.valueOf("8.00"));
    RewardConfirmation confirmation = repository.confirmReward(contribution, dining);
    assertNotNull("confirmation should not be null", confirmation);
    assertNotNull("confirmation number should not be null", confirmation.getConfirmationNumber());
    assertEquals("wrong contribution object", contribution, confirmation.getAccountContribution());
    verifyRewardInserted(confirmation, dining);
  }
  /** Removes the Beneficiary with the given name from the Account with the given id. */
  @RequestMapping(
      value = "/accounts/{accountId}/beneficiaries/{beneficiaryName}",
      method = RequestMethod.DELETE)
  @ResponseStatus(HttpStatus.NO_CONTENT)
  public void removeBeneficiary(
      @PathVariable("accountId") long accountId,
      @PathVariable("beneficiaryName") String beneficiaryName) {
    Account account = accountManager.getAccount(accountId);
    Beneficiary b = account.getBeneficiary(beneficiaryName);

    // We ought to reset the allocation percentages, but for now we won't
    // bother. If we are removing the only beneficiary or the beneficiary
    // has an allocation of zero we don't need to worry. Otherwise, throw an
    // exception.
    if (account.getBeneficiaries().size() != 1
        || (!b.getAllocationPercentage().equals(Percentage.zero()))) {
      throw new UnsupportedOperationException(
          "Beneficiary allocation rebalancing not implemented.");
    }

    accountManager.removeBeneficiary(accountId, beneficiaryName, new HashMap<String, Percentage>());
  }
 @Test
 public void testHandleDetailsRequest() {
   Account account = controller.accountDetails(0);
   assertNotNull(account);
   assertEquals(Long.valueOf(0), account.getEntityId());
 }