Search in sources :

Example 1 with CenterUpdate

use of org.mifos.dto.domain.CenterUpdate in project head by mifos.

the class CenterUpdateUsingCustomerServiceIntegrationTest method canUpdateCenterWithDifferentLoanOfficer.

@Test
public void canUpdateCenterWithDifferentLoanOfficer() throws Exception {
    // setup
    String externalId = center.getExternalId();
    String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(center.getMfiJoiningDate());
    AddressDto address = null;
    if (center.getAddress() != null) {
        address = Address.toDto(center.getAddress());
    }
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
    UserContext userContext = TestUtils.makeUser();
    otherLoanOfficer.setPreferredLocale(userContext.getLocaleId());
    IntegrationTestObjectMother.createPersonnel(otherLoanOfficer);
    String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
    CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), otherLoanOfficer.getPersonnelId(), externalId, mfiJoiningDate, address, customFields, customerPositions);
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    assertThat(center.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 2 with CenterUpdate

use of org.mifos.dto.domain.CenterUpdate in project head by mifos.

the class CenterUpdateUsingCustomerServiceIntegrationTest method canUpdateCenterWithNoLoanOfficerWhenCenterIsInactive.

@Test
public void canUpdateCenterWithNoLoanOfficerWhenCenterIsInactive() throws Exception {
    // setup
    CustomerStatusFlag centerStatusFlag = null;
    CustomerNoteEntity customerNote = null;
    customerService.updateCenterStatus(center, CustomerStatus.CENTER_INACTIVE, centerStatusFlag, customerNote);
    StaticHibernateUtil.flushAndClearSession();
    Short loanOfficerId = null;
    String externalId = center.getExternalId();
    String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(center.getMfiJoiningDate());
    AddressDto address = null;
    if (center.getAddress() != null) {
        address = Address.toDto(center.getAddress());
    }
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
    String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
    CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), loanOfficerId, externalId, mfiJoiningDate, address, customFields, customerPositions);
    UserContext userContext = TestUtils.makeUser();
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    assertThat(center.getPersonnel(), is(nullValue()));
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) CenterUpdate(org.mifos.dto.domain.CenterUpdate) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 3 with CenterUpdate

use of org.mifos.dto.domain.CenterUpdate in project head by mifos.

the class CenterUpdateUsingCustomerServiceIntegrationTest method canUpdateCenterWithExternalId.

@Test
public void canUpdateCenterWithExternalId() throws Exception {
    // setup
    Short loanOfficerId = center.getPersonnel().getPersonnelId();
    String newExternalId = "ext123";
    LocalDate dateInPast = new LocalDate(center.getMfiJoiningDate()).minusWeeks(4);
    String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(dateInPast.toDateMidnight().toDate());
    AddressDto newAddress = null;
    if (center.getAddress() != null) {
        newAddress = Address.toDto(center.getAddress());
    }
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
    String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
    CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), loanOfficerId, newExternalId, mfiJoiningDate, newAddress, customFields, customerPositions);
    UserContext userContext = TestUtils.makeUser();
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    assertThat(center.getExternalId(), is(newExternalId));
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) LocalDate(org.joda.time.LocalDate) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 4 with CenterUpdate

use of org.mifos.dto.domain.CenterUpdate in project head by mifos.

the class CenterUpdateBuilder method build.

public CenterUpdate build() {
    int versionNum = 1;
    int customerId = -1;
    Short loanOfficerId = -1;
    String externalId = null;
    String updatedDisplayName = "Center " + RandomStringUtils.random(5);
    String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(new Date());
    AddressDto address = null;
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
    return new CenterUpdate(customerId, updatedDisplayName, versionNum, loanOfficerId, externalId, mfiJoiningDate, address, customFields, customerPositions);
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 5 with CenterUpdate

use of org.mifos.dto.domain.CenterUpdate in project head by mifos.

the class CenterUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.

@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() 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 RuntimeException()).when(customerDao).save(mockedCenter);
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    verify(hibernateTransaction).rollbackTransaction();
    verify(hibernateTransaction).closeSession();
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) MifosRuntimeException(org.mifos.core.MifosRuntimeException) 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)

Aggregations

CenterUpdate (org.mifos.dto.domain.CenterUpdate)12 Test (org.junit.Test)10 UserContext (org.mifos.security.util.UserContext)10 AddressDto (org.mifos.dto.domain.AddressDto)7 SimpleDateFormat (java.text.SimpleDateFormat)6 ArrayList (java.util.ArrayList)6 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)6 CustomerPositionDto (org.mifos.dto.domain.CustomerPositionDto)6 CenterUpdateBuilder (org.mifos.domain.builders.CenterUpdateBuilder)5 LocalDate (org.joda.time.LocalDate)2 CenterBO (org.mifos.customers.center.business.CenterBO)2 CustomerException (org.mifos.customers.exceptions.CustomerException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)2 ApplicationException (org.mifos.framework.exceptions.ApplicationException)2 Date (java.util.Date)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 CustomerNoteEntity (org.mifos.customers.business.CustomerNoteEntity)1 CenterCustActionForm (org.mifos.customers.center.struts.actionforms.CenterCustActionForm)1 CustomerStatusFlag (org.mifos.customers.util.helpers.CustomerStatusFlag)1