use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method saveUserProperties_shouldRemoveAllExistingPropertiesAndAssignNewProperties.
@Test
public void saveUserProperties_shouldRemoveAllExistingPropertiesAndAssignNewProperties() {
executeDataSet(XML_FILENAME);
// retrieve a user who has UserProperties
User user = userService.getUser(5511);
assertEquals(1, user.getUserProperties().size());
// Authenticate the test user so that Context.getAuthenticatedUser() method returns above user
Context.authenticate(user.getUsername(), "testUser1234");
final String USER_PROPERTY_KEY_1 = "test-key1";
final String USER_PROPERTY_VALUE_1 = "test-value1";
final String USER_PROPERTY_KEY_2 = "test-key2";
final String USER_PROPERTY_VALUE_2 = "test-value2";
Map<String, String> propertiesMap = new HashMap<>();
propertiesMap.put(USER_PROPERTY_KEY_1, USER_PROPERTY_VALUE_1);
propertiesMap.put(USER_PROPERTY_KEY_2, USER_PROPERTY_VALUE_2);
propertiesMap = Collections.unmodifiableMap(propertiesMap);
User updatedUser = userService.saveUserProperties(propertiesMap);
// we should have only the new properties
assertEquals(2, updatedUser.getUserProperties().size());
// Verify that the new properties were saved
assertEquals(USER_PROPERTY_VALUE_1, updatedUser.getUserProperty(USER_PROPERTY_KEY_1));
assertEquals(USER_PROPERTY_VALUE_2, updatedUser.getUserProperty(USER_PROPERTY_KEY_2));
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method changeQuestionAnswer_shouldChangeTheSecretQuestionAndAnswerForGivenUser.
/**
* @see UserService#changeQuestionAnswer(User,String,String)
*/
@Test
@Ignore
public // TODO fix: the question not sticking - null expected:<[the question]> but was:<[]>
void changeQuestionAnswer_shouldChangeTheSecretQuestionAndAnswerForGivenUser() {
User u = userService.getUser(501);
userService.changeQuestionAnswer(u, "the question", "the answer");
// need to retrieve the user since the service method does not modify the given user object
User o = userService.getUser(501);
Assert.assertTrue(userService.isSecretAnswer(o, "the answer"));
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method changePassword_shouldBeAbleToUpdatePasswordMultipleTimes.
/**
* Test changing a user's password multiple times in the same transaction
*
* @see UserService#changePassword(String,String)
*/
@Test
public void changePassword_shouldBeAbleToUpdatePasswordMultipleTimes() {
User u = userService.getUserByUsername(ADMIN_USERNAME);
assertNotNull("There needs to be a user with username 'admin' in the database", u);
userService.changePassword("test", "Tester12");
userService.changePassword("Tester12", "Tester13");
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method setUserProperty_shouldModifyPropertyWithGivenKeyAndValueWhenKeyAlreadyExists.
/**
* @see UserService#setUserProperty(User,String,String)
*/
@Test
public void setUserProperty_shouldModifyPropertyWithGivenKeyAndValueWhenKeyAlreadyExists() {
executeDataSet(XML_FILENAME);
User user = userService.getUser(5505);
// Check that it already exists
Assert.assertEquals(user.getUserProperty("some key"), "some value");
userService.setUserProperty(user, "some key", "some new value");
user = userService.getUser(5505);
Assert.assertEquals("some new value", user.getUserProperty("some key"));
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method createUser_shouldNotAllowSystemIdEqualsExistingUsername.
@Test
public void createUser_shouldNotAllowSystemIdEqualsExistingUsername() {
User someUser = userService.getUserByUsername(SOME_USERNAME);
User newUser = userWithValidPerson();
newUser.setSystemId(someUser.getUsername());
expectedException.expect(DAOException.class);
expectedException.expectMessage(String.format("Username %s or system id %s is already in use.", newUser.getUsername(), newUser.getSystemId()));
userService.createUser(newUser, SOME_VALID_PASSWORD);
}
Aggregations