/** * @see RoleEditor#setAsText(String) */ @Test public void setAsText_shouldSetUsingName() { RoleEditor editor = new RoleEditor(); editor.setAsText("Provider"); Assert.assertNotNull(editor.getValue()); }
/** * @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); } }
@Override public String getAsText() { Role r = (Role) getValue(); if (r == null) { return ""; } else { return r.getRole(); } }
wdb.registerCustomEditor(ProgramWorkflowState.class, new ProgramWorkflowStateEditor()); wdb.registerCustomEditor(Provider.class, new ProviderEditor()); wdb.registerCustomEditor(Role.class, new RoleEditor()); wdb.registerCustomEditor(User.class, new UserEditor()); wdb.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, NumberFormat
/** * @see RoleEditor#setAsText(String) */ @Test public void setAsText_shouldSetUsingUuid() { RoleEditor editor = new RoleEditor(); editor.setAsText("3480cb6d-c291-46c8-8d3a-96dc33d199fb"); Assert.assertNotNull(editor.getValue()); } }