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

http://sigma-h.googlecode.com/ · Java · 95 lines · 66 code · 25 blank · 4 comment · 2 complexity · d2d7893b5b45a3ac1897c3d492f6e666 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 java.util.Collection;
  7. import junit.framework.Assert;
  8. import org.junit.Test;
  9. import org.junit.runner.RunWith;
  10. import org.sigmah.server.dao.OnDataSet;
  11. import org.sigmah.server.endpoint.gwtrpc.handler.CommandHandlerModule;
  12. import org.sigmah.shared.command.Delete;
  13. import org.sigmah.shared.command.GetSchema;
  14. import org.sigmah.shared.command.GetSites;
  15. import org.sigmah.shared.command.result.PagingResult;
  16. import org.sigmah.shared.dto.SchemaDTO;
  17. import org.sigmah.shared.dto.SiteDTO;
  18. import org.sigmah.shared.exception.CommandException;
  19. import org.sigmah.test.InjectionSupport;
  20. import org.sigmah.test.Modules;
  21. import com.extjs.gxt.ui.client.data.ModelData;
  22. @RunWith(InjectionSupport.class)
  23. @OnDataSet("/dbunit/sites-simple1.db.xml")
  24. @Modules({
  25. CommandHandlerModule.class
  26. })
  27. public class DeleteTest extends CommandTestCase {
  28. public <T extends ModelData> T getById(Collection<T> list, Integer id) {
  29. for (T element : list) {
  30. if (id.equals(element.get("id"))) {
  31. return element;
  32. }
  33. }
  34. return null;
  35. }
  36. @Test
  37. public void testDeleteSite() throws CommandException {
  38. PagingResult<SiteDTO> sites = execute(GetSites.byId(3));
  39. execute(new Delete(sites.getData().get(0)));
  40. sites = execute(GetSites.byId(3));
  41. Assert.assertEquals(0, sites.getData().size());
  42. sites = execute(new GetSites());
  43. Assert.assertNull(getById(sites.getData(), 3));
  44. }
  45. @Test
  46. public void testDeleteIndicator() throws CommandException {
  47. SchemaDTO schema = execute(new GetSchema());
  48. execute(new Delete(schema.getIndicatorById(1)));
  49. schema = execute(new GetSchema());
  50. Assert.assertNull(schema.getIndicatorById(1));
  51. PagingResult<SiteDTO> sites = execute(GetSites.byId(1));
  52. Assert.assertNull(sites.getData().get(0).getIndicatorValue(1));
  53. }
  54. @Test
  55. public void testDeleteAttribute() throws CommandException {
  56. SchemaDTO schema = execute(new GetSchema());
  57. execute(new Delete(schema.getActivityById(1).getAttributeById(1)));
  58. schema = execute(new GetSchema());
  59. Assert.assertNull(schema.getActivityById(1).getAttributeById(1));
  60. }
  61. @Test
  62. public void testDeleteActivity() throws CommandException {
  63. SchemaDTO schema = execute(new GetSchema());
  64. execute(new Delete(schema.getActivityById(1)));
  65. execute(new Delete("Activity", 4));
  66. schema = execute(new GetSchema());
  67. Assert.assertNull("delete by entity reference", schema.getActivityById(1));
  68. Assert.assertNull("delete by id", schema.getActivityById(4));
  69. }
  70. }