@Override protected User getObjectByUuid(String uuid) { return Context.getUserService().getUserByUuid(uuid); } }
/** * @see UserService#getUserByUuid(String) */ @Test public void getUserByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(userService.getUserByUuid("some invalid uuid")); }
User daemonUser = Context.getUserService().getUserByUuid(Daemon.getDaemonUserUuid()); alert.setCreator(daemonUser);
/** * @see UserService#getUserByUuid(String) */ @Test public void getUserByUuid_shouldFindObjectGivenValidUuid() { String uuid = "c1d8f5c2-e131-11de-babe-001e378eb67e"; User user = userService.getUserByUuid(uuid); Assert.assertEquals(501, (int) user.getUserId()); }
@Test @SkipBaseSetup public void getUserByUuid_shouldFetchUserWithGivenUuid() throws SQLException { initializeInMemoryDatabase(); executeDataSet(XML_FILENAME); authenticate(); User user = userService.getUserByUuid("013c49c6-e132-11de-babe-001e378eb67e"); assertEquals("Did not fetch user with given uuid", user, userService.getUser(5505)); }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#getByUniqueId(java.lang.String) */ @Override public User getByUniqueId(String string) { return Context.getUserService().getUserByUuid(string); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public UserAndPassword1_8 getByUniqueId(String uuid) { return new UserAndPassword1_8(Context.getUserService().getUserByUuid(uuid)); }
@RequestMapping(value = "/{userUuid}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void changeOthersPassword(@PathVariable("userUuid") String userUuid, @RequestBody Map<String, String> body) { String newPassword = body.get("newPassword"); Context.addProxyPrivilege(PrivilegeConstants.VIEW_USERS); Context.addProxyPrivilege("Get Users"); // support later versions of OpenMRS User user; try { user = userService.getUserByUuid(userUuid); } finally { Context.removeProxyPrivilege(PrivilegeConstants.VIEW_USERS); Context.removeProxyPrivilege("Get Users"); } if (user == null || user.getUserId() == null) { throw new NullPointerException(); } else { userService.changePassword(user, newPassword); } }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.SearchHandler#search(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public PageableResult search(RequestContext context) throws ResponseException { String userUuid = context.getParameter("user"); User user = Context.getUserService().getUserByUuid(userUuid); if (user == null) { return new EmptySearchResult(); } Person person = user.getPerson(); List<Provider> providers = (List<Provider>) Context.getProviderService().getProvidersByPerson(person); return new NeedsPaging<Provider>(providers, context); }
@Override public UserAndPassword1_8 newObject() { UserAndPassword1_8 userAndPassword = new UserAndPassword1_8(Context.getUserService() .getUserByUuid(getUuidProperty())); userAndPassword.setPassword("topsecret"); return userAndPassword; }
@Override public UserAndPassword1_8 newObject() { UserAndPassword1_8 userAndPassword = new UserAndPassword1_8(Context.getUserService() .getUserByUuid(getUuidProperty())); userAndPassword.setPassword("topsecret"); return userAndPassword; }
/** * @see UserController#findUsers(String,WebRequest,HttpServletResponse) * @throws Exception * @verifies find matching users */ @Test public void findUsers_shouldFindMatchingUsers() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("q", "but"); SimpleObject result = deserialize(handle(req)); Assert.assertNotNull(result); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(1, hits.size()); Util.log("Found " + hits.size() + " user(s)", result); Assert.assertEquals(service.getUserByUuid(getUuid()).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); }
/** * @see UserController#findUsers(String,WebRequest,HttpServletResponse) * @throws Exception * @verifies find matching users */ @Test public void findUsers_shouldFindMatchingUsers() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("q", "but"); SimpleObject result = deserialize(handle(req)); Assert.assertNotNull(result); List<Object> hits = (List<Object>) result.get("results"); assertEquals(1, hits.size()); Util.log("Found " + hits.size() + " user(s)", result); assertEquals(service.getUserByUuid(getUuid()).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); }
/** * @see UserController#updateUser(UserAndPassword1_8,SimpleObject,WebRequest) * @throws Exception * @verifies change a property on a patient */ @Test public void updateUser_shouldChangeAPropertyOnAUser() throws Exception { User user = service.getUserByUuid(getUuid()); Assert.assertNotNull(user); Assert.assertFalse("5-6".equals(user.getSystemId())); Util.log("Old User SystemId: ", user.getSystemId()); String json = "{\"systemId\":\"5-6\",\"password\":\"Admin@123\"}"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); User editedUser = service.getUserByUuid(getUuid()); Assert.assertNotNull(editedUser); Assert.assertEquals("5-6", editedUser.getSystemId()); Util.log("Edited User SystemId: ", editedUser.getSystemId()); }
/** * @see UserController#updateUser(UserAndPassword1_8,SimpleObject,WebRequest) * @throws Exception * @verifies change a property on a patient */ @Test public void updateUser_shouldChangeAPropertyOnAUser() throws Exception { User user = service.getUserByUuid(getUuid()); Assert.assertNotNull(user); Assert.assertFalse("5-6".equals(user.getSystemId())); Util.log("Old User SystemId: ", user.getSystemId()); String json = "{\"systemId\":\"5-6\",\"password\":\"Admin@123\"}"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); User editedUser = service.getUserByUuid(getUuid()); Assert.assertNotNull(editedUser); assertEquals("5-6", editedUser.getSystemId()); Util.log("Edited User SystemId: ", editedUser.getSystemId()); }
/** * @see UserController#retireUser(User,String,WebRequest) * @throws Exception * @verifies void a patient */ @Test public void retireUser_shouldRetireAUser() throws Exception { User user = service.getUserByUuid(getUuid()); Assert.assertFalse(user.isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + user.getUuid()); req.addParameter("!purge", ""); req.addParameter("reason", "unit test"); handle(req); User retiredUser = service.getUserByUuid(getUuid()); Assert.assertTrue(retiredUser.isRetired()); Assert.assertEquals("unit test", retiredUser.getRetireReason()); }
/** * @see UserController#retireUser(User,String,WebRequest) * @throws Exception * @verifies void a patient */ @Test public void retireUser_shouldRetireAUser() throws Exception { User user = service.getUserByUuid(getUuid()); Assert.assertFalse(user.isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + user.getUuid()); req.addParameter("!purge", ""); req.addParameter("reason", "unit test"); handle(req); User retiredUser = service.getUserByUuid(getUuid()); assertTrue(retiredUser.isRetired()); assertEquals("unit test", retiredUser.getRetireReason()); }
assertEquals(originalCount + 1, getAllCount()); User createdUser = service.getUserByUuid(getUuid()); Assert.assertNotNull(createdUser); assertTrue(createdUser.hasRole("Provider"));
@Test public void updateUser_shouldUpdateTheUserPassword() throws Exception { User user = service.getUserByUuid(RestTestConstants1_8.USER_UUID); assertNotNull(user); assertNotEquals(user, Context.getAuthenticatedUser()); final String username = user.getUsername(); final String newPassword = "SomeOtherPassword123"; ContextAuthenticationException exception = null; try { Context.authenticate(username, newPassword); } catch (ContextAuthenticationException e) { exception = e; } assertNotNull(exception); assertEquals("Invalid username and/or password: " + username, exception.getMessage()); handle(newPostRequest("password" + "/" + user.getUuid(), "{\"newPassword\":\"" + newPassword + "\"}")); Context.logout(); Context.authenticate(username, newPassword); assertEquals(user, Context.getAuthenticatedUser()); }
@Test public void updateUser_shouldUpdateTheUserPassword() throws Exception { User user = service.getUserByUuid(getUuid()); assertNotNull(user); assertNotEquals(user, Context.getAuthenticatedUser()); final String username = user.getUsername(); final String newPassword = "SomeOtherPassword123"; ContextAuthenticationException exception = null; try { Context.authenticate(username, newPassword); } catch (ContextAuthenticationException e) { exception = e; } assertNotNull(exception); assertEquals("Invalid username and/or password: " + username, exception.getMessage()); handle(newPostRequest(getURI() + "/" + user.getUuid(), "{\"password\":\"" + newPassword + "\"}")); Context.logout(); Context.authenticate(username, newPassword); assertEquals(user, Context.getAuthenticatedUser()); }