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);
}
}
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);
}
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);
}
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);
}
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());
}
Aggregations