/**
  * Maps the beneficiary columns in a single row to an AllocatedBeneficiary object.
  *
  * @param rs the result set with its cursor positioned at the current row
  * @return an allocated beneficiary
  * @throws SQLException an exception occurred extracting data from the result set
  */
 private Beneficiary mapBeneficiary(ResultSet rs) throws SQLException {
   String name = rs.getString("BENEFICIARY_NAME");
   MonetaryAmount savings = MonetaryAmount.valueOf(rs.getString("BENEFICIARY_SAVINGS"));
   Percentage allocationPercentage =
       Percentage.valueOf(rs.getString("BENEFICIARY_ALLOCATION_PERCENTAGE"));
   return new Beneficiary(name, allocationPercentage, savings);
 }
  @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);
  }
Beispiel #3
0
 /**
  * Validation check that returns true only if the total beneficiary allocation adds up to 100%.
  */
 @Transient
 public boolean isValid() {
   Percentage totalPercentage = Percentage.zero();
   for (Beneficiary b : beneficiaries) {
     try {
       totalPercentage = totalPercentage.add(b.getAllocationPercentage());
     } catch (IllegalArgumentException e) {
       // total would have been over 100% - return invalid
       return false;
     }
   }
   if (totalPercentage.equals(Percentage.oneHundred())) {
     return true;
   } else {
     return false;
   }
 }
  public void testFindByCreditCard() {
    Account account = repository.findByCreditCard("1234123412341234");
    // assert the returned account contains what you expect given the state of the database
    // and the Account Hibernate mapping configuration
    assertNotNull("account should never be null", account);
    assertEquals("wrong entity id", Long.valueOf(0), account.getEntityId());
    assertEquals("wrong account number", "123456789", account.getNumber());
    assertEquals("wrong name", "Keith and Keri Donald", account.getName());
    assertEquals("wrong beneficiary collection size", 2, account.getBeneficiaries().size());

    Beneficiary b1 = account.getBeneficiary("Annabelle");
    assertNotNull("Annabelle should be a beneficiary", b1);
    assertEquals("wrong savings", MonetaryAmount.valueOf("0.00"), b1.getSavings());
    assertEquals(
        "wrong allocation percentage", Percentage.valueOf("50%"), b1.getAllocationPercentage());

    Beneficiary b2 = account.getBeneficiary("Corgan");
    assertNotNull("Corgan should be a beneficiary", b2);
    assertEquals("wrong savings", MonetaryAmount.valueOf("0.00"), b2.getSavings());
    assertEquals(
        "wrong allocation percentage", Percentage.valueOf("50%"), b2.getAllocationPercentage());
  }
  /** 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>());
  }
Beispiel #6
0
 /**
  * Add a single beneficiary with a 100% allocation percentage.
  *
  * @param beneficiaryName the name of the beneficiary (should be unique)
  */
 public void addBeneficiary(String beneficiaryName) {
   addBeneficiary(beneficiaryName, Percentage.oneHundred());
 }
 public StubRestaurantRepository() {
   Restaurant restaurant = new Restaurant("1234567890", "Apple Bees");
   restaurant.setBenefitPercentage(Percentage.valueOf("8%"));
   restaurant.setBenefitAvailabilityPolicy(new AlwaysReturnsTrue());
   restaurantsByMerchantNumber.put(restaurant.getNumber(), restaurant);
 }