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

http://sigma-h.googlecode.com/ · Java · 97 lines · 61 code · 25 blank · 11 comment · 0 complexity · a634fc1846a2da42d2b6627846aa0e9a 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.Ignore;
  8. import org.junit.Test;
  9. import org.junit.runner.RunWith;
  10. import org.sigmah.server.dao.OnDataSet;
  11. import org.sigmah.shared.command.GetSites;
  12. import org.sigmah.shared.command.UpdateEntity;
  13. import org.sigmah.shared.command.result.ListResult;
  14. import org.sigmah.shared.domain.Site;
  15. import org.sigmah.shared.dto.SiteDTO;
  16. import org.sigmah.shared.exception.CommandException;
  17. import org.sigmah.test.InjectionSupport;
  18. import java.util.HashMap;
  19. import java.util.Map;
  20. @RunWith(InjectionSupport.class)
  21. @OnDataSet("/dbunit/sites-simple1.db.xml")
  22. public class UpdateSiteTest extends CommandTestCase {
  23. @Test
  24. public void testUpdate() throws CommandException {
  25. // retrieve from the server
  26. ListResult<SiteDTO> result = execute(GetSites.byId(1));
  27. SiteDTO model = result.getData().get(0);
  28. // modify and generate command
  29. model.setComments("NEW <b>Commentaire</b>");
  30. model.setLocationName("NEWNAME");
  31. model.setAttributeValue(1, true);
  32. model.setAttributeValue(2, null);
  33. model.setAttributeValue(3, true);
  34. model.setAttributeValue(4, false);
  35. model.setIndicatorValue(2, 995.0);
  36. model.setAdminEntity(2, null);
  37. execute(new UpdateEntity(model, model.getProperties()));
  38. // retrieve the old one
  39. result = execute(GetSites.byId(1));
  40. SiteDTO secondRead = result.getData().get(0);
  41. // confirm that the changes are there
  42. Assert.assertEquals("site.comments", model.getComments(), secondRead.getComments());
  43. Assert.assertEquals("site.location.name", model.getLocationName(), secondRead.getLocationName());
  44. Assert.assertEquals("site.reportingPeriod[0].indicatorValue[0]", 995,
  45. secondRead.getIndicatorValue(2).intValue());
  46. Assert.assertEquals("site.attribute[1]", true, model.getAttributeValue(1));
  47. Assert.assertNull("site.attribute[2]", model.getAttributeValue(2));
  48. Assert.assertEquals("site.attribute[3]", true, model.getAttributeValue(1));
  49. Assert.assertEquals("site.attribute[4]", true, model.getAttributeValue(1));
  50. }
  51. @Ignore
  52. @Test
  53. public void testUpdatePartner() throws CommandException {
  54. // define changes for site id=2
  55. Map<String, Object> changes = new HashMap<String, Object>();
  56. changes.put("partnerId", 2);
  57. execute(new UpdateEntity("Site", 2, changes));
  58. // assure that the change has been effected
  59. Site site = em.find(Site.class, 2);
  60. Assert.assertEquals("partnerId", 2, site.getPartner().getId());
  61. }
  62. @Test
  63. @OnDataSet("/dbunit/project-indicator.db.xml")
  64. public void updateLocationNameOnSiteWithoutActivityId() throws CommandException {
  65. Map<String, Object> changes = new HashMap<String, Object>();
  66. changes.put("locationName", "Goma 2");
  67. execute(new UpdateEntity("Site", 4, changes));
  68. // assure that the change has been effected
  69. Site site = em.find(Site.class, 4);
  70. Assert.assertEquals("location Name", "Goma 2", site.getLocation().getName());
  71. }
  72. }