Validation of DirectiveSet processing



DirectiveSets enable email notifications to contain links (or nice AUI buttons) that the receiver can click, to affect issue update (including workflow transitions) securely, without authentication.  When one link is used in a DirectiveSet all links created in the same notification e.g. Approve/ Decline are removed, so there can be no retry.



The DirectiveSetTest class in the examples package shows how a full round trip integration test of DirectiveSet links can be done, in a nutshell it will:

  • Remove all existing DirectiveSets and DirectiveSetLinks in the system

  • Make admin the default assignee of the DST project

  • Upload a Test Case

  • Upload a Profile

  • Upload a custom IssueEvent TemplateSet containing the markup to add a DirectiveSet link

  • Setup EventListener single line TEXT custom fields for "Email Sender Address", "Email Sender Name" and multi-line TEXT "Email Participants" field.

  • Create DirectiveSet entries (the definitions, including the required JEMH Directives to drive workflow for 'approve' versus 'reject') - instance expected to be Software with default workflow for this to work!

  • Create a TemplateSetBean, updated to have the uploaded Profile's ID (CLICKBACK_PROFILE_ID) , and the DirectiveSet Action ID's (APPROVE_DIRECTIVE_SET_ID and REJECT_DIRECTIVE_SET_ID) referred.

  • Test Case execution, assertion that issue created (JEMH will be driven to process this event (created), and generate customized notifications), only one user should receive the DirectiveSet link

  • Jira mail queue is flushed, mail is delivered to the local Greenmail SMTP server

  • Assertion made over the number of created links (that happened during the email render phase)

Extracting generated mail content

This test demonstrates how mail pulled from Greenmail can have its content accessed.  The template content was modified around the DiectiveSet <A> tag manufacture to include an element id of form "jemh-ds-X" where X is the ID fo the approve workflow DirectiveSet, used in the test to identify its presence.

Two notifications should have occurred, the one to the email user should NOT contain the DirectiveSet link.  The one to the assignee SHOULD.  In that case, we actually invoke the URL of the Approve DirectiveSet, and finally make an assertion that the status of the Issue has changed to what we expect.

#awesomesauce!

Assert.assertTrue("Expected a directive set link to be generated, found "+count, count==2); MimeMessage[] messages = greenMail.getReceivedMessages(); ITMailUtil mailUtils = fTestHarness.getMailUtil(); for (int i = 0; i < messages.length; i++) { MimeMessage reloaded=reloadMessage(messages[i]); //logMessage(reloaded); InternetAddress addr=(InternetAddress)reloaded.getRecipients(RecipientType.TO)[0]; if (addr.getAddress().equals("andy@localhost")) { //validate that the sender email doesn't contain the link String content = mailUtils.getContent(messages[i], profile); Assert.assertFalse("Content for reporter should not be empty", content.isEmpty()); Assert.assertTrue("DirectiveSet link MUST NOT be present in mail to the originator", content.indexOf(CLICKBACK_URL)==-1); } else if (addr.getAddress().equals("admin@admin.com")) { String wikiContent = mailUtils.getContent(messages[i], profile); Assert.assertNotNull("Wiki content was null",wikiContent); String htmlContent = mailUtils.getExactContent(reloaded, true, profile); Assert.assertNotNull("RawHTML content was null",wikiContent); //validate the assignee DOES have the link. Assert.assertFalse("Content for assigneee with DirectiveSet link should not be empty", htmlContent.isEmpty()); Assert.assertTrue("DirectiveSet link MUST be present in mail to the assignee", htmlContent.indexOf(CLICKBACK_URL)!=-1); String href = mailUtils.getLinkHref(htmlContent, "a#jemh-ds-"+approveDS.getId()); Assert.assertNotNull("Link href was null", href); //todo use HTTP client to click the link ITWebUtil webUtil = fTestHarness.getWebUtil(); String response=webUtil.getUrl(href); //throw away notifications mailManager.clearJiraMailQueue(); Assert.assertNotNull("Expected to get a response from invocation",response); Assert.assertTrue(response.contains("JEMH DirectiveSet action completed")); //todo assert expected issue workflow state change Issue refreshedIssue = ComponentAccessor.getIssueManager().getIssueObject(createdIssue.getKey()); String statusName = refreshedIssue.getStatus().getName(); Assert.assertTrue("Expected issue status to now be In Progress, was: "+statusName, "In Progress".equals(statusName)); } }