use of org.openmrs.Role in project openmrs-core by openmrs.
the class UserServiceTest method saveRole_shouldSaveGivenRoleToTheDatabase.
/**
* @see UserService#saveRole(Role)
*/
@Test
public void saveRole_shouldSaveGivenRoleToTheDatabase() {
Role role = new Role("new role", "new desc");
userService.saveRole(role);
Assert.assertNotNull(userService.getRole("new role"));
}
use of org.openmrs.Role in project openmrs-core by openmrs.
the class UserServiceTest method createUser_shouldShouldCreateUserWhoIsPatientAlready.
@Test
@SkipBaseSetup
public void createUser_shouldShouldCreateUserWhoIsPatientAlready() throws SQLException {
// create the basic user and give it full rights
initializeInMemoryDatabase();
// authenticate to the temp database
authenticate();
assertTrue("The context needs to be correctly authenticated to by a user", Context.isAuthenticated());
// add in some basic data
executeDataSet(XML_FILENAME);
// the user should not exist yet
User preliminaryFetchedUser = userService.getUser(2);
assertNull(preliminaryFetchedUser);
// get the person object we'll make into a user
Person personToMakeUser = Context.getPersonService().getPerson(2);
// this avoids a lazy init exception, since we're going to clear the session
((Patient) personToMakeUser).getIdentifiers().size();
Context.clearSession();
// this is the user object we'll be saving
User user = new User(personToMakeUser);
user.setUsername("bwolfe");
user.setSystemId("asdf");
// included in xml file
user.addRole(new Role("Some Role", "This is a test role"));
// make sure everything was added to the user correctly
assertTrue(user.getUsername().equals("bwolfe"));
assertTrue(user.hasRole("Some Role"));
// do the actual creating of the user object
userService.createUser(user, "Openmr5xy");
Assert.assertNotNull("User was not created", userService.getUser(user.getUserId()));
Integer shouldCreateUserWhoIsPatientAlreadyTestUserIdCreated = user.getUserId();
Context.flushSession();
// get the same user we just created and make sure the user portion exists
User fetchedUser = userService.getUser(shouldCreateUserWhoIsPatientAlreadyTestUserIdCreated);
User fetchedUser3 = userService.getUser(3);
if (fetchedUser3 != null) {
throw new RuntimeException("There is a user with id #3");
}
assertNotNull("Uh oh, the user object was not created", fetchedUser);
assertNotNull("Uh oh, the username was not saved", fetchedUser.getUsername());
assertTrue("Uh oh, the username was not saved", fetchedUser.getUsername().equals("bwolfe"));
assertTrue("Uh oh, the role was not assigned", fetchedUser.hasRole("Some Role"));
Context.clearSession();
List<User> allUsers = userService.getAllUsers();
assertEquals(11, allUsers.size());
// there should still only be the one patient we created in the xml file
List<Patient> allPatientsSet = Context.getPatientService().getAllPatients();
assertEquals(1, allPatientsSet.size());
}
use of org.openmrs.Role in project openmrs-core by openmrs.
the class UserServiceTest method getUsers_shouldNotFailIfRolesAreSearchedButNameIsEmpty.
/**
* This is a regression test for TRUNK-2108 <br>
*
* @see UserService#getUsers(String,List,boolean)
*/
@Test
public void getUsers_shouldNotFailIfRolesAreSearchedButNameIsEmpty() {
Role role = new Role("Provider");
List<Role> roles = new ArrayList<>();
roles.add(role);
Assert.assertEquals(2, userService.getUsers("", roles, true).size());
}
use of org.openmrs.Role in project openmrs-core by openmrs.
the class UserServiceTest method getUsers_shouldFetchUsersWithAtLeastOneOfTheGivenRoleObjects.
/**
* @see UserService#getUsers(String,List,boolean)
*/
@Test
public void getUsers_shouldFetchUsersWithAtLeastOneOfTheGivenRoleObjects() {
executeDataSet(XML_FILENAME);
List<Role> roles = Collections.singletonList(new Role("Some Role"));
Assert.assertEquals(1, userService.getUsers("Susy Kingman", roles, false).size());
}
use of org.openmrs.Role in project openmrs-core by openmrs.
the class UserServiceTest method purgeRole_shouldDeleteGivenRoleFromDatabase.
/**
* @see UserService#purgeRole(Role)
*/
@Test
public void purgeRole_shouldDeleteGivenRoleFromDatabase() {
executeDataSet(XML_FILENAME);
Role role = userService.getRole("Some Role To Delete");
userService.purgeRole(role);
Assert.assertNull(userService.getRole("Some Role To Delete"));
}
Aggregations