Search in sources :

Example 46 with User

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));
}
Also used : User(org.openmrs.User) HashMap(java.util.HashMap) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 47 with User

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"));
}
Also used : User(org.openmrs.User) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 48 with User

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");
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 49 with User

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"));
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 50 with User

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);
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

User (org.openmrs.User)201 Test (org.junit.Test)150 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)132 Date (java.util.Date)38 Person (org.openmrs.Person)33 Encounter (org.openmrs.Encounter)21 Patient (org.openmrs.Patient)18 PersonName (org.openmrs.PersonName)17 Role (org.openmrs.Role)13 GlobalProperty (org.openmrs.GlobalProperty)11 Location (org.openmrs.Location)11 ArrayList (java.util.ArrayList)10 EncounterType (org.openmrs.EncounterType)10 Locale (java.util.Locale)7 UserService (org.openmrs.api.UserService)7 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 EncounterRole (org.openmrs.EncounterRole)6 PatientIdentifier (org.openmrs.PatientIdentifier)6