/** * @see org.openmrs.Attributable#hydrate(java.lang.String) */ @Override public User hydrate(String userId) { try { return Context.getUserService().getUser(Integer.valueOf(userId)); } catch (Exception e) { return new User(); } }
/** * @see UserValidator#validate(Object,Errors) */ @Test public void validate_shouldNotThrowNPEWhenUserIsNull() { Errors errors = new BindException(new User(), "user"); validator.validate(null, errors); Assert.assertTrue(true); }
/** * @see AuditableInterceptor#onSave(Object,Serializable,Object[],String[],Type[]) */ @Test public void onSave_shouldReturnTrueIfCreatorWasNull() { AuditableInterceptor interceptor = new AuditableInterceptor(); User u = new User(); String[] propertyNames = new String[] { "creator", "dateCreated" }; Object[] currentState = new Object[] { null, new Date() }; boolean result = interceptor.onSave(u, 0, currentState, propertyNames, null); Assert.assertTrue(result); }
private User getEnterer(ORC orc) throws HL7Exception { XCN hl7Enterer = orc.getEnteredBy(0); Integer entererId = Context.getHL7Service().resolveUserId(hl7Enterer); if (entererId == null) { throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedEnterer")); } User enterer = new User(); enterer.setUserId(entererId); return enterer; }
@Test public void createUser_shouldNotAllowNullPassword() { User unsavedUser = new User(); expectedException.expect(ValidationException.class); userService.createUser(unsavedUser, null); }
@Test public void createUser_shouldNotAllowBlankPassword() { User unsavedUser = new User(); expectedException.expect(ValidationException.class); userService.createUser(unsavedUser, ""); }
/** * @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); }
@Before public void setUp() { user = new User(); user.addRole(new Role("Some Role", "This is a test role")); }
/** * @see BaseRetireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldNotSetRetiredByIfNonNull() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetiredBy(new User(3)); handler.handle(retireable, new User(2), null, " "); Assert.assertEquals(3, retireable.getRetiredBy().getId().intValue()); }
/** * @see PersonVoidHandler#handle(Person,User,Date,String) */ @Test public void handle_shouldNotSetPersonVoidedByIfNonNull() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); person.setPersonVoidedBy(new User(3)); handler.handle(person, new User(2), null, " "); assertEquals(3, person.getPersonVoidedBy().getId().intValue()); }
/** * @see Daemon#isDaemonUser(User user) * */ @Test public void isDaemonUser_shouldReturnFalseIFTheUserIsNotADaemon() { User user = new User(); user.setUuid("any other value"); Assert.assertFalse(Daemon.isDaemonUser(user)); } }
/** * @see UserService#changePassword(User,String,String) */ @Test public void changePassword_shouldThrowAPIExceptionIfGivenUserDoesNotExist() { //user.getUserId is null - so it is not existing user User notExistingUser = new User(); String anyString = "anyString"; expectedException.expect(APIException.class); expectedException.expectMessage(messages.getMessage("user.must.exist")); userService.changePassword(notExistingUser, anyString, anyString); }
/** * @see UserValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfEmailIsInvalid() { User user = new User(); user.setEmail("mkyong123@.com"); Errors errors = new BindException(user, "user"); validator.validate(user, errors); Assert.assertTrue(errors.hasFieldErrors("email")); }
/** * @see UserValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfEmailIsValid() { User user = new User(); user.setEmail("test@example.com"); Errors errors = new BindException(user, "user"); validator.validate(user, errors); Assert.assertFalse(errors.hasFieldErrors("email")); } }
private void invokeValidateAndAssertHasErrorRetireReason(String invalidRetireReason) { User user = new User(); user.setUsername("test"); user.setRetireReason(invalidRetireReason); user.setRetired(true); Errors errors = new BindException(user, "user"); validator.validate(user, errors); Assert.assertTrue(errors.hasFieldErrors("retireReason")); }
/** * @see BaseUnretireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldUnsetTheRetirer() { UnretireHandler<Retireable> handler = new BaseUnretireHandler(); Retireable retireable = new Location(); retireable.setRetired(true); retireable.setRetiredBy(new User(1)); handler.handle(retireable, null, null, null); Assert.assertNull(retireable.getRetiredBy()); }
/** * @see BaseUnvoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldUnsetTheVoider() { UnvoidHandler<Voidable> handler = new BaseUnvoidHandler(); Voidable voidable = new Person(); voidable.setVoided(true); voidable.setVoidedBy(new User(1)); handler.handle(voidable, null, null, null); Assert.assertNull(voidable.getVoidedBy()); }
/** * @see BaseRetireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldNotSetTheRetireReasonIfAlreadyVoided() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetired(true); retireable.setRetiredBy(new User()); handler.handle(retireable, null, null, "THE REASON"); Assert.assertNull(retireable.getRetireReason()); }
/** * @see PersonUnvoidHandler#handle(Person,User,Date,String) */ @Test public void handle_shouldUnsetThePersonVoider() { UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(true); person.setPersonVoidedBy(new User(1)); handler.handle(person, null, null, null); Assert.assertNull(person.getPersonVoidedBy()); }
/** * @see AuditableInterceptor#onSave(Object,Serializable,Object[],String[],Type[]) */ @Test public void onSave_shouldBeCalledWhenSavingOpenmrsObject() { User u = new User(); u.setSystemId("user"); u.setPerson(Context.getPersonService().getPerson(1)); Context.getUserService().createUser(u, "Admin123"); Assert.assertSame(Context.getAuthenticatedUser(), u.getCreator()); Assert.assertNotNull(u.getDateCreated()); }