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

http://sigma-h.googlecode.com/ · Java · 64 lines · 34 code · 15 blank · 15 comment · 0 complexity · 90f67d2121ea2218e941b50a79ded54e 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.GetUsers;
  11. import org.sigmah.shared.command.result.UserResult;
  12. import org.sigmah.shared.exception.CommandException;
  13. import org.sigmah.test.InjectionSupport;
  14. @RunWith(InjectionSupport.class)
  15. @OnDataSet("/dbunit/sites-simple1.db.xml")
  16. public class GetUsersTest extends CommandTestCase {
  17. private final static int DATABASE_OWNER = 1;
  18. @Test
  19. public void testUnsorted() throws CommandException {
  20. setUser(DATABASE_OWNER);
  21. GetUsers cmd = new GetUsers(1);
  22. UserResult result = (UserResult) execute(cmd);
  23. Assert.assertEquals(3, result.getData().size());
  24. }
  25. /**
  26. * Verify that users with ManageUsers permission can get a list of users
  27. * within their organisation
  28. */
  29. @Test
  30. public void testManageUsersPermission() throws CommandException {
  31. // populate with a known state and authenticate as user 3, who
  32. // has ManageUser permissions for Solidarites
  33. setUser(3); // Lisa from Solidarites
  34. // execute
  35. UserResult result = (UserResult) execute(new GetUsers(1));
  36. // VERIFY that we have 1 result:
  37. // - the one other solidarites user
  38. Assert.assertEquals("number of results", 1, result.getTotalLength());
  39. Assert.assertEquals("user name", "Marlene", result.getData().get(0).getName());
  40. }
  41. @Test
  42. public void testManageAllUsersPermission() throws CommandException {
  43. setUser(2); // Bavon from NRC(with manageAllUsers) permission
  44. // execute
  45. UserResult result = (UserResult) execute(new GetUsers(1));
  46. // VERIFY that we can get can see the two other users from NRC
  47. Assert.assertEquals("number of results", 2, result.getTotalLength());
  48. }
  49. }