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

http://sigma-h.googlecode.com/ · Java · 82 lines · 55 code · 23 blank · 4 comment · 0 complexity · 0c4098a510d8a3e19f1a5bb8d89180c8 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.Test;
  7. import org.junit.runner.RunWith;
  8. import org.sigmah.server.dao.OnDataSet;
  9. import org.sigmah.shared.command.CreateEntity;
  10. import org.sigmah.shared.command.GetIndicatorDataSources;
  11. import org.sigmah.shared.command.UpdateEntity;
  12. import org.sigmah.shared.command.result.CreateResult;
  13. import org.sigmah.shared.command.result.IndicatorDataSourceList;
  14. import org.sigmah.shared.exception.CommandException;
  15. import org.sigmah.test.InjectionSupport;
  16. import java.util.HashMap;
  17. import java.util.HashSet;
  18. import java.util.Map;
  19. import java.util.Set;
  20. import static org.hamcrest.CoreMatchers.equalTo;
  21. import static org.junit.Assert.assertThat;
  22. @RunWith(InjectionSupport.class)
  23. @OnDataSet("/dbunit/sites-simple1.db.xml")
  24. public class GetIndicatorDataSourcesTest extends CommandTestCase {
  25. @Test
  26. public void indicatorWithNoDataSources() throws CommandException {
  27. setUser(1);
  28. IndicatorDataSourceList dsList = execute(new GetIndicatorDataSources(1));
  29. assertThat(dsList.getData().size(), equalTo(0));
  30. }
  31. @Test
  32. public void indicatorWithAddedDataSources() throws CommandException {
  33. setUser(1);
  34. Set<Integer> dataSources = new HashSet<Integer>();
  35. dataSources.add(2);
  36. Map<String,Object> changes = new HashMap<String,Object>();
  37. changes.put("dataSourceIds", dataSources);
  38. execute(new UpdateEntity("Indicator", 1, changes));
  39. IndicatorDataSourceList dsList = execute(new GetIndicatorDataSources(1));
  40. assertThat(dsList.getData().size(), equalTo(1));
  41. assertThat(dsList.getData().get(0).getIndicatorName(), equalTo("baches"));
  42. assertThat(dsList.getData().get(0).getIndicatorId(), equalTo(2));
  43. assertThat(dsList.getData().get(0).getDatabaseId(), equalTo(1));
  44. assertThat(dsList.getData().get(0).getDatabaseName(), equalTo("PEAR"));
  45. }
  46. @Test
  47. public void createIndicatorWithSources() throws CommandException {
  48. Set<Integer> dataSources = new HashSet<Integer>();
  49. dataSources.add(1);
  50. dataSources.add(2);
  51. Map<String,Object> properties = new HashMap<String,Object>();
  52. properties.put("databaseId", 1);
  53. properties.put("name", "total beneficiaries");
  54. properties.put("dataSourceIds", dataSources);
  55. CreateResult created = execute(new CreateEntity("Indicator", properties));
  56. IndicatorDataSourceList dsList = execute(new GetIndicatorDataSources(created.getNewId()));
  57. assertThat(dsList.getData().size(), equalTo(2));
  58. }
  59. }