@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);
  }
  public void testSuccessfulUpdate_RateFee() throws Exception {
    fee =
        TestObjectFactory.createOneTimeRateFee(
            "One Time Fee", FeeCategory.ALLCUSTOMERS, 24.0, FeeFormula.AMOUNT, FeePayment.UPFRONT);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, fee, request);
    setRequestPathInfo("/feeaction.do");
    addRequestParameter("method", "manage");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();

    setRequestPathInfo("/feeaction.do");
    addRequestParameter("method", "editPreview");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("rate", "30");
    actionPerform();

    setRequestPathInfo("/feeaction.do");
    addRequestParameter("method", "update");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyForward(ActionForwards.update_success.toString());

    fee = (FeeBO) TestObjectFactory.getObject(FeeBO.class, fee.getFeeId());
    Assert.assertTrue(fee.isActive());
    Assert.assertEquals(30.0, ((RateFeeBO) fee).getRate(), DELTA);
  }
  public void testSuccessfulUpdate_AmountFee() throws Exception {
    fee =
        TestObjectFactory.createOneTimeAmountFee(
            "One Time Fee", FeeCategory.ALLCUSTOMERS, "100", FeePayment.UPFRONT);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, fee, request);
    setRequestPathInfo("/feeaction.do");
    addRequestParameter("method", "manage");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();

    setRequestPathInfo("/feeaction.do");
    addRequestParameter("method", "editPreview");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("amount", "200.0");
    addRequestParameter("feeStatus", FeeStatus.INACTIVE.getValue().toString());
    actionPerform();

    setRequestPathInfo("/feeaction.do");
    addRequestParameter("method", "update");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyForward(ActionForwards.update_success.toString());

    fee = (FeeBO) TestObjectFactory.getObject(FeeBO.class, fee.getFeeId());
    Assert.assertFalse(fee.isActive());
    Assert.assertEquals(new Money(getCurrency(), "200.0"), ((AmountFeeBO) fee).getFeeAmount());
  }
  public void testSuccessfulViewAllFees() throws Exception {
    StaticHibernateUtil.startTransaction();
    fee =
        TestObjectFactory.createOneTimeRateFee(
            "Group_Fee", FeeCategory.GROUP, 10.0, FeeFormula.AMOUNT, FeePayment.UPFRONT);
    fee1 =
        TestObjectFactory.createOneTimeRateFee(
            "Customer_Fee", FeeCategory.ALLCUSTOMERS, 20.0, FeeFormula.AMOUNT, FeePayment.UPFRONT);
    fee2 =
        TestObjectFactory.createOneTimeRateFee(
            "Loan_Fee1", FeeCategory.LOAN, 30.0, FeeFormula.AMOUNT, FeePayment.UPFRONT);
    fee3 =
        TestObjectFactory.createOneTimeRateFee(
            "Center_Fee", FeeCategory.CENTER, 40.0, FeeFormula.AMOUNT, FeePayment.UPFRONT);
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.closeSession();
    setRequestPathInfo("/feeaction.do");
    addRequestParameter("method", "viewAll");

    actionPerform();
    verifyNoActionErrors();
    verifyForward(ActionForwards.viewAll_success.toString());
    flowKey = request.getAttribute(Constants.CURRENTFLOWKEY).toString();
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    List<FeeBO> customerFees =
        (List<FeeBO>) SessionUtils.getAttribute(FeeConstants.CUSTOMER_FEES, request);
    List<FeeBO> productFees =
        (List<FeeBO>) SessionUtils.getAttribute(FeeConstants.PRODUCT_FEES, request);
    Assert.assertEquals(3, customerFees.size());
    Assert.assertEquals(1, productFees.size());

    Assert.assertEquals("Center_Fee", customerFees.get(0).getFeeName());
    Assert.assertEquals("Customer_Fee", customerFees.get(1).getFeeName());
    Assert.assertEquals("Group_Fee", customerFees.get(2).getFeeName());

    Assert.assertEquals("Loan_Fee1", productFees.get(0).getFeeName());

    fee = (FeeBO) TestObjectFactory.getObject(FeeBO.class, fee.getFeeId());
    fee1 = (FeeBO) TestObjectFactory.getObject(FeeBO.class, fee1.getFeeId());
    fee2 = (FeeBO) TestObjectFactory.getObject(FeeBO.class, fee2.getFeeId());
    fee3 = (FeeBO) TestObjectFactory.getObject(FeeBO.class, fee3.getFeeId());
  }
 public void testSuccessfulGetFee() throws Exception {
   fee =
       TestObjectFactory.createOneTimeAmountFee(
           "One Time Fee", FeeCategory.ALLCUSTOMERS, "100", FeePayment.UPFRONT);
   request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
   setRequestPathInfo("/feeaction.do");
   addRequestParameter("method", "get");
   addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
   addRequestParameter("feeId", fee.getFeeId().toString());
   actionPerform();
   fee = (FeeBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
   Assert.assertNotNull(fee);
 }
  @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));
  }