[ 
http://mifosforge.jira.com/browse/MIFOS-4175?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=62974#action_62974
 ] 

Vivek Singh edited comment on MIFOS-4175 at 12/16/10 4:34 AM:
--------------------------------------------------------------

Autowiring doesn't work for both scalatest as well as easyb. And yes using 
SpringContext is a workaround right now.

Groovy is a dynamic language and Scala is strongly typed functional language.
Dynamic languages provide lot more options for domain specific languages 
because of its ability to do late binding. Scala being a compiled language it 
doesn't lend itself so well to it. For writing acceptance tests easyb, based on 
groovy looks to be a better option.

Groovy test
------------------
scenario "Save the cash flow", {
  given "cash flow object is defined", {
    revenue = 100.21G
    expense = 50.37G
    dateTime = new DateTime(2010, 10, 11, 12, 13, 14, 15)

    list = [new MonthlyCashFlowDetail(dateTime, revenue, expense, "my notes"),
            new MonthlyCashFlowDetail(dateTime.plusMonths(1), revenue + 20.01G, 
expense + 10.22G, "my other notes")]

    cashFlowDetail = new CashFlowDetail(list)
    cashFlowDetail.with {
      totalLiability = 123G
      totalCapital = 456G
    }
  }

  when "cash flow service and dao are available and save is called", {
    factory = ScalaUtil.getCashFlowContext()
    factory.with {
      cashFlowService = getBean("cashFlowService")
      cashFlowDao = getBean("cashFlowDao")
    }
    cashFlowId = cashFlowService.save(cashFlowDetail);
  }

  then "total capital and liability is also saved along with the cash flow", {
    cashFlow = cashFlowDao.getDetails(cashFlowId);
    cashFlow.totalLiability.shouldBe 123G
    cashFlow.totalCapital.shouldBe 456G
  }
}

Scala test
---------------
class CashFlowServiceSpec extends FeatureSpec with GivenWhenThen {

  var cashFlowService: CashFlowService = null;
  var cashFlowDao: CashFlowDao = null;

  val revenue: BigDecimal = new BigDecimal(100.21d)
  val expense: BigDecimal = new BigDecimal(50.37d)

  feature("The User should be able to save a cash flow"){
    scenario("save the cash flow") {
      given("there is a cash flow")
      val factory: BeanFactory = ScalaUtil.getCashFlowContext
      val cashFlowDetails: CashFlowDetail = getCashFlowDetails(new 
BigDecimal(123d), new BigDecimal(456d))

      when("save is called")
      cashFlowService= 
factory.getBean("cashFlowService").asInstanceOf[CashFlowService]
      cashFlowDao= factory.getBean("cashFlowDao").asInstanceOf[CashFlowDao]
      var cashFlowId: Integer = cashFlowService.save(cashFlowDetails)
      var cashFlow: CashFlow = cashFlowDao.getDetails(cashFlowId)

      then("the cash flow should be saved")
      var totalLiability: BigDecimal = cashFlow.getTotalLiability
      var totalCapital: BigDecimal = cashFlow.getTotalCapital
      assert(totalCapital.doubleValue === 123d)
      assert(totalLiability.doubleValue === 456d)
    }
  }

  def getCashFlowDetails(totalCapital: BigDecimal, totalLiability: BigDecimal): 
CashFlowDetail = {
    var dateTime: DateTime = new DateTime(2010, 10, 11, 12, 13, 14, 15)
    var list: java.util.ArrayList[MonthlyCashFlowDetail] = new 
java.util.ArrayList[MonthlyCashFlowDetail]
    list.add(new 
org.mifos.platform.cashflow.service.MonthlyCashFlowDetail(dateTime, revenue, 
expense, "my notes"))
    list.add(new 
org.mifos.platform.cashflow.service.MonthlyCashFlowDetail(dateTime.plusMonths(1),
 revenue.add(new BigDecimal(20.01)),
      expense.add(new BigDecimal(10.22)), "my other notes"))
    val cashFlowDetail: CashFlowDetail = new CashFlowDetail(list)
    cashFlowDetail.setTotalCapital(totalCapital);
    cashFlowDetail.setTotalLiability(totalLiability);
    return  cashFlowDetail;
  }
}

Java
------
    public void shouldSaveCashFlowWithTotalCapitalAndTotalLiability() {
        Integer cashFlowId = cashFlowService.save(getCashFlowDetails(123d, 
456d));
        CashFlow cashFlow = cashFlowDao.getDetails(cashFlowId);
        BigDecimal totalLiability = cashFlow.getTotalLiability();
        BigDecimal totalCapital = cashFlow.getTotalCapital();
        assertThat(totalCapital.doubleValue(), is(123d));
        assertThat(totalLiability.doubleValue(), is(456d));
    }

    private CashFlowDetail getCashFlowDetails(double totalCapital, double 
totalLiability) {
        DateTime dateTime = new DateTime(2010, 10, 11, 12, 13, 14, 15);
        return new CashFlowDetailsBuilder().
                withMonthlyCashFlow(new MonthlyCashFlowDetail(dateTime, 
revenue, expense, "my notes")).
                withMonthlyCashFlow(new 
MonthlyCashFlowDetail(dateTime.plusMonths(1), revenue.add(new 
BigDecimal(20.01)), expense.add(new BigDecimal(10.22)), "my other notes")).
                withTotalCapital(totalCapital).
                withTotalLiability(totalLiability).
                build();
    }


public class CashFlowDetailsBuilder {
    private CashFlowDetail cashFlowDetail;

    public CashFlowDetailsBuilder() {
        cashFlowDetail = new CashFlowDetail(new 
ArrayList<MonthlyCashFlowDetail>());
    }

    public CashFlowDetailsBuilder withMonthlyCashFlow(MonthlyCashFlowDetail 
monthlyCashFlowDetail) {
        cashFlowDetail.getMonthlyCashFlowDetails().add(monthlyCashFlowDetail);
        return this;
    }

    public CashFlowDetail build() {
        return cashFlowDetail;
    }

    public CashFlowDetailsBuilder withTotalCapital(double totalCapital) {
        cashFlowDetail.setTotalCapital(new BigDecimal(totalCapital));
        return this;
    }

    public CashFlowDetailsBuilder withTotalLiability(double totalLiability) {
        cashFlowDetail.setTotalLiability(new BigDecimal(totalLiability));
        return this;
    }
}


      was (Author: petmongrels):
    Autowiring doesn't work for both scalatest as well as easyb. And yes using 
SpringContext is a workaround right now.

Groovy is a dynamic language and Scala is strongly typed functional language.
Dynamic languages provide lot more options for domain specific languages 
because of its ability to do late binding. Scala being a compiled language it 
doesn't lend itself so well to it. For writing acceptance tests easyb, based on 
groovy would be an a better option.

Groovy test
------------------
scenario "Save the cash flow", {
  given "cash flow object is defined", {
    revenue = 100.21G
    expense = 50.37G
    dateTime = new DateTime(2010, 10, 11, 12, 13, 14, 15)

    list = [new MonthlyCashFlowDetail(dateTime, revenue, expense, "my notes"),
            new MonthlyCashFlowDetail(dateTime.plusMonths(1), revenue + 20.01G, 
expense + 10.22G, "my other notes")]

    cashFlowDetail = new CashFlowDetail(list)
    cashFlowDetail.with {
      totalLiability = 123G
      totalCapital = 456G
    }
  }

  when "cash flow service and dao are available and save is called", {
    factory = ScalaUtil.getCashFlowContext()
    factory.with {
      cashFlowService = getBean("cashFlowService")
      cashFlowDao = getBean("cashFlowDao")
    }
    cashFlowId = cashFlowService.save(cashFlowDetail);
  }

  then "total capital and liability is also saved along with the cash flow", {
    cashFlow = cashFlowDao.getDetails(cashFlowId);
    cashFlow.totalLiability.shouldBe 123G
    cashFlow.totalCapital.shouldBe 456G
  }
}

Scala test
---------------
class CashFlowServiceSpec extends FeatureSpec with GivenWhenThen {

  var cashFlowService: CashFlowService = null;
  var cashFlowDao: CashFlowDao = null;

  val revenue: BigDecimal = new BigDecimal(100.21d)
  val expense: BigDecimal = new BigDecimal(50.37d)

  feature("The User should be able to save a cash flow"){
    scenario("save the cash flow") {
      given("there is a cash flow")
      val factory: BeanFactory = ScalaUtil.getCashFlowContext
      val cashFlowDetails: CashFlowDetail = getCashFlowDetails(new 
BigDecimal(123d), new BigDecimal(456d))

      when("save is called")
      cashFlowService= 
factory.getBean("cashFlowService").asInstanceOf[CashFlowService]
      cashFlowDao= factory.getBean("cashFlowDao").asInstanceOf[CashFlowDao]
      var cashFlowId: Integer = cashFlowService.save(cashFlowDetails)
      var cashFlow: CashFlow = cashFlowDao.getDetails(cashFlowId)

      then("the cash flow should be saved")
      var totalLiability: BigDecimal = cashFlow.getTotalLiability
      var totalCapital: BigDecimal = cashFlow.getTotalCapital
      assert(totalCapital.doubleValue === 123d)
      assert(totalLiability.doubleValue === 456d)
    }
  }

  def getCashFlowDetails(totalCapital: BigDecimal, totalLiability: BigDecimal): 
CashFlowDetail = {
    var dateTime: DateTime = new DateTime(2010, 10, 11, 12, 13, 14, 15)
    var list: java.util.ArrayList[MonthlyCashFlowDetail] = new 
java.util.ArrayList[MonthlyCashFlowDetail]
    list.add(new 
org.mifos.platform.cashflow.service.MonthlyCashFlowDetail(dateTime, revenue, 
expense, "my notes"))
    list.add(new 
org.mifos.platform.cashflow.service.MonthlyCashFlowDetail(dateTime.plusMonths(1),
 revenue.add(new BigDecimal(20.01)),
      expense.add(new BigDecimal(10.22)), "my other notes"))
    val cashFlowDetail: CashFlowDetail = new CashFlowDetail(list)
    cashFlowDetail.setTotalCapital(totalCapital);
    cashFlowDetail.setTotalLiability(totalLiability);
    return  cashFlowDetail;
  }
}
  
> Spike on using a BDD testing framework
> --------------------------------------
>
>                 Key: MIFOS-4175
>                 URL: http://mifosforge.jira.com/browse/MIFOS-4175
>             Project: mifos
>          Issue Type: Story
>          Components: Build and Testing
>    Affects Versions: Elsie F - Iteration 6
>            Reporter: jbrewster
>            Assignee: Vivek Singh
>             Fix For: Elsie F - Iteration 6
>
>
> Do a spike on using a BDD development tool to allow for more 
> BA/developer/tester/customer visibility to what automated tests we have in 
> place.  BDD tool could be used in place of current acceptance tests, or at 
> some other functional test level.  
> Related to developer email thread - http://tinyurl.com/247u3sj.
> Some possibilities to evaluate (real choices are up the the task owner) - 
> ScalaTest, EasyB, JBehave
> Acceptance Criteria:
> Showcase Prototype(s) test built that shows contrast to current test.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://mifosforge.jira.com/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Mifos-issues mailing list
Mifos-issues@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mifos-issues

Reply via email to