Search in sources :

Example 81 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class CenterUpdateTest method rollsbackTransactionClosesSessionAndReThrowsApplicationException.

@Test(expected = CustomerException.class)
public void rollsbackTransactionClosesSessionAndReThrowsApplicationException() throws Exception {
    // setup
    PersonnelBO existingLoanOfficer = PersonnelBuilder.anyLoanOfficer();
    UserContext userContext = TestUtils.makeUser();
    CenterUpdate centerUpdate = new CenterUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(centerUpdate.getCustomerId())).thenReturn(mockedCenter);
    when(personnelDao.findPersonnelById(centerUpdate.getLoanOfficerId())).thenReturn(existingLoanOfficer);
    when(mockedCenter.isLoanOfficerChanged(existingLoanOfficer)).thenReturn(false);
    when(mockedCenter.getOffice()).thenReturn(new OfficeBuilder().build());
    // stub
    doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(mockedCenter).validate();
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    verify(hibernateTransaction).rollbackTransaction();
    verify(hibernateTransaction).closeSession();
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) CenterUpdateBuilder(org.mifos.domain.builders.CenterUpdateBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 82 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class CenterValidationTest method cannotCreateCenterWithoutALoanOfficer.

@Test
public void cannotCreateCenterWithoutALoanOfficer() {
    // setup
    PersonnelBO noLoanOfficer = null;
    center = new CenterBuilder().withName("center1").withLoanOfficer(noLoanOfficer).build();
    // exercise test
    try {
        center.validate();
        fail("cannotCreateCenterWithoutALoanOfficer");
    } catch (ApplicationException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_SELECT_LOAN_OFFICER));
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) Test(org.junit.Test)

Example 83 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class CustomerCreationDaoHibernateIntegrationTest method testShouldCreateCustomerAndCustomerAccount.

@Test
public void testShouldCreateCustomerAndCustomerAccount() throws Exception {
    String displayName = "centerCascade";
    Address address = null;
    final List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    final List<FeeDto> fees = new ArrayList<FeeDto>();
    final String externalId = null;
    final Date mfiJoiningDate = new DateTime().minusDays(1).toDate();
    final OfficeBO existingOffice = IntegrationTestObjectMother.sampleBranchOffice();
    final PersonnelBO loanOfficer = IntegrationTestObjectMother.testUser();
    UserContext userContext = new UserContext();
    userContext.setId(loanOfficer.getPersonnelId());
    userContext.setBranchId(existingOffice.getOfficeId());
    userContext.setBranchGlobalNum(existingOffice.getGlobalOfficeNum());
    center = new CenterBO(userContext, displayName, address, customFields, fees, externalId, mfiJoiningDate, existingOffice, weeklyMeeting, loanOfficer, new CustomerPersistence());
    StaticHibernateUtil.startTransaction();
    customerDao.save(center);
    StaticHibernateUtil.flushSession();
    assertThat(center.getCustomerAccount(), is(notNullValue()));
    assertThat(center.getGlobalCustNum(), is(nullValue()));
}
Also used : Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) FeeDto(org.mifos.accounts.fees.business.FeeDto) CenterBO(org.mifos.customers.center.business.CenterBO) Date(java.util.Date) DateTime(org.joda.time.DateTime) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) Test(org.junit.Test)

Example 84 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class CustomerTrxnDetailEntityIntegrationTest method testGenerateReverseTrxn.

@Test
public void testGenerateReverseTrxn() throws Exception {
    accountBO = client.getCustomerAccount();
    Date currentDate = new Date(System.currentTimeMillis());
    CustomerAccountBO customerAccountBO = (CustomerAccountBO) accountBO;
    customerAccountBO.setUserContext(userContext);
    CustomerScheduleEntity accountAction = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(Short.valueOf("1"));
    accountAction.setMiscFeePaid(TestUtils.createMoney(100));
    accountAction.setMiscPenaltyPaid(TestUtils.createMoney(100));
    accountAction.setPaymentDate(currentDate);
    accountAction.setPaymentStatus(PaymentStatus.PAID);
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(accountBO, TestUtils.createMoney(100), "1111", currentDate, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    CustomerTrxnDetailEntity accountTrxnEntity = new CustomerTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.PAYMENT, Short.valueOf("1"), accountAction.getActionDate(), TestObjectFactory.getPersonnel(userContext.getId()), currentDate, TestUtils.createMoney(200), "payment done", null, TestUtils.createMoney(100), TestUtils.createMoney(100));
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountAction.getAccountFeesActionDetails()) {
        CustomerAccountBOTestUtils.setFeeAmountPaid((CustomerFeeScheduleEntity) accountFeesActionDetailEntity, TestUtils.createMoney(100));
        FeesTrxnDetailEntity feeTrxn = new FeesTrxnDetailEntity(accountTrxnEntity, accountFeesActionDetailEntity.getAccountFee(), accountFeesActionDetailEntity.getFeeAmount());
        accountTrxnEntity.addFeesTrxnDetail(feeTrxn);
    }
    accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
    AccountTestUtils.addAccountPayment(accountPaymentEntity, customerAccountBO);
    PersonnelBO loggedInUser = legacyPersonnelDao.getPersonnel(userContext.getId());
    for (AccountTrxnEntity accntTrxn : customerAccountBO.findMostRecentPaymentByPaymentDate().getAccountTrxns()) {
        AccountTrxnEntity reverseAccntTrxn = ((CustomerTrxnDetailEntity) accntTrxn).generateReverseTrxn(loggedInUser, "adjustment");
        Assert.assertEquals(reverseAccntTrxn.getAmount(), accntTrxn.getAmount().negate());
        Assert.assertEquals(loggedInUser.getPersonnelId(), reverseAccntTrxn.getPersonnel().getPersonnelId());
    }
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity) Test(org.junit.Test)

Example 85 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class CustomerAccountBOIntegrationTest method testUpdateInstallmentAfterAdjustment.

@Test
public void testUpdateInstallmentAfterAdjustment() throws Exception {
    userContext = TestUtils.makeUser();
    createInitialObjects();
    applyPayment();
    customerAccountBO = TestObjectFactory.getObject(CustomerAccountBO.class, customerAccountBO.getAccountId());
    client = customerAccountBO.getCustomer();
    customerAccountBO.setUserContext(userContext);
    List<AccountTrxnEntity> reversedTrxns = AccountTestUtils.reversalAdjustment("payment adjustment done", customerAccountBO.findMostRecentPaymentByPaymentDate());
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    customerAccountBO.updateInstallmentAfterAdjustment(reversedTrxns, loggedInUser);
    for (AccountTrxnEntity accntTrxn : reversedTrxns) {
        CustomerTrxnDetailEntity custTrxn = (CustomerTrxnDetailEntity) accntTrxn;
        CustomerScheduleEntity accntActionDate = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(custTrxn.getInstallmentId());
        Assert.assertEquals("Misc Fee Adjusted", accntActionDate.getMiscFeePaid(), TestUtils.createMoney());
        Assert.assertEquals("Misc Penalty Adjusted", accntActionDate.getMiscPenaltyPaid(), TestUtils.createMoney());
    }
    for (CustomerActivityEntity customerActivityEntity : customerAccountBO.getCustomerActivitDetails()) {
        Assert.assertEquals("Amnt Adjusted", customerActivityEntity.getDescription());
    }
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Test(org.junit.Test)

Aggregations

PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)239 Test (org.junit.Test)91 UserContext (org.mifos.security.util.UserContext)65 ArrayList (java.util.ArrayList)62 Money (org.mifos.framework.util.helpers.Money)46 MifosRuntimeException (org.mifos.core.MifosRuntimeException)44 OfficeBO (org.mifos.customers.office.business.OfficeBO)44 MifosUser (org.mifos.security.MifosUser)44 PersistenceException (org.mifos.framework.exceptions.PersistenceException)41 Date (java.util.Date)39 LocalDate (org.joda.time.LocalDate)37 AccountException (org.mifos.accounts.exceptions.AccountException)37 DateTime (org.joda.time.DateTime)36 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)34 BusinessRuleException (org.mifos.service.BusinessRuleException)33 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)31 MeetingBO (org.mifos.application.meeting.business.MeetingBO)30 CustomerBO (org.mifos.customers.business.CustomerBO)27 ServiceException (org.mifos.framework.exceptions.ServiceException)27 LoanBO (org.mifos.accounts.loan.business.LoanBO)25