Search in sources :

Example 21 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class MifosMockStrutsTestCase method beforeStrutsTest.

@Before
public void beforeStrutsTest() throws Exception {
    mockStruts.setUp();
    if (!strutsConfigSet) {
        setStrutsConfig();
        strutsConfigSet = true;
    }
    getActionServlet().getServletContext().setAttribute(ShutdownManager.class.getName(), new ShutdownManager());
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) ShutdownManager(org.mifos.application.admin.system.ShutdownManager) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Example 22 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class PersonnelNoteActionStrutsTest method testSuccessCreatePersonnelNote.

@Test
public void testSuccessCreatePersonnelNote() throws Exception {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    createPersonnelAndSetInSession(getBranchOffice(), PersonnelLevel.LOAN_OFFICER);
    setRequestPathInfo("/personnelNoteAction.do");
    addRequestParameter("method", Methods.create.toString());
    addRequestParameter("personnelId", personnel.getPersonnelId().toString());
    addRequestParameter("comment", "Test");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyForward(ActionForwards.create_success.toString());
    verifyNoActionErrors();
    verifyNoActionMessages();
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 23 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class CustHistoricalDataActionStrutsTest method testUpdateHistoricalDataWhenCustHistoricalDataIsNotNull.

@Test
public void testUpdateHistoricalDataWhenCustHistoricalDataIsNotNull() throws Exception {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    createInitialObjects();
    CustomerHistoricalDataEntity customerHistoricalDataEntity = new CustomerHistoricalDataEntity(group);
    group.updateHistoricalData(customerHistoricalDataEntity);
    group.update();
    StaticHibernateUtil.flushSession();
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, group, request);
    setRequestPathInfo("/custHistoricalDataAction.do");
    addRequestParameter("method", "updateHistoricalData");
    addRequestParameter("productName", "Test");
    addRequestParameter("loanAmount", "200");
    addRequestParameter("totalAmountPaid", "150");
    addRequestParameter("interestPaid", "50");
    addRequestParameter("missedPaymentsCount", "2");
    addRequestParameter("totalPaymentsCount", "3");
    addRequestParameter("commentNotes", "Test notes");
    addRequestParameter("loanCycleNumber", "2");
    addRequestParameter("type", "Group");
    addRequestParameter("mfiJoiningDate", DateUtils.getCurrentDate(((UserContext) request.getSession().getAttribute("UserContext")).getPreferredLocale()));
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyForward(ActionForwards.updateHistoricalData_success.toString());
    verifyNoActionErrors();
    verifyNoActionMessages();
    group = TestObjectFactory.getGroup(group.getCustomerId());
    Assert.assertEquals("Test", group.getHistoricalData().getProductName());
    Assert.assertEquals("Test notes", group.getHistoricalData().getNotes());
    Assert.assertEquals(new Money(getCurrency(), "200"), group.getHistoricalData().getLoanAmount());
    Assert.assertEquals(new Money(getCurrency(), "150"), group.getHistoricalData().getTotalAmountPaid());
    Assert.assertEquals(new Money(getCurrency(), "50"), group.getHistoricalData().getInterestPaid());
    Assert.assertEquals(2, group.getHistoricalData().getMissedPaymentsCount().intValue());
    Assert.assertEquals(3, group.getHistoricalData().getTotalPaymentsCount().intValue());
    Assert.assertEquals(2, group.getHistoricalData().getLoanCycleNumber().intValue());
}
Also used : Money(org.mifos.framework.util.helpers.Money) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) UserContext(org.mifos.security.util.UserContext) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 24 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class LoanArrearsAgingHelperIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    StaticHibernateUtil.getSessionTL().clear();
    oldRoundingMode = (String) MifosConfigurationManager.getInstance().getProperty(AccountingRulesConstants.CURRENCY_ROUNDING_MODE);
    //FIXME this test was using CELLING ROUNDING MODE due to MIFOS-2659
    MifosConfigurationManager.getInstance().setProperty(AccountingRulesConstants.CURRENCY_ROUNDING_MODE, RoundingMode.CEILING.toString());
    /*
         * Takes lateness days out of the equation so that the LoanArrearsTask will set all overdue account into bad
         * standing.
         *
         * Resetting the database in tear down puts the original value back for other tests
         */
    setLatenessDaysToZero();
    LoanArrearsTask arrearsTask = new LoanArrearsTask();
    loanArrearHelper = (LoanArrearsHelper) arrearsTask.getTaskHelper();
    LoanArrearsAgingTask loanArrearsAgingTask = new LoanArrearsAgingTask();
    loanArrearsAgingHelper = (LoanArrearsAgingHelper) loanArrearsAgingTask.getTaskHelper();
    dateTime = initializeToFixedDateTime();
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Example 25 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class SavingsApplyAdjustmentActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    userContext = TestObjectFactory.getContext();
    userContext.setPreferredLocale(new Locale("en", "GB"));
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    request.getSession().setAttribute(Constants.USER_CONTEXT_KEY, userContext);
    request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
    flowKey = createFlow(request, SavingsApplyAdjustmentAction.class);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : Locale(java.util.Locale) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Aggregations

MifosUserBuilder (org.mifos.builders.MifosUserBuilder)29 MifosUser (org.mifos.security.MifosUser)29 Authentication (org.springframework.security.core.Authentication)29 SecurityContext (org.springframework.security.core.context.SecurityContext)29 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)29 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)28 Before (org.junit.Before)13 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)5 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 Money (org.mifos.framework.util.helpers.Money)4 BigDecimal (java.math.BigDecimal)3 Date (java.util.Date)3 Locale (java.util.Locale)3 LocalDate (org.joda.time.LocalDate)3 BeforeClass (org.junit.BeforeClass)3 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)3 RecurringSchedule (org.mifos.clientportfolio.loan.service.RecurringSchedule)3 CreateLoanAccount (org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount)3 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)3