/** * @see PrivilegeEditor#setAsText(String) */ @Test public void setAsText_shouldSetUsingUuid() { PrivilegeEditor editor = new PrivilegeEditor(); editor.setAsText("d979d066-15e6-467c-9d4b-cb575ef97f0f"); 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 { Privilege p = es.getPrivilege(text); setValue(p); //when a privilege is not found, no exception is generated. throw one to execute the catch block if (p == null) { throw new Exception(); } } catch (Exception ex) { Privilege p = es.getPrivilegeByUuid(text); setValue(p); if (p == null) { log.error("Error setting text: " + text, ex); throw new IllegalArgumentException("Privilege not found: " + ex.getMessage()); } } } else { setValue(null); } }
@Override public String getAsText() { Privilege p = (Privilege) getValue(); if (p == null) { return ""; } else { return p.getPrivilege(); } }
wdb.registerCustomEditor(PersonAttributeType.class, new PersonAttributeTypeEditor()); wdb.registerCustomEditor(Person.class, new PersonEditor()); wdb.registerCustomEditor(Privilege.class, new PrivilegeEditor()); wdb.registerCustomEditor(Program.class, new ProgramEditor()); wdb.registerCustomEditor(ProgramWorkflow.class, new ProgramWorkflowEditor());
/** * @see PrivilegeEditor#setAsText(String) */ @Test public void setAsText_shouldSetUsingName() { PrivilegeEditor editor = new PrivilegeEditor(); editor.setAsText("Some Privilege"); Assert.assertNotNull(editor.getValue()); }