Search in sources :

Example 1 with AuditTransactionForTests

use of org.mifos.framework.hibernate.helper.AuditTransactionForTests in project head by mifos.

the class LoanOfferingBOIntegrationTest method testUpdateLoanOfferingForLogging.

@Test
public void testUpdateLoanOfferingForLogging() throws ProductDefinitionException, FeeException {
    createIntitalObjects();
    Date startDate = offSetCurrentDate(0);
    Date endDate = offSetCurrentDate(2);
    periodicFee = TestObjectFactory.createPeriodicAmountFee("Loan Periodic", FeeCategory.LOAN, "100", RecurrenceType.MONTHLY, (short) 1);
    oneTimeFee = TestObjectFactory.createOneTimeAmountFee("Loan One time", FeeCategory.LOAN, "100", FeePayment.UPFRONT);
    List<FeeBO> fees = new ArrayList<FeeBO>();
    fees.add(periodicFee);
    fees.add(oneTimeFee);
    product = createLoanOfferingBO("Loan Product", "LOAP");
    ((AuditInterceptor) StaticHibernateUtil.getInterceptor()).createInitialValueMap(product);
    product.update((short) 1, "Loan Product", "LOAN", productCategory, prdApplicableMaster, startDate, endDate, "Loan Product updated", PrdStatus.LOAN_ACTIVE, null, interestTypes, (short) 0, 12.0, 2.0, 12.0, false, true, true, null, fees, null, (short) 2, RecurrenceType.MONTHLY, populateLoanPrdActionForm("1", "1", new Double("3000"), new Double("1000"), new Double("1000"), "12", "1", "2"), waiverInterest, null);
    StaticHibernateUtil.flushAndClearSession();
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    product = (LoanOfferingBO) TestObjectFactory.getObject(LoanOfferingBO.class, product.getPrdOfferingId());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.LOANPRODUCT, new Integer(product.getPrdOfferingId().toString()));
    Assert.assertEquals(1, auditLogList.size());
    Assert.assertEquals(EntityType.LOANPRODUCT.getValue(), auditLogList.get(0).getEntityType());
    Assert.assertEquals(15, auditLogList.get(0).getAuditLogRecords().size());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Min Loan Amount")) {
            Assert.assertEquals("300.0", auditLogRecord.getOldValue());
            Assert.assertEquals("1000.0", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Description")) {
            Assert.assertEquals("-", auditLogRecord.getOldValue());
            Assert.assertEquals("Loan Product updated", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Applicable For")) {
            Assert.assertEquals("Groups", auditLogRecord.getOldValue());
            Assert.assertEquals("Clients", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Frequency Of Installments")) {
            Assert.assertEquals("Week(s)", auditLogRecord.getOldValue());
            Assert.assertEquals("Month(s)", auditLogRecord.getNewValue());
        }
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) ArrayList(java.util.ArrayList) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) Date(java.sql.Date) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Test(org.junit.Test)

Example 2 with AuditTransactionForTests

use of org.mifos.framework.hibernate.helper.AuditTransactionForTests 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)

Example 3 with AuditTransactionForTests

use of org.mifos.framework.hibernate.helper.AuditTransactionForTests in project head by mifos.

the class ClientTransferActionStrutsTest method testSuccessful_transferToBranch_AuditLog.

@Test
public void testSuccessful_transferToBranch_AuditLog() throws Exception {
    createObjectsForClientTransfer();
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, client, request);
    setRequestPathInfo("/clientTransferAction.do");
    addRequestParameter("method", "transferToBranch");
    addRequestParameter("officeId", office.getOfficeId().toString());
    addRequestParameter("officeName", office.getOfficeName());
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyForward(ActionForwards.update_success.toString());
    verifyNoActionErrors();
    verifyNoActionMessages();
    client = TestObjectFactory.getClient(client.getCustomerId());
    Assert.assertEquals(client.getOffice().getOfficeId(), office.getOfficeId());
    Assert.assertEquals(CustomerStatus.CLIENT_HOLD, client.getStatus());
    office = client.getOffice();
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.CLIENT, client.getCustomerId());
    Assert.assertEquals(1, auditLogList.size());
    Assert.assertEquals(EntityType.CLIENT.getValue(), auditLogList.get(0).getEntityType());
    Assert.assertEquals(client.getCustomerId(), auditLogList.get(0).getEntityId());
    Assert.assertEquals(3, auditLogList.get(0).getAuditLogRecords().size());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Loan Officer Assigned")) {
            matchValues(auditLogRecord, "mifos", "-");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Status")) {
            matchValues(auditLogRecord, "Active", "On Hold");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Branch Office Name")) {
            matchValues(auditLogRecord, "TestBranchOffice", "customer_office");
        }
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Test(org.junit.Test)

Example 4 with AuditTransactionForTests

use of org.mifos.framework.hibernate.helper.AuditTransactionForTests in project head by mifos.

the class CenterStatusChangeIntegrationTest method auditLogingTracksStatusChangeOfCenterFromActiveToInactive.

@Test
public void auditLogingTracksStatusChangeOfCenterFromActiveToInactive() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().withName("Center-IntegrationTest").with(existingMeeting).with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    GroupBO existingPendingGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_CANCELLED).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingPendingGroup, existingMeeting);
    ClientBO existingCancelledClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_CANCELLED).withParentCustomer(existingPendingGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingCancelledClient, existingMeeting);
    existingCenter = this.customerDao.findCenterBySystemId(existingCenter.getGlobalCustNum());
    existingPendingGroup = this.customerDao.findGroupBySystemId(existingPendingGroup.getGlobalCustNum());
    existingCancelledClient = this.customerDao.findClientBySystemId(existingCancelledClient.getGlobalCustNum());
    existingCenter.setUserContext(TestUtils.makeUserWithLocales());
    CustomerStatusFlag customerStatusFlag = null;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("go inactive", new Date(), existingCenter.getPersonnel(), existingCenter);
    // exercise test
    customerService.updateCenterStatus(existingCenter, CustomerStatus.CENTER_INACTIVE, customerStatusFlag, customerNote);
    // verification
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.CENTER, existingCenter.getCustomerId());
    assertThat(auditLogList.size(), is(1));
    assertThat(auditLogList.get(0).getEntityTypeAsEnum(), is(EntityType.CENTER));
}
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) GroupBO(org.mifos.customers.group.business.GroupBO) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) Date(java.util.Date) AuditLog(org.mifos.framework.components.audit.business.AuditLog) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 5 with AuditTransactionForTests

use of org.mifos.framework.hibernate.helper.AuditTransactionForTests in project head by mifos.

the class AuditInterceptorIntegrationTest method testUpdateLoanForLogging.

/*
     * Note: since this loan is active the disbursement date will not be updated
     */
@Test
public void testUpdateLoanForLogging() throws Exception {
    Date newDate = incrementCurrentDate(14);
    accountBO = getLoanAccount();
    accountBO.setUserContext(TestUtils.makeUser());
    ((AuditInterceptor) StaticHibernateUtil.getInterceptor()).createInitialValueMap(accountBO);
    LoanBO loanBO = ((LoanBO) accountBO);
    ((LoanBO) accountBO).updateLoan(true, loanBO.getLoanAmount(), loanBO.getInterestRate(), loanBO.getNoOfInstallments(), newDate, (short) 2, TestObjectFactory.SAMPLE_BUSINESS_ACTIVITY_2, "Added note", null, null, false, null, null);
    StaticHibernateUtil.flushSession();
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId());
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.LOAN, accountBO.getAccountId());
    Assert.assertEquals(1, auditLogList.size());
    Assert.assertEquals(EntityType.LOAN.getValue(), auditLogList.get(0).getEntityType());
    Assert.assertEquals(3, auditLogList.get(0).getAuditLogRecords().size());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Collateral Notes")) {
            Assert.assertEquals("-", auditLogRecord.getOldValue());
            Assert.assertEquals("Added note", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Service Charge deducted At Disbursement")) {
            Assert.assertEquals("1", auditLogRecord.getOldValue());
            Assert.assertEquals("0", auditLogRecord.getNewValue());
        }
    }
    accountBO = null;
    group = null;
    center = null;
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) LoanBO(org.mifos.accounts.loan.business.LoanBO) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) Date(java.util.Date) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 AuditLog (org.mifos.framework.components.audit.business.AuditLog)9 AuditTransactionForTests (org.mifos.framework.hibernate.helper.AuditTransactionForTests)9 AuditLogRecord (org.mifos.framework.components.audit.business.AuditLogRecord)7 AuditInterceptor (org.mifos.framework.components.audit.util.helpers.AuditInterceptor)4 Date (java.sql.Date)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 CustomerNoteEntity (org.mifos.customers.business.CustomerNoteEntity)2 CenterBO (org.mifos.customers.center.business.CenterBO)2 ClientBO (org.mifos.customers.client.business.ClientBO)2 GroupBO (org.mifos.customers.group.business.GroupBO)2 CustomerStatusFlag (org.mifos.customers.util.helpers.CustomerStatusFlag)2 CenterBuilder (org.mifos.domain.builders.CenterBuilder)2 ClientBuilder (org.mifos.domain.builders.ClientBuilder)2 GroupBuilder (org.mifos.domain.builders.GroupBuilder)2 List (java.util.List)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1