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

http://sigma-h.googlecode.com/ · Java · 93 lines · 53 code · 25 blank · 15 comment · 0 complexity · 9176ad934208bd2015e43acb5edf249f 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 junit.framework.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.BatchCommand;
  11. import org.sigmah.shared.command.CreateEntity;
  12. import org.sigmah.shared.command.GetSchema;
  13. import org.sigmah.shared.command.UpdateEntity;
  14. import org.sigmah.shared.command.result.CreateResult;
  15. import org.sigmah.shared.dto.ActivityDTO;
  16. import org.sigmah.shared.dto.LocationTypeDTO;
  17. import org.sigmah.shared.dto.SchemaDTO;
  18. import org.sigmah.shared.dto.UserDatabaseDTO;
  19. import org.sigmah.shared.exception.CommandException;
  20. import org.sigmah.test.InjectionSupport;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. @RunWith(InjectionSupport.class)
  24. @OnDataSet("/dbunit/schema1.db.xml")
  25. public class ActivityTest extends CommandTestCase {
  26. @Test
  27. public void testActivity() throws CommandException {
  28. /*
  29. * Initial data load
  30. */
  31. SchemaDTO schema = execute(new GetSchema());
  32. UserDatabaseDTO db = schema.getDatabaseById(1);
  33. /*
  34. * Create a new activity
  35. */
  36. LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
  37. ActivityDTO act = new ActivityDTO();
  38. act.setName("Warshing the dishes");
  39. act.setLocationTypeId(locType.getId());
  40. act.setReportingFrequency(ActivityDTO.REPORT_MONTHLY);
  41. CreateResult cresult = execute(CreateEntity.Activity(db, act));
  42. int newId = cresult.getNewId();
  43. /*
  44. * Reload schema to verify the changes have stuck
  45. */
  46. schema = execute(new GetSchema());
  47. act = schema.getActivityById(newId);
  48. Assert.assertEquals("name", "Warshing the dishes", act.getName());
  49. Assert.assertEquals("locationType", locType.getName(), act.getLocationType().getName());
  50. Assert.assertEquals("reportingFrequency", ActivityDTO.REPORT_MONTHLY, act.getReportingFrequency());
  51. }
  52. @Test
  53. public void updateSortOrderTest() throws Throwable {
  54. /* Update Sort Order */
  55. Map<String, Object> changes1 = new HashMap<String, Object>();
  56. changes1.put("sortOrder", 2);
  57. Map<String, Object> changes2 = new HashMap<String, Object>();
  58. changes2.put("sortOrder", 1);
  59. execute(new BatchCommand(
  60. new UpdateEntity("Activity", 1, changes1),
  61. new UpdateEntity("Activity", 2, changes2)
  62. ));
  63. /* Confirm the order is changed */
  64. SchemaDTO schema = execute(new GetSchema());
  65. Assert.assertEquals(2, schema.getDatabaseById(1).getActivities().get(0).getId());
  66. Assert.assertEquals(1, schema.getDatabaseById(1).getActivities().get(1).getId());
  67. }
  68. }