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

http://sigma-h.googlecode.com/ · Java · 116 lines · 72 code · 37 blank · 7 comment · 7 complexity · aa7565619ea10d20d71835b8311282c6 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.Test;
  8. import org.junit.runner.RunWith;
  9. import org.sigmah.server.dao.OnDataSet;
  10. import org.sigmah.shared.command.GetSchema;
  11. import org.sigmah.shared.dto.ActivityDTO;
  12. import org.sigmah.shared.dto.AttributeDTO;
  13. import org.sigmah.shared.dto.IndicatorDTO;
  14. import org.sigmah.shared.dto.SchemaDTO;
  15. import org.sigmah.shared.exception.CommandException;
  16. import org.sigmah.test.InjectionSupport;
  17. @RunWith(InjectionSupport.class)
  18. @OnDataSet("/dbunit/schema1.db.xml")
  19. public class GetSchemaTest extends CommandTestCase {
  20. @Test
  21. public void testDatabaseVisibilityForOwners() throws CommandException {
  22. // owners should be able to see their databases
  23. setUser(1); // Alex
  24. SchemaDTO schema = execute(new GetSchema());
  25. Assert.assertTrue("ALEX(owner) in PEAR", schema.getDatabaseById(1) != null); // PEAR
  26. Assert.assertTrue("ALEX can design", schema.getDatabaseById(1).isDesignAllowed());
  27. Assert.assertTrue("Alex can edit all", schema.getDatabaseById(1).isEditAllowed());
  28. Assert.assertTrue("object graph is preserved", schema.getDatabaseById(1).getCountry() == schema.getDatabaseById(2).getCountry());
  29. Assert.assertTrue("object graph is preserved (database-activity)",
  30. schema.getDatabaseById(1) ==
  31. schema.getDatabaseById(1).getActivities().get(0).getDatabase());
  32. }
  33. @Test
  34. public void testDatabaseVisibilityForView() throws CommandException {
  35. setUser(2); // Bavon
  36. SchemaDTO schema = execute(new GetSchema());
  37. Assert.assertTrue("BAVON in PEAR", schema.getDatabaseById(1) != null);
  38. Assert.assertTrue("bavon can edit", schema.getDatabaseById(1).isEditAllowed());
  39. Assert.assertFalse("bavon cannot edit all", schema.getDatabaseById(1).isEditAllAllowed());
  40. }
  41. @Test
  42. public void testDatabaseVisibilityNone() throws CommandException {
  43. setUser(3); // Stefan
  44. SchemaDTO schema = execute(new GetSchema());
  45. Assert.assertTrue("STEFAN not in PEAR", schema.getDatabaseById(1) == null);
  46. }
  47. @Test
  48. public void testIndicators() throws CommandException {
  49. setUser(1); // Alex
  50. SchemaDTO schema = execute(new GetSchema());
  51. Assert.assertTrue("no indicators case",
  52. schema.getActivityById(2).getIndicators().size() == 0);
  53. ActivityDTO nfi = schema.getActivityById(1);
  54. IndicatorDTO[] indicators = nfi.getIndicators().toArray(new IndicatorDTO[0]);
  55. Assert.assertEquals("indicators are present", 2, indicators.length);
  56. //Assert.assertTrue("indicators are sorted",
  57. // indicators[0].getSortOrder() <= indicators[1].getSortOrder());
  58. IndicatorDTO test = nfi.getIndicatorById(2);
  59. Assert.assertEquals("property:name", test.getName(), "kits");
  60. Assert.assertEquals("property:units", test.getUnits(), "menages");
  61. Assert.assertEquals("property:aggregation", test.getAggregation(), 0);
  62. Assert.assertEquals("property:collectIntervention", test.isCollectIntervention(), true);
  63. Assert.assertEquals("property:collectMonitoring", test.isCollectMonitoring(), true);
  64. Assert.assertEquals("property:category", test.getCategory(), "outputs");
  65. Assert.assertEquals("property:code", test.getCode(), "header");
  66. Assert.assertEquals("property:description", test.getDescription(), "desc");
  67. }
  68. @Test
  69. public void testAttributes() throws CommandException {
  70. setUser(1); // Alex
  71. SchemaDTO schema = execute(new GetSchema());
  72. Assert.assertTrue("no attributes case", schema.getActivityById(2).getAttributeGroups().size() == 0);
  73. ActivityDTO nfi = schema.getActivityById(1);
  74. AttributeDTO[] attributes = nfi.getAttributeGroups().get(0).getAttributes().toArray(new AttributeDTO[0]);
  75. Assert.assertTrue("attributes are present", attributes.length == 2);
  76. AttributeDTO test = nfi.getAttributeById(1);
  77. Assert.assertEquals("property:name", "Retour", test.getName());
  78. }
  79. }