/** * @should set using name * @should set using uuid */ @Override public void setAsText(String text) throws IllegalArgumentException { UserService es = Context.getUserService(); if (StringUtils.hasText(text)) { try { Role r = es.getRole(text); setValue(r); //when a role is not found, no exception is generated. throw one to execute the catch block if (r == null) { throw new Exception(); } } catch (Exception ex) { Role r = es.getRoleByUuid(text); setValue(r); if (r == null) { log.error("Error setting text: " + text, ex); throw new IllegalArgumentException("Role not found: " + ex.getMessage()); } } } else { setValue(null); } }
/** * @see UserService#getRoleByUuid(String) */ @Test public void getRoleByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(userService.getRoleByUuid("some invalid uuid")); }
/** * @see UserService#getRoleByUuid(String) */ @Test public void getRoleByUuid_shouldFindObjectGivenValidUuid() { String uuid = "3480cb6d-c291-46c8-8d3a-96dc33d199fb"; Role role = userService.getRoleByUuid(uuid); Assert.assertEquals("Provider", role.getRole()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ @Override public Role getByUniqueId(String uniqueId) { return Context.getUserService().getRoleByUuid(uniqueId); }
/** * @param rolesParameter A comma separated list of role names or role UUIDs. May not be null. * @return A non-null list of existing {@link Role}s that may be empty, if no valid roles are * found. */ private List<Role> getRequestedRoles(final String rolesParameter) { final List<Role> result = new ArrayList<Role>(); final List<String> roleStrings = Arrays.asList(StringUtils.split(rolesParameter, ",")); for (String roleString : roleStrings) { // try with uuid Role role = Context.getUserService().getRoleByUuid(roleString); // try with display name if (role == null) { role = Context.getUserService().getRole(roleString); } // add if found if (role != null) { result.add(role); } } return result; }
@Override public Role newObject() { Role role = Context.getUserService().getRoleByUuid(getUuidProperty()); return role; }
/** * @see RoleController#search(String, javax.servlet.http.HttpServletRequest, * HttpServletResponse) * @verifies find matching Roles */ @Test @Ignore("Roles do not support searching yet.") public void findRoles_shouldFindMatchingRoles() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("q", "Provider"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(1, hits.size()); Assert.assertEquals(service.getRoleByUuid("3480cb6d-c291-46c8-8d3a-96dc33d199fb"), PropertyUtils.getProperty(hits.get(0), "uuid")); }
Assert.assertFalse(dependencies.contains(Context.getUserService().getRoleByUuid( "92b70b00-58b1-11e0-80e3-0800200c9a66"))); Assert.assertFalse(dependencies.contains(Context.getUserService().getRoleByUuid( "a238c500-58b1-11e0-80e3-0800200c9a66")));
Assert.assertTrue(dependencies.contains(Context.getUserService().getRoleByUuid( "92b70b00-58b1-11e0-80e3-0800200c9a66"))); Assert.assertTrue(dependencies.contains(Context.getUserService().getRoleByUuid( "a238c500-58b1-11e0-80e3-0800200c9a66")));
Assert.assertTrue(dependencies.contains(Context.getUserService().getRoleByUuid( "92b70b00-58b1-11e0-80e3-0800200c9a66"))); Assert.assertTrue(dependencies.contains(Context.getUserService().getRoleByUuid( "a238c500-58b1-11e0-80e3-0800200c9a66")));
Assert.assertTrue(dependencies.contains(Context.getUserService().getRoleByUuid( "92b70b00-58b1-11e0-80e3-0800200c9a66"))); Assert.assertTrue(dependencies.contains(Context.getUserService().getRoleByUuid( "a238c500-58b1-11e0-80e3-0800200c9a66")));
/** * @see RoleController#update(String, SimpleObject, javax.servlet.http.HttpServletRequest, * HttpServletResponse) * @verifies change a property on a Role */ @Test public void updateRole_shouldChangeAPropertyOnARole() throws Exception { final String editedDescription = "Role description edited"; String json = "{ \"description\":\"" + editedDescription + "\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Role editedRole = service.getRoleByUuid(getUuid()); Assert.assertNotNull(editedRole); Assert.assertEquals(editedDescription, editedRole.getDescription()); }
/** * @see RoleController#delete(String, String, javax.servlet.http.HttpServletRequest, * HttpServletResponse) * @verifies void a Role */ @Test public void retireRole_shouldRetireARole() throws Exception { Role role = service.getRoleByUuid(getUuid()); Assert.assertFalse(role.isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + role.getUuid()); req.addParameter("!purge", ""); req.addParameter("reason", "random reason"); handle(req); Role retiredRole = service.getRoleByUuid(getUuid()); Assert.assertTrue(retiredRole.isRetired()); Assert.assertEquals("random reason", retiredRole.getRetireReason()); }