/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/MonthlyReportsTest.java

http://sigma-h.googlecode.com/ · Java · 84 lines · 54 code · 25 blank · 5 comment · 0 complexity · fd7e5042e3afaaf5c80b4195f34a1d8d MD5 · raw file

  1. /*
  2. * All Sigmah code is released under the GNU General Public License v3
  3. * See COPYRIGHT.txt and LICENSE.txt.
  4. */
  5. package org.sigmah.server.endpoint.gwtrpc;
  6. import org.junit.Assert;
  7. import org.junit.Test;
  8. import org.junit.runner.RunWith;
  9. import org.sigmah.server.dao.OnDataSet;
  10. import org.sigmah.shared.command.GetMonthlyReports;
  11. import org.sigmah.shared.command.Month;
  12. import org.sigmah.shared.command.UpdateMonthlyReports;
  13. import org.sigmah.shared.command.result.MonthlyReportResult;
  14. import org.sigmah.test.InjectionSupport;
  15. import java.util.ArrayList;
  16. @RunWith(InjectionSupport.class)
  17. @OnDataSet("/dbunit/sites-simple1.db.xml")
  18. public class MonthlyReportsTest extends CommandTestCase {
  19. @Test
  20. public void testMonthCompare() throws Exception {
  21. Month feb = new Month(2009, 2);
  22. Month maxMonth = new Month(2009, 2);
  23. Assert.assertEquals(0, maxMonth.compareTo(feb));
  24. }
  25. @Test
  26. public void testGetReports() throws Exception {
  27. GetMonthlyReports cmd = new GetMonthlyReports(6);
  28. cmd.setStartMonth(new Month(2009, 1));
  29. cmd.setEndMonth(new Month(2009, 2));
  30. MonthlyReportResult result = execute(cmd);
  31. Assert.assertEquals(1, result.getData().size());
  32. Assert.assertEquals(35, result.getData().get(0).getValue(2009, 1).intValue());
  33. Assert.assertEquals(70, result.getData().get(0).getValue(2009, 2).intValue());
  34. }
  35. @Test
  36. public void testGetReportsWhenEmpty() throws Exception {
  37. GetMonthlyReports cmd = new GetMonthlyReports(7);
  38. cmd.setStartMonth(new Month(2009, 1));
  39. cmd.setEndMonth(new Month(2009, 2));
  40. MonthlyReportResult result = execute(cmd);
  41. Assert.assertEquals(1, result.getData().size());
  42. }
  43. @Test
  44. public void testUpdate() throws Exception {
  45. ArrayList<UpdateMonthlyReports.Change> changes = new ArrayList<UpdateMonthlyReports.Change>();
  46. changes.add(new UpdateMonthlyReports.Change(6, new Month(2009, 1), 45.0));
  47. changes.add(new UpdateMonthlyReports.Change(6, new Month(2009, 3), 22.0));
  48. execute(new UpdateMonthlyReports(6, changes));
  49. // verify that that changes have been made
  50. GetMonthlyReports cmd = new GetMonthlyReports(6);
  51. cmd.setStartMonth(new Month(2009, 1));
  52. cmd.setEndMonth(new Month(2009, 3));
  53. MonthlyReportResult result = execute(cmd);
  54. Assert.assertEquals(1, result.getData().size());
  55. Assert.assertEquals(45, result.getData().get(0).getValue(2009, 1).intValue());
  56. Assert.assertEquals(70, result.getData().get(0).getValue(2009, 2).intValue());
  57. Assert.assertEquals(22, result.getData().get(0).getValue(2009, 3).intValue());
  58. }
  59. }