Search in sources :

Example 11 with Flow

use of org.mifos.framework.util.helpers.Flow in project head by mifos.

the class FlowKeyInterceptor method createToken.

private void createToken(HttpServletRequest request) {
    String flowKey = String.valueOf(new DateTimeService().getCurrentDateTime().getMillis());
    FlowManager flowManager = (FlowManager) request.getSession().getAttribute(Constants.FLOWMANAGER);
    if (flowManager == null) {
        flowManager = new FlowManager();
        request.getSession(false).setAttribute(Constants.FLOWMANAGER, flowManager);
    }
    flowManager.addFLow(flowKey, new Flow(), this.getClass().getName());
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
}
Also used : FlowManager(org.mifos.framework.util.helpers.FlowManager) DateTimeService(org.mifos.framework.util.DateTimeService) Flow(org.mifos.framework.util.helpers.Flow)

Example 12 with Flow

use of org.mifos.framework.util.helpers.Flow in project head by mifos.

the class LoanPrdActionTest method shouldSetSelectedQuestionGroupsOnSession.

@Test
public void shouldSetSelectedQuestionGroupsOnSession() throws PageExpiredException {
    List<QuestionGroupDetail> questionGroupDetails = asList(getQuestionGroupDetail(1, "QG1", true), getQuestionGroupDetail(2, "QG2", true), getQuestionGroupDetail(3, "QG3", false));
    when(questionnaireServiceFacade.getQuestionGroupDetailForLoanPrd(1)).thenReturn(questionGroupDetails.get(0));
    when(questionnaireServiceFacade.getQuestionGroupDetailForLoanPrd(2)).thenReturn(questionGroupDetails.get(1));
    when(questionnaireServiceFacade.getQuestionGroupDetailForLoanPrd(3)).thenReturn(questionGroupDetails.get(2));
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    Flow flow = new Flow();
    when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    LoanOfferingBO loanOfferingBO = new LoanProductBuilder().buildForUnitTests();
    loanOfferingBO.setQuestionGroups(getQustionGroups(1, 2, 3));
    loanPrdAction.setSelectedQuestionGroupsOnSession(request, loanOfferingBO, questionnaireServiceFacade);
    List<QuestionGroupDetail> questionGroupDetailList = (List<QuestionGroupDetail>) flow.getObjectFromSession(ProductDefinitionConstants.SELECTEDQGLIST);
    assertThat(questionGroupDetailList, is(notNullValue()));
    assertThat(questionGroupDetailList.size(), is(2));
    assertQuestionGroup(questionGroupDetailList.get(0), 1, "QG1");
    assertQuestionGroup(questionGroupDetailList.get(1), 2, "QG2");
    verify(questionnaireServiceFacade, times(3)).getQuestionGroupDetailForLoanPrd(anyInt());
    verify(request, times(1)).getAttribute(Constants.CURRENTFLOWKEY);
    verify(request, times(1)).getSession();
    verify(session, times(1)).getAttribute(Constants.FLOWMANAGER);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) LoanProductBuilder(org.mifos.domain.builders.LoanProductBuilder) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Flow(org.mifos.framework.util.helpers.Flow) Test(org.junit.Test)

Example 13 with Flow

use of org.mifos.framework.util.helpers.Flow in project head by mifos.

the class LoanPrdActionFormTest method shouldNotAllowPeriodicFeeForVariableInstallmentLoanProduct.

@Test
public void shouldNotAllowPeriodicFeeForVariableInstallmentLoanProduct() {
    String PERIODIC_FEE_2 = "2";
    String NON_PERIODIC_FEE = "3";
    when(periodicFeeRate.isPeriodic()).thenReturn(true);
    when(periodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
    when(periodicFeeRate.getFeeId()).thenReturn(Short.valueOf(PERIODIC_FEE_2));
    when(periodicFeeRate.getFeeName()).thenReturn("periodic fee2");
    when(nonPeriodicFeeRate.isPeriodic()).thenReturn(false);
    when(nonPeriodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
    when(nonPeriodicFeeRate.getFeeId()).thenReturn(Short.valueOf(NON_PERIODIC_FEE));
    when(nonPeriodicFeeRate.getFeeName()).thenReturn("non Periodic fee");
    when(((RateFeeBO) nonPeriodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity);
    when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST);
    List<FeeBO> allPrdFees = new ArrayList<FeeBO>();
    allPrdFees.add(periodicFeeRate);
    allPrdFees.add(nonPeriodicFeeRate);
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    when(session.getAttribute(ProductDefinitionConstants.LOANPRDFEE)).thenReturn(allPrdFees);
    Flow flow = new Flow();
    try {
        when(flowManager.getFromFlow(Mockito.anyString(), Mockito.anyString())).thenReturn(allPrdFees);
        when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    } catch (PageExpiredException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    ActionMessageMatcher actionMessageMatcher = new ActionMessageMatcher(ProductDefinitionConstants.PERIODIC_FEE_NOT_APPLICABLE);
    loanPrdActionForm.setCanConfigureVariableInstallments(true);
    loanPrdActionForm.setPrdOfferinFees(new String[] { PERIODIC_FEE_2, NON_PERIODIC_FEE });
    loanPrdActionForm.validateSelectedFeeForVariableInstallment(request, errors);
    Mockito.verify(errors, Mockito.times(1)).add(Mockito.anyString(), Mockito.argThat(actionMessageMatcher));
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Flow(org.mifos.framework.util.helpers.Flow) Test(org.junit.Test)

Example 14 with Flow

use of org.mifos.framework.util.helpers.Flow in project head by mifos.

the class SavingsAccountActionTest method shouldSetQuestionGroupInstanceDetailsInSession.

@Test
public void shouldSetQuestionGroupInstanceDetailsInSession() throws PageExpiredException {
    List<QuestionGroupInstanceDetail> instanceDetails = asList(getQuestionGroupInstanceDetail("QG1"), getQuestionGroupInstanceDetail("QG2"));
    when(questionnaireServiceFacade.getQuestionGroupInstances(101, "View", "Savings")).thenReturn(instanceDetails);
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    Flow flow = new Flow();
    when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    savingsAccountAction.setQuestionGroupInstances(questionnaireServiceFacade, request, 101);
    assertThat((List<QuestionGroupInstanceDetail>) flow.getObjectFromSession("questionGroupInstances"), is(instanceDetails));
    verify(questionnaireServiceFacade, times(1)).getQuestionGroupInstances(101, "View", "Savings");
    verify(request, times(1)).getAttribute(Constants.CURRENTFLOWKEY);
    verify(request, times(1)).getSession();
    verify(session, times(1)).getAttribute(Constants.FLOWMANAGER);
}
Also used : QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) Flow(org.mifos.framework.util.helpers.Flow) Test(org.junit.Test)

Example 15 with Flow

use of org.mifos.framework.util.helpers.Flow in project head by mifos.

the class LoanPrdActionFormTest method shouldAllowPeriodicFeeForNonVariableInstallmentLoanProduct.

@Test
public void shouldAllowPeriodicFeeForNonVariableInstallmentLoanProduct() {
    String PERIODIC_FEE_2 = "2";
    String NON_PERIODIC_FEE = "3";
    final FeeDto feeDto = Mockito.mock(FeeDto.class);
    loanPrdActionForm = new LoanPrdActionForm() {

        @Override
        FeeDto getFeeDto(@SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") FeeBO fee) {
            return feeDto;
        }
    };
    FeeFrequencyEntity feeFrequencyEntity = Mockito.mock(FeeFrequencyEntity.class);
    MeetingBO meetingBo = Mockito.mock(MeetingBO.class);
    MeetingDetailsEntity meetingDetailsEntity = Mockito.mock(MeetingDetailsEntity.class);
    when(periodicFeeRate.isPeriodic()).thenReturn(true);
    when(periodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
    when(periodicFeeRate.getFeeId()).thenReturn(Short.valueOf(PERIODIC_FEE_2));
    when(periodicFeeRate.getFeeName()).thenReturn("periodic fee2");
    when((periodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity);
    when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST);
    when(periodicFeeRate.getFeeFrequency()).thenReturn(feeFrequencyEntity);
    when(nonPeriodicFeeRate.isPeriodic()).thenReturn(false);
    when(nonPeriodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
    when(nonPeriodicFeeRate.getFeeId()).thenReturn(Short.valueOf(NON_PERIODIC_FEE));
    when(nonPeriodicFeeRate.getFeeName()).thenReturn("non Periodic fee");
    when(((RateFeeBO) nonPeriodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity);
    when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST);
    List<FeeBO> allPrdFees = new ArrayList<FeeBO>();
    allPrdFees.add(periodicFeeRate);
    allPrdFees.add(nonPeriodicFeeRate);
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    when(session.getAttribute(ProductDefinitionConstants.LOANPRDFEE)).thenReturn(allPrdFees);
    Flow flow = new Flow();
    try {
        when(flowManager.getFromFlow(Mockito.anyString(), Mockito.anyString())).thenReturn(allPrdFees);
        when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    } catch (PageExpiredException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    loanPrdActionForm.setCanConfigureVariableInstallments(false);
    loanPrdActionForm.setPrdOfferinFees(new String[] { PERIODIC_FEE_2, NON_PERIODIC_FEE });
    loanPrdActionForm.validateSelectedFeeForVariableInstallment(request, errors);
    Mockito.verifyZeroInteractions(errors);
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) FeeDto(org.mifos.accounts.fees.business.FeeDto) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) Flow(org.mifos.framework.util.helpers.Flow) HttpServletRequest(javax.servlet.http.HttpServletRequest) MeetingDetailsEntity(org.mifos.application.meeting.business.MeetingDetailsEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) FeeFrequencyEntity(org.mifos.accounts.fees.business.FeeFrequencyEntity) Test(org.junit.Test)

Aggregations

Flow (org.mifos.framework.util.helpers.Flow)15 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)4 FlowManager (org.mifos.framework.util.helpers.FlowManager)4 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)4 QuestionGroupInstanceDetail (org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail)4 Arrays.asList (java.util.Arrays.asList)3 List (java.util.List)3 DateTimeService (org.mifos.framework.util.DateTimeService)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 RateFeeBO (org.mifos.accounts.fees.business.RateFeeBO)2 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)2 UserContext (org.mifos.security.util.UserContext)2 Locale (java.util.Locale)1 Random (java.util.Random)1 HttpSession (javax.servlet.http.HttpSession)1 Before (org.junit.Before)1 FeeDto (org.mifos.accounts.fees.business.FeeDto)1 FeeFrequencyEntity (org.mifos.accounts.fees.business.FeeFrequencyEntity)1