Search in sources :

Example 31 with CustomerException

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

the class GroupValidationTest method formedByPersonnelMustBeAssigned.

@Test
public void formedByPersonnelMustBeAssigned() {
    group = new GroupBuilder().withName("group-On-center").withParentCustomer(center).formedBy(null).build();
    try {
        group.validate();
        fail("should throw customer exception as personnel that fomed group must exist when creating group.");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.INVALID_FORMED_BY));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) GroupBuilder(org.mifos.domain.builders.GroupBuilder) Test(org.junit.Test)

Example 32 with CustomerException

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

the class CustomerStatusUpdateTest method throwsCheckedExceptionWhenVersionOfCustomerForUpdateIsDifferentToPersistedCustomerVersion.

@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenVersionOfCustomerForUpdateIsDifferentToPersistedCustomerVersion() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(customerStatusUpdate.getCustomerId())).thenReturn(mockedCenter);
    doThrow(new CustomerException(Constants.ERROR_VERSION_MISMATCH)).when(mockedCenter).validateVersion(anyInt());
    // exercise test
    customerService.updateCustomerStatus(userContext, customerStatusUpdate);
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerStatusUpdate(org.mifos.application.servicefacade.CustomerStatusUpdate) UserContext(org.mifos.security.util.UserContext) CustomerStatusUpdateBuilder(org.mifos.domain.builders.CustomerStatusUpdateBuilder) Test(org.junit.Test)

Example 33 with CustomerException

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

the class GroupCreationTest method throwsCheckedExceptionWhenGroupValidationFails.

@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenGroupValidationFails() throws Exception {
    // setup
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    // stubbing
    doThrow(new CustomerException(CustomerConstants.ERRORS_SPECIFY_NAME)).when(mockedGroup).validate();
    // exercise test
    customerService.createGroup(mockedGroup, meeting, accountFees);
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 34 with CustomerException

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

the class ClientServiceFacadeWebTier method transferClientToGroup.

@Override
public String transferClientToGroup(Integer groupId, String clientGlobalCustNum, Integer previousClientVersionNo) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    ClientBO client;
    try {
        client = this.customerService.transferClientTo(userContext, groupId, clientGlobalCustNum, previousClientVersionNo);
        return client.getGlobalCustNum();
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) MifosUser(org.mifos.security.MifosUser)

Example 35 with CustomerException

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

the class CustomerServiceFacadeWebTier method search.

@Override
public CustomerSearch search(String searchString) throws ApplicationException {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    if (searchString == null) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String normalisedSearchString = org.mifos.framework.util.helpers.SearchUtils.normalizeSearchString(searchString);
    if (normalisedSearchString.equals("")) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String officeId = userContext.getBranchId().toString();
    String officeName = this.officeDao.findOfficeDtoById(userContext.getBranchId()).getName();
    PersonnelBO loggedInUser = personnelDao.findPersonnelById(userContext.getId());
    QueryResult searchResult = customerDao.search(normalisedSearchString, loggedInUser);
    return new CustomerSearch(searchResult, searchString, officeId, officeName);
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser)

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