Search in sources :

Example 81 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class GroupValidationTest method givenCenterHasMeetingWithDifferentPeriodicityGroupTransferToCenterShouldFailValidation.

@Test
public void givenCenterHasMeetingWithDifferentPeriodicityGroupTransferToCenterShouldFailValidation() {
    // setup
    MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).build();
    CenterBO toCenter = new CenterBuilder().withName("receivingCenter").with(weeklyMeeting).build();
    MeetingBO monthlyMeeting = new MeetingBuilder().customerMeeting().monthly().every(1).onDayOfMonth(1).build();
    CenterBO oldCenter = new CenterBuilder().withName("oldCenter").with(monthlyMeeting).build();
    GroupBO group = new GroupBuilder().withParentCustomer(oldCenter).build();
    // exercise test
    try {
        group.validateReceivingCenter(toCenter);
        fail("should fail validation");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_MEETING_FREQUENCY_MISMATCH));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) Test(org.junit.Test)

Example 82 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class GroupValidationTest method loanOfficerMustBeAssigned.

@Test
public void loanOfficerMustBeAssigned() {
    OfficeBO office = new OfficeBuilder().build();
    group = new GroupBuilder().withName("group-On-branch").withOffice(office).withLoanOfficer(null).buildAsTopOfHierarchy();
    try {
        group.validate();
        fail("should throw customer exception as loan officer must exist when creating group under a branch.");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_SELECT_LOAN_OFFICER));
    }
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) OfficeBO(org.mifos.customers.office.business.OfficeBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) Test(org.junit.Test)

Example 83 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class GroupValidationTest method givenCenterIsSameAsGroupsParentGroupTransferToCenterShouldFailValidation.

@Test
public void givenCenterIsSameAsGroupsParentGroupTransferToCenterShouldFailValidation() {
    // setup
    CenterBO center = new CenterBuilder().build();
    GroupBO group = new GroupBuilder().withParentCustomer(center).build();
    // exercise test
    try {
        group.validateReceivingCenter(center);
        fail("should fail validation");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_SAME_CENTER_TRANSFER));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) GroupBuilder(org.mifos.domain.builders.GroupBuilder) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) Test(org.junit.Test)

Example 84 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class GroupValidationTest method givenGroupIsTrainedButTrainedDateIsNotSetThenShouldThrowCustomerException.

@Test
public void givenGroupIsTrainedButTrainedDateIsNotSetThenShouldThrowCustomerException() {
    PersonnelBO formedBy = new PersonnelBuilder().build();
    group = new GroupBuilder().withName("group-On-center").withParentCustomer(center).formedBy(formedBy).isTrained().trainedOn(null).build();
    try {
        group.validate();
        fail("should throw customer exception as trained date must be provided if in trained state when creating group.");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.INVALID_TRAINED_OR_TRAINEDDATE));
    }
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) Test(org.junit.Test)

Example 85 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class CustomerStatusUpdateTest method throwsCheckedExceptionWhenUserDoesNotHavePermissionToUpdateCustomerStatus.

@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenUserDoesNotHavePermissionToUpdateCustomerStatus() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().build();
    CenterBO existingCenter = new CenterBuilder().withVersion(customerStatusUpdate.getVersionNum()).build();
    // stubbing
    when(customerDao.findCustomerById(customerStatusUpdate.getCustomerId())).thenReturn(existingCenter);
    doThrow(new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED)).when(customerDao).checkPermissionForStatusChange(anyShort(), eq(userContext), anyShort(), anyShort(), anyShort());
    // exercise test
    customerService.updateCustomerStatus(userContext, customerStatusUpdate);
    // verification
    verify(customerDao).checkPermissionForStatusChange(customerStatusUpdate.getNewStatus().getValue(), userContext, customerStatusUpdate.getCustomerStatusFlag().getValue(), existingCenter.getOffice().getOfficeId(), existingCenter.getPersonnel().getPersonnelId());
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerStatusUpdate(org.mifos.application.servicefacade.CustomerStatusUpdate) UserContext(org.mifos.security.util.UserContext) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) CustomerStatusUpdateBuilder(org.mifos.domain.builders.CustomerStatusUpdateBuilder) Test(org.junit.Test)

Aggregations

CustomerException (org.mifos.customers.exceptions.CustomerException)103 Test (org.junit.Test)52 UserContext (org.mifos.security.util.UserContext)29 ClientBO (org.mifos.customers.client.business.ClientBO)23 GroupBuilder (org.mifos.domain.builders.GroupBuilder)21 PersistenceException (org.mifos.framework.exceptions.PersistenceException)21 BusinessRuleException (org.mifos.service.BusinessRuleException)21 CenterBO (org.mifos.customers.center.business.CenterBO)20 GroupBO (org.mifos.customers.group.business.GroupBO)20 AccountException (org.mifos.accounts.exceptions.AccountException)18 CenterBuilder (org.mifos.domain.builders.CenterBuilder)18 ArrayList (java.util.ArrayList)17 MifosRuntimeException (org.mifos.core.MifosRuntimeException)14 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)13 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)13 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)12 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 MifosUser (org.mifos.security.MifosUser)11 DateTime (org.joda.time.DateTime)10