Search in sources :

Example 86 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserDAOTest method getUsers_shouldEscapeSqlWildcardsInSearchPhrase.

@Test
public void getUsers_shouldEscapeSqlWildcardsInSearchPhrase() {
    User u = new User();
    u.setPerson(new Person());
    u.getPerson().setGender("M");
    // we used to also test %, but UserValidator actually doesn't allow that in usernames. TODO: remove the loop
    String[] wildcards = new String[] { "_" };
    // with the wildcards and carry out a search for that user
    for (String wildcard : wildcards) {
        PersonName name = new PersonName(wildcard + "cats", wildcard + "and", wildcard + "dogs");
        name.setDateCreated(new Date());
        u.addName(name);
        u.setUsername(wildcard + "test" + wildcard);
        Context.getUserService().createUser(u, "Openmr5xy");
        // we expect only one matching name or or systemId  to be returned
        int size = dao.getUsers(wildcard + "ca", null, false, null, null).size();
        assertEquals(1, size);
        // if actually the search returned the matching name or system id
        String userName = (dao.getUsers(wildcard + "ca", null, false, null, null).get(0).getUsername());
        assertEquals("Test failed since no user containing the character " + wildcard + " was found, ", wildcard + "test" + wildcard, userName);
    }
}
Also used : PersonName(org.openmrs.PersonName) User(org.openmrs.User) Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 87 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class AuditableInterceptorTest method onFlushDirty_shouldNotFailWithNullPreviousState.

/**
 * @see AuditableInterceptor#onFlushDirty(Object,Serializable,Object[],Object[],String[],Type[])
 */
@Test
public void onFlushDirty_shouldNotFailWithNullPreviousState() {
    AuditableInterceptor interceptor = new AuditableInterceptor();
    User u = new User();
    // sanity check
    Assert.assertTrue(u instanceof Auditable);
    String[] propertyNames = new String[] { "changedBy", "dateChanged" };
    Object[] currentState = new Object[] { "", null };
    interceptor.onFlushDirty(u, null, currentState, null, propertyNames, null);
}
Also used : Auditable(org.openmrs.Auditable) User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 88 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class AuditableInterceptorTest method onFlushDirty_shouldBeCalledWhenSavingAnAuditable.

/**
 * This test makes sure that the AuditableInterceptor is registered on the session
 *
 * @see AuditableInterceptor#onFlushDirty(Object,Serializable,Object[],Object[],String[],Type[])
 */
@Test
public void onFlushDirty_shouldBeCalledWhenSavingAnAuditable() {
    User u = Context.getUserService().getUser(1);
    u.setUsername("asdf");
    Date beforeDate = u.getDateChanged();
    Context.getUserService().saveUser(u);
    Date afterDate = u.getDateChanged();
    Assert.assertNotSame(beforeDate, afterDate);
}
Also used : User(org.openmrs.User) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 89 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class AuditableInterceptorTest method onSave_shouldReturnFalseIfDateCreatedAndCreatorWasNotNull.

/**
 * @see AuditableInterceptor#onSave(Object,Serializable,Object[],String[],Type[])
 */
@Test
public void onSave_shouldReturnFalseIfDateCreatedAndCreatorWasNotNull() {
    AuditableInterceptor interceptor = new AuditableInterceptor();
    User u = new User();
    String[] propertyNames = new String[] { "creator", "dateCreated" };
    Object[] currentState = new Object[] { 0, new Date() };
    boolean result = interceptor.onSave(u, 0, currentState, propertyNames, null);
    Assert.assertFalse(result);
}
Also used : User(org.openmrs.User) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 90 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class BaseVoidHandlerTest method handle_shouldNotSetVoidedByIfNonNull.

/**
 * @see BaseVoidHandler#handle(Voidable,User,Date,String)
 */
@Test
public void handle_shouldNotSetVoidedByIfNonNull() {
    VoidHandler<Voidable> handler = new BaseVoidHandler();
    Voidable voidable = new Person();
    voidable.setVoidedBy(new User(3));
    handler.handle(voidable, new User(2), null, " ");
    Assert.assertEquals(3, voidable.getVoidedBy().getId().intValue());
}
Also used : User(org.openmrs.User) Voidable(org.openmrs.Voidable) Person(org.openmrs.Person) Test(org.junit.Test)

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