Feature - Jira testing
Description
Included with GINT is an extension that providessimple testing or automation of Atlassian JIRA capabilities and plugins. This extension is also an example of how the GINT framework can be extended to provide integration testing of diverse environments.
Dependencies
- JIRA Command Line Interface (CLI) - installed on the client running the test
How does it work?
Testcases use the JIRA command generator that produces the necessary CLI commands based on relatively simple testcase parameters relating to JIRA testing. Helper functions provide ways to retrieve JIRA server information, issue ids, and project ids.
Usage
- Functions are provided to do some standard things for macro testing
- getCreateProjectTestcase and getDeleteProjectTestcase - normally used for setUp and tearDown
- getProjectName and setProjectName - normally just use the default name constructed from prefix and test name
- getProjectKey and setProjectKey - normally just use the default key constructed from the space name
- isServerAvailable and getServerInfo - for getting version and other information about the configured JIRA server
- noTearDown is set to true by default so that the JIRA project and issues that are created by the testing are preserved after the test completes. This helps for doing manual verifications and debugging. An explicit tearDown target can be run to remove the space.
- See dependencies above. GINT requires the jiraCli property be defined and point to the CLI - normally set in the user's or project's gint.properties file.
- See detailed information - Command generator for Jira
Example
This example is from the GINT integration test. It includes code to bypass the test if suitable JIRA configuration is not available allowing allowing the integration test to run error free on any system. This example also includes an example of using CURL using the Command generator for CURL to access JIRA for testing actions not available through the JIRA CLI.
GintForJira
- includeTool << org.swift.tools.GintForJira includes the gint framework with special extensions for JIRA testing.
jiraTest.gant
@GrabResolver(name='atlassian', root='https://maven.atlassian.com/content/groups/public/') @Grab(group='org.swift.tools', module='gint', version='1.8.2') import org.swift.tools.* includeTool << org.swift.tools.Helper // helper object for general utility functions includeTool << org.swift.tools.GintForJira // gint framework with extensions for JIRA testing gint.initialize(this) // required // cli or jiraCli must be set info = gint.getServerInfoWithVerify() // need JIRA server level check later //def v60 = (info?.version >= '6.0') // use to test if JIRA server is at least a specific version saved = [:] // Save dynamically created information - must be a global variable Closure createdIssueClosure = { testcase -> saved.createdIssue = gint.searchForIssueKey(testcase.outData) helper.logWithFormat('saved', saved) } Closure createdIssueIdClosure = { testcase -> def matcher = (testcase.outData =~ /${saved.createdIssue} \((\d+)\)/) saved.createdIssueId = (matcher.find() ? matcher.group(1) : null) helper.logWithFormat('saved', saved) } Closure createdIssueIdViaCurlClosure = { testcase -> if (saved.createdIssueIdViaCurl == null) { //matcher = (helper.readFile(testcase.output.file) =~ /issueId=(\d+)/) matcher = (gint.readFile(testcase) =~ /issueId=(\d+)/) // short way to get output file saved.createdIssueIdViaCurl = (matcher.find() ? matcher.group(1) : null) } helper.logWithFormat('saved', saved) } // Get the project id Closure projectIdClosure = { testcase -> def matcher = (testcase.outData =~ /${project.toUpperCase()}, (\d+),/) saved.projectId = (matcher.find() ? matcher.group(1) : null) helper.logWithFormat('saved', saved) } // Closure to get the atl_token from the data from a curl request def atlassianTokenClosure = { testcase -> saved.atlassianToken = gint.searchForAtlassianToken(new File(testcase.output.file)) } // For curl access to JIRA, need url and authentication jiraUrl = helper.getParameterValue('jiraUrl') jiraUser = helper.getParameterValue('jiraUser') jiraPassword = helper.getParameterValue('jiraPassword') project = gint.getProjectKey() attachment = this.getClass().getName() + '.gant' summary = 'Summary_make_this_unique_for_text_search' gint.addSetUp(gint.getCreateProjectTestcase()) // creates a default project gint.addTearDown(gint.getDeleteProjectTestcase()) // required when createProjectTestcase is added  gint.add('base', [ [action: "createIssue", description: 'Create an issue in the default project', project: project, parameters: [summary: summary, type: 1], finalClosure: createdIssueClosure, // used to set createIssue variable with key for issue created data: ['created'], ], [action: "addAttachment", description: 'Add attachment to created issue', depends: 'createIssue', issue: { -> saved.createdIssue }, // note closure syntax since createdIssue is only valid after createIssue testcase runs file: attachment, data: ['added to issue'], ], [action: "getProjectList", description: 'Get project id', data: [gint.getProjectKey()], finalClosure: projectIdClosure, ], [name: "getIssue", description: 'Get issue and issue id', depends: 'createIssue', issue: { -> saved.createdIssue }, // note closure syntax since createdIssue is only valid after createIssue testcase runs data: summary, finalClosure: [createdIssueIdClosure], ], [name: "getIssueViaCurl", description: 'Using curl to access JIRA', level: helper.isNotBlank(jiraUrl), depends: 'createIssue', cmdGenerator: gint.getCmdGenerator('curl', [user: jiraUser, password: jiraPassword]), url: "${jiraUrl}/browse/${ { -> saved.createdIssue } }", output: [data: summary], finalClosure: [createdIssueIdViaCurlClosure, atlassianTokenClosure], ], [name: "compareCreatedIssueId", description: 'Compare CLI verses curl to obtain the id', level: helper.isNotBlank(jiraUrl), depends: ['getIssue', 'getIssueViaCurl'], inline: { assert saved.createdIssueId == saved.createdIssueIdViaCurl } ], [name: 'checkAtlassianToken', description: 'Make sure atlassian token retrieved correctly', level: helper.isNotBlank(jiraUrl), depends: 'getIssueViaCurl', inline: { assert saved.atlassianToken != null }, ], ]) gint.finalizeTest() // final preparations for running tests Â
© 2005 -2024 gint.org