Search in sources :

Example 11 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class ClientStatusChangeIntegrationTest method givenClientHasActiveAccountsShouldNotPassValidationWhenTryingToTranistionClientToClosed.

@Test
public void givenClientHasActiveAccountsShouldNotPassValidationWhenTryingToTranistionClientToClosed() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().with(existingMeeting).withName("Center-IntegrationTest").with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    GroupBO existingActiveGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_ACTIVE).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingActiveGroup, existingMeeting);
    ClientBO existingActiveClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_ACTIVE).withParentCustomer(existingActiveGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingActiveClient, existingMeeting);
    StaticHibernateUtil.flushAndClearSession();
    DateTime startDate = new DateTime().minusDays(14);
    LoanOfferingBO clientLoanProduct = new LoanProductBuilder().appliesToClientsOnly().withGlobalProductNumber("XXX-00002").active().withMeeting(existingMeeting).withName("Loan-client").withShortName("dsvd").withStartDate(startDate).withDefaultInterest(1.2).buildForIntegrationTests();
    IntegrationTestObjectMother.createProduct(clientLoanProduct);
    LoanBO clientLoan = new LoanAccountBuilder().withLoanProduct(clientLoanProduct).withCustomer(existingActiveClient).withOriginalLoanAmount(600.0).build();
    IntegrationTestObjectMother.saveLoanAccount(clientLoan);
    existingActiveGroup = this.customerDao.findGroupBySystemId(existingActiveGroup.getGlobalCustNum());
    existingActiveClient = this.customerDao.findClientBySystemId(existingActiveClient.getGlobalCustNum());
    existingActiveClient.setUserContext(TestUtils.makeUser());
    CustomerStatusFlag customerStatusFlag = null;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("go active", new Date(), existingActiveClient.getPersonnel(), existingActiveClient);
    // exercise test
    try {
        customerService.updateClientStatus(existingActiveClient, existingActiveClient.getStatus(), CustomerStatus.CLIENT_CLOSED, customerStatusFlag, customerNote);
        fail("should fail validation");
    } catch (CustomerException expected) {
        assertThat(expected.getKey(), is(CustomerConstants.CUSTOMER_HAS_ACTIVE_ACCOUNTS_EXCEPTION));
        assertThat(existingActiveClient.getStatus(), is(CustomerStatus.CLIENT_ACTIVE));
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) LoanAccountBuilder(org.mifos.domain.builders.LoanAccountBuilder) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanProductBuilder(org.mifos.domain.builders.LoanProductBuilder) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) DateTime(org.joda.time.DateTime) Date(java.util.Date) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) GroupBO(org.mifos.customers.group.business.GroupBO) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 12 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class ClientStatusChangeIntegrationTest method givenGroupIsInPartialStateShouldNotPassValidationWhenTryingToTranistionClientToActive.

@Test
public void givenGroupIsInPartialStateShouldNotPassValidationWhenTryingToTranistionClientToActive() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().with(existingMeeting).withName("Center-IntegrationTest").with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    GroupBO existingCancelledGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_PARTIAL).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingCancelledGroup, existingMeeting);
    ClientBO existingPartialClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_PARTIAL).withParentCustomer(existingCancelledGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingPartialClient, existingMeeting);
    existingCancelledGroup = this.customerDao.findGroupBySystemId(existingCancelledGroup.getGlobalCustNum());
    existingPartialClient = this.customerDao.findClientBySystemId(existingPartialClient.getGlobalCustNum());
    existingPartialClient.setUserContext(TestUtils.makeUser());
    CustomerStatusFlag customerStatusFlag = null;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("go active", new Date(), existingPartialClient.getPersonnel(), existingPartialClient);
    // exercise test
    try {
        customerService.updateClientStatus(existingPartialClient, existingPartialClient.getStatus(), CustomerStatus.CLIENT_ACTIVE, customerStatusFlag, customerNote);
        fail("should fail validation");
    } catch (CustomerException expected) {
        assertThat(expected.getKey(), is(ClientConstants.INVALID_CLIENT_STATUS_EXCEPTION));
        assertThat(existingPartialClient.getStatus(), is(CustomerStatus.CLIENT_PARTIAL));
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) Date(java.util.Date) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 13 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class GroupCreationUsingCustomerServiceIntegrationTest method shouldSaveAllDetailsToDoWithGroup.

@Test
public void shouldSaveAllDetailsToDoWithGroup() throws Exception {
    // setup
    Address address = new Address("line1", "line2", "line3", "city", "state", "country", "zip", "phonenumber");
    GroupBO group = new GroupBuilder().withName("newGroup").withAddress(address).withStatus(CustomerStatus.GROUP_ACTIVE).withParentCustomer(existingCenter).formedBy(existingUser).build();
    // exercise test
    customerService.createGroup(group, existingMeeting, noAccountFees);
    // verification
    assertThat(group.getDisplayName(), is("newGroup"));
    assertThat(group.getAddress().getDisplayAddress(), is("line1, line2, line3"));
    assertThat(group.getSearchId(), is("1." + group.getParentCustomer().getCustomerId() + ".3"));
    assertThat(group.getStatus(), is(CustomerStatus.GROUP_ACTIVE));
    assertThat(group.getGroupPerformanceHistory().getGroup().getCustomerId(), is(group.getCustomerId()));
    assertThat(group.getCustomFields().size(), is(0));
    assertThat(group.getMaxChildCount(), is(0));
    assertThat(existingCenter.getMaxChildCount(), is(3));
}
Also used : Address(org.mifos.framework.business.util.Address) GroupBuilder(org.mifos.domain.builders.GroupBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) Test(org.junit.Test)

Example 14 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class GroupCreationUsingCustomerServiceIntegrationTest method shouldCreateGroupAndRelatedCustomerAccountWithGlobalCustomerNumbersGenerated.

@Test
public void shouldCreateGroupAndRelatedCustomerAccountWithGlobalCustomerNumbersGenerated() throws Exception {
    // setup
    GroupBO group = new GroupBuilder().withParentCustomer(existingCenter).formedBy(existingUser).build();
    // exercise test
    customerService.createGroup(group, existingMeeting, noAccountFees);
    // verification
    assertThat(group.getCustomerId(), is(notNullValue()));
    assertThat(group.getGlobalCustNum(), is(notNullValue()));
    assertThat(group.getCustomerAccount(), is(notNullValue()));
    assertThat(group.getCustomerAccount().getAccountId(), is(notNullValue()));
    assertThat(group.getCustomerAccount().getGlobalAccountNum(), is(notNullValue()));
}
Also used : GroupBuilder(org.mifos.domain.builders.GroupBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) Test(org.junit.Test)

Example 15 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class GroupStatusChangeIntegrationTest method auditLogingTracksStatusChangeOfGroupFromActiveToCancelled.

@Test
public void auditLogingTracksStatusChangeOfGroupFromActiveToCancelled() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().withName("Center-IntegrationTest").with(existingMeeting).with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    GroupBO existingActiveGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_ACTIVE).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingActiveGroup, existingMeeting);
    ClientBO existingCancelledClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_CANCELLED).withParentCustomer(existingActiveGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingCancelledClient, existingMeeting);
    existingActiveGroup = this.customerDao.findGroupBySystemId(existingActiveGroup.getGlobalCustNum());
    existingActiveGroup.setUserContext(TestUtils.makeUserWithLocales());
    CustomerStatusFlag customerStatusFlag = CustomerStatusFlag.GROUP_CANCEL_BLACKLISTED;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("Made Inactive", new java.util.Date(), existingActiveGroup.getPersonnel(), existingActiveGroup);
    // exercise test
    customerService.updateGroupStatus(existingActiveGroup, existingActiveGroup.getStatus(), CustomerStatus.GROUP_CANCELLED, customerStatusFlag, customerNote);
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    // verification
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.GROUP, existingActiveGroup.getCustomerId());
    assertThat(auditLogList.size(), is(1));
    assertThat(auditLogList.get(0).getEntityTypeAsEnum(), is(EntityType.GROUP));
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) AuditLog(org.mifos.framework.components.audit.business.AuditLog) GroupBO(org.mifos.customers.group.business.GroupBO) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Aggregations

GroupBO (org.mifos.customers.group.business.GroupBO)84 Test (org.junit.Test)56 CenterBO (org.mifos.customers.center.business.CenterBO)45 GroupBuilder (org.mifos.domain.builders.GroupBuilder)42 CenterBuilder (org.mifos.domain.builders.CenterBuilder)36 CustomerException (org.mifos.customers.exceptions.CustomerException)23 ClientBO (org.mifos.customers.client.business.ClientBO)22 ArrayList (java.util.ArrayList)16 OfficeBO (org.mifos.customers.office.business.OfficeBO)16 MeetingBO (org.mifos.application.meeting.business.MeetingBO)15 ClientBuilder (org.mifos.domain.builders.ClientBuilder)15 DateTime (org.joda.time.DateTime)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)11 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)11 UserContext (org.mifos.security.util.UserContext)11 LocalDate (org.joda.time.LocalDate)10 MifosRuntimeException (org.mifos.core.MifosRuntimeException)10 ApplicationException (org.mifos.framework.exceptions.ApplicationException)10 Date (java.util.Date)9