Package accounts.dao

Source Code of accounts.dao.AccountDaoTests

package accounts.dao;



import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import accounts.dao.AccountRepository;
import accounts.model.Account;
import accounts.model.Beneficiary;

import common.money.MonetaryAmount;
import common.money.Percentage;

import static org.junit.Assert.*;

/**
* Unit test for the Hibernate-based account manager implementation. Tests application behavior to verify the Account
* Hibernate mapping is correct.
*/

@ContextConfiguration(locations={"classpath:applicationContextTest.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class AccountDaoTests {

  @Autowired
  private AccountRepository accountRepository;

  @Test
  public void testFindByCreditCard() {
    Account account = accountRepository.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());
  }

}
TOP

Related Classes of accounts.dao.AccountDaoTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.