/sigmah/src/test/java/org/sigmah/client/offline/command/handler/LocalGetSchemaHandlerIntTest.java

http://sigma-h.googlecode.com/ · Java · 80 lines · 59 code · 17 blank · 4 comment · 0 complexity · 4cab9e3dbb3ad2b9b131706cd049bebc 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.client.offline.command.handler;
  6. import org.junit.Test;
  7. import org.junit.runner.RunWith;
  8. import org.sigmah.server.dao.OnDataSet;
  9. import org.sigmah.server.endpoint.gwtrpc.GwtRpcModule;
  10. import org.sigmah.server.util.BeanMappingModule;
  11. import org.sigmah.server.util.logging.LoggingModule;
  12. import org.sigmah.shared.command.GetSchema;
  13. import org.sigmah.shared.command.handler.LocalHandlerTestCase;
  14. import org.sigmah.shared.dto.ActivityDTO;
  15. import org.sigmah.shared.dto.AttributeGroupDTO;
  16. import org.sigmah.shared.dto.SchemaDTO;
  17. import org.sigmah.shared.dto.UserDatabaseDTO;
  18. import org.sigmah.shared.exception.CommandException;
  19. import org.sigmah.test.InjectionSupport;
  20. import org.sigmah.test.MockHibernateModule;
  21. import org.sigmah.test.Modules;
  22. import static org.hamcrest.CoreMatchers.equalTo;
  23. import static org.junit.Assert.assertThat;
  24. @RunWith(InjectionSupport.class)
  25. @Modules({
  26. MockHibernateModule.class,
  27. BeanMappingModule.class,
  28. GwtRpcModule.class,
  29. LoggingModule.class
  30. })
  31. public class LocalGetSchemaHandlerIntTest extends LocalHandlerTestCase {
  32. @Test
  33. @OnDataSet("/dbunit/sites-simple1.db.xml")
  34. public void forDatabaseOwner() throws CommandException {
  35. synchronize();
  36. LocalGetSchemaHandler handler = new LocalGetSchemaHandler(localConnection, localAuth);
  37. SchemaDTO schema = handler.execute(new GetSchema(), user);
  38. assertThat(schema.getDatabases().size(), equalTo(2));
  39. assertThat(schema.getDatabaseById(1).isDesignAllowed(), equalTo(true));
  40. assertThat(schema.getDatabaseById(1).getAmOwner(), equalTo(true));
  41. assertThat(schema.getDatabaseById(2).getAmOwner(), equalTo(true));
  42. assertThat(schema.getDatabaseById(1).getOwnerName(), equalTo("Alex"));
  43. }
  44. @Test
  45. @OnDataSet("/dbunit/sites-simple1.db.xml")
  46. public void forUser() throws CommandException {
  47. setUser(2); // Bavon, has access only to PEAR
  48. synchronize();
  49. LocalGetSchemaHandler handler = new LocalGetSchemaHandler(localConnection, localAuth);
  50. SchemaDTO schema = handler.execute(new GetSchema(), user);
  51. assertThat(schema.getDatabases().size(), equalTo(1));
  52. UserDatabaseDTO pearDb = schema.getDatabaseById(1);
  53. assertThat(pearDb.getAmOwner(), equalTo(false));
  54. assertThat(pearDb.isViewAllAllowed(), equalTo(false));
  55. assertThat(pearDb.isEditAllowed(), equalTo(true));
  56. assertThat(pearDb.isEditAllAllowed(), equalTo(false));
  57. ActivityDTO activity = schema.getActivityById(1);
  58. assertThat(activity.getAttributeGroups().size(), equalTo(2));
  59. AttributeGroupDTO group = activity.getAttributeGroupById(1);
  60. assertThat(group.getName(), equalTo("cause"));
  61. assertThat(group.getAttributes().size(), equalTo(2));
  62. }
  63. }