Search in sources :

Example 6 with AuditInterceptor

use of org.mifos.framework.components.audit.util.helpers.AuditInterceptor 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 7 with AuditInterceptor

use of org.mifos.framework.components.audit.util.helpers.AuditInterceptor in project head by mifos.

the class SavingsOfferingBOIntegrationTest method testUpdateSavingsOfferingForLogging.

@Test
public void testUpdateSavingsOfferingForLogging() throws Exception {
    String name = "Savings_offering";
    String newName = "Savings_offeringChanged";
    String shortName = "S";
    String newShortName = "S1";
    PrdApplicableMasterEntity prdApplicableMaster = new PrdApplicableMasterEntity(ApplicableTo.CLIENTS);
    SavingsTypeEntity savingsType = new SavingsTypeEntity(SavingsType.MANDATORY);
    InterestCalcTypeEntity intCalType = new InterestCalcTypeEntity(InterestCalcType.AVERAGE_BALANCE);
    MeetingBO intCalcMeeting = getMeeting();
    MeetingBO intPostMeeting = getMeeting();
    ProductCategoryBO productCategory = (ProductCategoryBO) TestObjectFactory.getObject(ProductCategoryBO.class, (short) 2);
    Date startDate = offSetCurrentDate(0);
    Date endDate = offSetCurrentDate(7);
    savingsProduct = createSavingsOfferingBO(name, shortName, ApplicableTo.CLIENTS, startDate, PrdStatus.SAVINGS_ACTIVE, SavingsType.VOLUNTARY, InterestCalcType.MINIMUM_BALANCE);
    savingsProduct.setUserContext(TestUtils.makeUserWithLocales());
    ((AuditInterceptor) StaticHibernateUtil.getInterceptor()).createInitialValueMap(savingsProduct);
    savingsProduct.update(Short.valueOf("1"), newName, newShortName, productCategory, prdApplicableMaster, startDate, endDate, "Desc", PrdStatus.SAVINGS_INACTIVE, null, savingsType, intCalType, intCalcMeeting, intPostMeeting, new Money(getCurrency(), "10"), new Money(getCurrency(), "100"), new Money(getCurrency(), "1"), 10.0);
    StaticHibernateUtil.flushSession();
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    savingsProduct = (SavingsOfferingBO) TestObjectFactory.getObject(SavingsOfferingBO.class, savingsProduct.getPrdOfferingId());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.SAVINGSPRODUCT, new Integer(savingsProduct.getPrdOfferingId().toString()));
    Assert.assertEquals(1, auditLogList.size());
    Assert.assertEquals(EntityType.SAVINGSPRODUCT, auditLogList.get(0).getEntityTypeAsEnum());
    Set<AuditLogRecord> records = auditLogList.get(0).getAuditLogRecords();
    Assert.assertEquals(12, records.size());
    for (AuditLogRecord auditLogRecord : records) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Balance used for Interest rate calculation")) {
            Assert.assertEquals("Minimum Balance", auditLogRecord.getOldValue());
            Assert.assertEquals("Average Balance", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Status")) {
            Assert.assertEquals("Active", auditLogRecord.getOldValue());
            Assert.assertEquals("Inactive", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Type Of Deposits")) {
            Assert.assertEquals("Voluntary", auditLogRecord.getOldValue());
            Assert.assertEquals("Mandatory", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Service Charge Rate")) {
            Assert.assertEquals("1.2", auditLogRecord.getOldValue());
            Assert.assertEquals("10.0", auditLogRecord.getNewValue());
        } else {
        // What are the others?
        }
    }
}
Also used : AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) MeetingBO(org.mifos.application.meeting.business.MeetingBO) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) Date(java.sql.Date) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Money(org.mifos.framework.util.helpers.Money) AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) Test(org.junit.Test)

Example 8 with AuditInterceptor

use of org.mifos.framework.components.audit.util.helpers.AuditInterceptor 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)

Aggregations

AuditInterceptor (org.mifos.framework.components.audit.util.helpers.AuditInterceptor)8 Test (org.junit.Test)4 AuditLog (org.mifos.framework.components.audit.business.AuditLog)4 AuditLogRecord (org.mifos.framework.components.audit.business.AuditLogRecord)4 AuditTransactionForTests (org.mifos.framework.hibernate.helper.AuditTransactionForTests)4 Date (java.sql.Date)3 ArrayList (java.util.ArrayList)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 Date (java.util.Date)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 MeetingBO (org.mifos.application.meeting.business.MeetingBO)1 Money (org.mifos.framework.util.helpers.Money)1