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

http://sigma-h.googlecode.com/ · Java · 86 lines · 51 code · 25 blank · 10 comment · 0 complexity · 64a416d56d7cd7261eeb9b143f82a710 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.Before;
  8. import org.junit.Test;
  9. import org.junit.runner.RunWith;
  10. import org.sigmah.server.dao.OnDataSet;
  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.AttributeGroupDTO;
  17. import org.sigmah.shared.dto.SchemaDTO;
  18. import org.sigmah.test.InjectionSupport;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. @RunWith(InjectionSupport.class)
  22. @OnDataSet("/dbunit/schema1.db.xml")
  23. public class AttributeGroupTest extends CommandTestCase {
  24. @Before
  25. public void setUp() {
  26. setUser(1);
  27. }
  28. @Test
  29. public void testCreate() throws Exception {
  30. // execute the command
  31. Map<String, Object> properties = new HashMap<String, Object>();
  32. properties.put("name", "Type de Conflit");
  33. properties.put("multipleAllowed", true);
  34. properties.put("activityId", 1);
  35. CreateEntity cmd = new CreateEntity("AttributeGroup", properties);
  36. CreateResult result = execute(cmd);
  37. // check if it has been added
  38. SchemaDTO schema = execute(new GetSchema());
  39. ActivityDTO activity = schema.getActivityById(1);
  40. AttributeGroupDTO group = activity.getAttributeGroupById(result.getNewId());
  41. Assert.assertNotNull("attribute group is created", group);
  42. Assert.assertEquals("name is correct", group.getName(), "Type de Conflit");
  43. Assert.assertTrue("multiple allowed is set to true", group.isMultipleAllowed());
  44. }
  45. @Test
  46. public void testUpdate() throws Exception {
  47. // initial data load
  48. SchemaDTO schema = execute(new GetSchema());
  49. // change the name of an entity group
  50. ActivityDTO activity = schema.getActivityById(1);
  51. AttributeGroupDTO group = activity.getAttributeGroups().get(0);
  52. group.setName("Foobar");
  53. Map<String, Object> changes = new HashMap<String, Object>();
  54. changes.put("name", group.getName());
  55. execute(new UpdateEntity(group, changes));
  56. // reload data
  57. schema = execute(new GetSchema());
  58. // verify the property has been duly changed
  59. Assert.assertEquals(group.getName(), schema.getActivityById(1).getAttributeGroups().get(0).getName());
  60. }
  61. }