Search in sources :

Example 6 with AuditTransactionForTests

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

the class LoanOfferingBOIntegrationTest method testUpdateLoanOfferingFeeTypesForLogging.

@Test
public void testUpdateLoanOfferingFeeTypesForLogging() throws Exception {
    createIntitalObjects();
    Date startDate = offSetCurrentDate(0);
    Date endDate = offSetCurrentDate(2);
    periodicFee = TestObjectFactory.createPeriodicAmountFee("Loan Periodic", FeeCategory.LOAN, "100", RecurrenceType.MONTHLY, (short) 1);
    List<FeeBO> fees = new ArrayList<FeeBO>();
    fees.add(periodicFee);
    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, false, 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());
    fees = new ArrayList<FeeBO>();
    oneTimeFee = TestObjectFactory.createOneTimeAmountFee("Loan One time", FeeCategory.LOAN, "100", FeePayment.UPFRONT);
    fees.add(oneTimeFee);
    product.setUserContext(TestUtils.makeUser());
    ((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, false, 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(2, auditLogList.size());
    Assert.assertEquals(EntityType.LOANPRODUCT.getValue(), auditLogList.get(0).getEntityType());
    Assert.assertEquals(14, auditLogList.get(0).getAuditLogRecords().size());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Fee Types") && auditLogRecord.getNewValue().equalsIgnoreCase("Loan Periodic")) {
            Assert.assertEquals("-", auditLogRecord.getOldValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Fee Types") && auditLogRecord.getNewValue().equalsIgnoreCase("Loan One time")) {
            Assert.assertEquals("Loan Periodic", auditLogRecord.getOldValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Service Charge deducted At Disbursement")) {
            Assert.assertEquals("1", auditLogRecord.getOldValue());
            Assert.assertEquals("0", 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 7 with AuditTransactionForTests

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

the class ClientCustActionStrutsTest method testSuccessfulUpdatePersonalInfo_AuditLog.

@Test
public void testSuccessfulUpdatePersonalInfo_AuditLog() throws Exception {
    createClientForAuditLog();
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "editPersonalInfo");
    addRequestParameter("officeId", "3");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    List<CustomFieldDto> customFieldDefs = getCustomFieldFromSession();
    List<BusinessActivityEntity> povertyStatusList = (List<BusinessActivityEntity>) SessionUtils.getAttribute(ClientConstants.POVERTY_STATUS, request);
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "previewEditPersonalInfo");
    addRequestParameter("clientName.salutation", Integer.valueOf("48").toString());
    addRequestParameter("clientName.firstName", "Diti");
    addRequestParameter("clientName.middleName", "S");
    addRequestParameter("clientName.secondLastName", "S");
    addRequestParameter("clientName.lastName", "Sharma");
    addRequestParameter("spouseName.firstName", "Abc");
    addRequestParameter("spouseName.middleName", "A");
    addRequestParameter("spouseName.secondLastName", "A");
    addRequestParameter("spouseName.lastName", "Sharma");
    addRequestParameter("spouseName.nameType", "2");
    addRequestParameter("clientDetailView.povertyStatus", povertyStatusList.get(1).getId().toString());
    addRequestParameter("clientDetailView.gender", Integer.valueOf("50").toString());
    addRequestParameter("clientDetailView.citizenship", Integer.valueOf("131").toString());
    addRequestParameter("clientDetailView.ethnicity", Integer.valueOf("219").toString());
    addRequestParameter("clientDetailView.handicapped", Integer.valueOf("139").toString());
    addRequestParameter("clientDetailView.businessActivities", "");
    addRequestParameter("clientDetailView.maritalStatus", Integer.valueOf("67").toString());
    addRequestParameter("clientDetailView.educationLevel", Integer.valueOf("227").toString());
    addRequestParameter("clientDetailView.numChildren", Integer.valueOf("2").toString());
    int i = 0;
    for (CustomFieldDto customFieldDef : customFieldDefs) {
        addRequestParameter("customField[" + i + "].fieldId", customFieldDef.getFieldId().toString());
        addRequestParameter("customField[" + i + "].fieldValue", "11");
        addRequestParameter("customField[" + i + "].fieldType", "1");
        i++;
    }
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.previewEditPersonalInfo_success.toString());
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "updatePersonalInfo");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyForward(ActionForwards.updatePersonalInfo_success.toString());
    client = TestObjectFactory.getClient(client.getCustomerId());
    Assert.assertEquals(219, client.getCustomerDetail().getEthnicity().shortValue(), DELTA);
    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());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Gender")) {
            matchValues(auditLogRecord, "Male", "Female");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Ethnicity")) {
            matchValues(auditLogRecord, "OBC", "FC");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Number Of Children")) {
            matchValues(auditLogRecord, "1", "2");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Handicapped")) {
            matchValues(auditLogRecord, "Yes", "No");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Marital Status")) {
            matchValues(auditLogRecord, "Married", "UnMarried");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Education Level")) {
            matchValues(auditLogRecord, "Both Literate", "Both Illiterate");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Poverty Status")) {
            matchValues(auditLogRecord, "Very poor", "Poor");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Citizenship")) {
            matchValues(auditLogRecord, "Hindu", "Muslim");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Business Activities")) {
            matchValues(auditLogRecord, "Trading", "-");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Salutation")) {
            matchValues(auditLogRecord, "Mr", "Mrs");
        }
    }
}
Also used : BusinessActivityEntity(org.mifos.application.master.business.BusinessActivityEntity) AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) List(java.util.List) ArrayList(java.util.ArrayList) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Test(org.junit.Test)

Example 8 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)

Example 9 with AuditTransactionForTests

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

the class SavingsActionStrutsTest method testSuccessful_Update_AuditLog.

@Test
public void testSuccessful_Update_AuditLog() throws Exception {
    createAndAddObjects(AccountState.SAVINGS_PARTIAL_APPLICATION);
    savingsOffering = null;
    addRequestParameter("recommendedAmount", "600.0");
    setRequestPathInfo("/savingsAction.do");
    addRequestParameter("method", "update");
    actionPerform();
    verifyForward("update_success");
    String globalAccountNum = (String) request.getAttribute(SavingsConstants.GLOBALACCOUNTNUM);
    Assert.assertNotNull(globalAccountNum);
    StaticHibernateUtil.flushSession();
    savings = savingsDao.findBySystemId(globalAccountNum);
    Assert.assertNotNull(savings);
    Assert.assertEquals(TestUtils.createMoney(600.0), savings.getRecommendedAmount());
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.SAVINGS, savings.getAccountId());
    Assert.assertEquals(1, auditLogList.size());
    Assert.assertEquals(EntityType.SAVINGS.getValue(), auditLogList.get(0).getEntityType());
    Assert.assertEquals(savings.getAccountId(), auditLogList.get(0).getEntityId());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Recommended Amount")) {
            matchValues(auditLogRecord, "300.0", "600.0");
        // } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Additional Information")) {
        // matchValues(auditLogRecord, "External Savings Id-custom field value", "External Savings Id-12");
        }
    }
}
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)

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