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

http://sigma-h.googlecode.com/ · Java · 113 lines · 75 code · 38 blank · 0 comment · 0 complexity · 66b06318749fb95027755025fd2995ac MD5 · raw file

  1. package org.sigmah.server.endpoint.gwtrpc;
  2. import static org.hamcrest.CoreMatchers.equalTo;
  3. import static org.junit.Assert.assertThat;
  4. import org.junit.Test;
  5. import org.junit.runner.RunWith;
  6. import org.sigmah.server.dao.OnDataSet;
  7. import org.sigmah.shared.command.GetIndicators;
  8. import org.sigmah.shared.command.result.IndicatorListResult;
  9. import org.sigmah.shared.dto.IndicatorDTO;
  10. import org.sigmah.shared.dto.IndicatorGroup;
  11. import org.sigmah.shared.exception.CommandException;
  12. import org.sigmah.test.InjectionSupport;
  13. @RunWith(InjectionSupport.class)
  14. @OnDataSet("/dbunit/sites-simple1.db.xml")
  15. public class GetIndicatorsHandlerTest extends CommandTestCase {
  16. private static final int DATABASE_OWNER = 1;
  17. @Test
  18. public void testList() throws CommandException {
  19. setUser(DATABASE_OWNER);
  20. GetIndicators cmd = new GetIndicators();
  21. cmd.setUserDatabaseId(1);
  22. IndicatorListResult result = execute(cmd);
  23. assertThat(result.getData().size(), equalTo(3));
  24. IndicatorDTO i0 = result.getData().get(0);
  25. IndicatorDTO i1 = result.getData().get(1);
  26. IndicatorDTO i2 = result.getData().get(2);
  27. assertThat(i0.getName(), equalTo("baches"));
  28. assertThat(i0.isDirectDataEntryEnabled(), equalTo(true));
  29. assertThat(i1.getName(), equalTo("beneficiaries"));
  30. assertThat(i1.getId(), equalTo(1));
  31. assertThat(i1.getCurrentValue(), equalTo(15100d));
  32. assertThat(i1.getObjective(), equalTo(10000d));
  33. assertThat(i1.getGroupId(), equalTo(1));
  34. assertThat(i2.getName(), equalTo("Nb. of distributions"));
  35. assertThat(result.getGroups().size(), equalTo(2));
  36. IndicatorGroup g1 = result.getGroups().get(0);
  37. assertThat(g1.getId(), equalTo(1));
  38. assertThat(g1.getName(), equalTo("NFI"));
  39. assertThat(g1.getIndicators().size(), equalTo(3));
  40. }
  41. @Test
  42. @OnDataSet("/dbunit/project-indicator.db.xml")
  43. public void testListWithCategorical() throws CommandException {
  44. setUser(DATABASE_OWNER);
  45. GetIndicators cmd = new GetIndicators();
  46. cmd.setUserDatabaseId(2);
  47. IndicatorListResult result = execute(cmd);
  48. assertThat(result.getData().size(), equalTo(2));
  49. IndicatorDTO construction = result.getData().get(0);
  50. IndicatorDTO service = result.getData().get(1);
  51. assertThat(construction.getLabels().size(), equalTo(3));
  52. assertThat(construction.getLabels().get(0), equalTo("Good"));
  53. assertThat(construction.getLabels().get(1), equalTo("Bad"));
  54. assertThat(construction.getLabels().get(2), equalTo("Ugly"));
  55. assertThat(construction.getLabelCounts().size(), equalTo(3));
  56. assertThat(construction.getLabelCounts().get(0), equalTo(1));
  57. assertThat(construction.getLabelCounts().get(1), equalTo(2));
  58. assertThat(construction.getLabelCounts().get(2), equalTo(1));
  59. assertThat(construction.formatMode(), equalTo("Bad (50%)"));
  60. assertThat(service.getLabels().size(), equalTo(3));
  61. assertThat(service.getLabels().get(0), equalTo("Mediocre"));
  62. assertThat(service.getLabels().get(1), equalTo("Pretty bad"));
  63. assertThat(service.getLabels().get(2), equalTo("Terrible"));
  64. }
  65. @Test
  66. @OnDataSet("/dbunit/project-indicator-linked.db.xml")
  67. public void valuesFromDataSourcesAreIncludedInAggregates_Issue359() throws Exception {
  68. IndicatorListResult result = execute(GetIndicators.forDatabase(1));
  69. IndicatorDTO indicator2 = result.getIndicatorById(2);
  70. assertThat(indicator2.getCurrentValue(), equalTo(2644d));
  71. IndicatorDTO indicator91 = result.getIndicatorById(91);
  72. assertThat(indicator91.getLabelCounts().get(0), equalTo(1));
  73. assertThat(indicator91.getLabelCounts().get(1), equalTo(1));
  74. }
  75. }