/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/GetUsersTest.java
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 6package org.sigmah.server.endpoint.gwtrpc; 7 8import org.junit.Assert; 9import org.junit.Test; 10import org.junit.runner.RunWith; 11import org.sigmah.server.dao.OnDataSet; 12import org.sigmah.shared.command.GetUsers; 13import org.sigmah.shared.command.result.UserResult; 14import org.sigmah.shared.exception.CommandException; 15import org.sigmah.test.InjectionSupport; 16 17@RunWith(InjectionSupport.class) 18@OnDataSet("/dbunit/sites-simple1.db.xml") 19public class GetUsersTest extends CommandTestCase { 20 21 private final static int DATABASE_OWNER = 1; 22 23 @Test 24 public void testUnsorted() throws CommandException { 25 setUser(DATABASE_OWNER); 26 27 GetUsers cmd = new GetUsers(1); 28 UserResult result = (UserResult) execute(cmd); 29 30 Assert.assertEquals(3, result.getData().size()); 31 } 32 33 /** 34 * Verify that users with ManageUsers permission can get a list of users 35 * within their organisation 36 */ 37 @Test 38 public void testManageUsersPermission() throws CommandException { 39 // populate with a known state and authenticate as user 3, who 40 // has ManageUser permissions for Solidarites 41 setUser(3); // Lisa from Solidarites 42 43 // execute 44 UserResult result = (UserResult) execute(new GetUsers(1)); 45 46 // VERIFY that we have 1 result: 47 // - the one other solidarites user 48 49 Assert.assertEquals("number of results", 1, result.getTotalLength()); 50 Assert.assertEquals("user name", "Marlene", result.getData().get(0).getName()); 51 } 52 53 @Test 54 public void testManageAllUsersPermission() throws CommandException { 55 56 setUser(2); // Bavon from NRC(with manageAllUsers) permission 57 58 // execute 59 UserResult result = (UserResult) execute(new GetUsers(1)); 60 61 // VERIFY that we can get can see the two other users from NRC 62 Assert.assertEquals("number of results", 2, result.getTotalLength()); 63 } 64}