PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/src/test/groovy/com/ceilfors/jenkins/plugins/jiratrigger/parameter/IssueAttributePathParameterResolverTest.groovy

https://gitlab.com/github-cloud-corp/jira-trigger-plugin
Groovy | 64 lines | 49 code | 11 blank | 4 comment | 3 complexity | 793417879045d3c98b9d2e44c51234aa MD5 | raw file
  1. package com.ceilfors.jenkins.plugins.jiratrigger.parameter
  2. import com.atlassian.jira.rest.client.api.domain.Issue
  3. import com.atlassian.jira.rest.client.internal.json.IssueJsonParser
  4. import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
  5. import hudson.model.StringParameterValue
  6. import org.codehaus.jettison.json.JSONObject
  7. import spock.lang.Specification
  8. import spock.lang.Unroll
  9. /**
  10. * @author ceilfors
  11. */
  12. class IssueAttributePathParameterResolverTest extends Specification {
  13. private Issue createIssueFromFile(issueKey) {
  14. def issueJsonObject = new JSONObject(this.class.getResource("${issueKey}.json").text)
  15. return new IssueJsonParser(new JSONObject([:]), new JSONObject([:])).parse(issueJsonObject)
  16. }
  17. @Unroll
  18. def "Should be able to resolve parameter by hitting JIRA"(String attributePath, String attributeValue) {
  19. given:
  20. IssueAttributePathParameterResolver resolver = new IssueAttributePathParameterResolver()
  21. when:
  22. IssueAttributePathParameterMapping mapping = new IssueAttributePathParameterMapping("parameter", attributePath)
  23. StringParameterValue result = resolver.resolve(createIssueFromFile("TEST-136"), mapping)
  24. then:
  25. result != null
  26. result.value == attributeValue
  27. result.name == "parameter"
  28. where:
  29. attributePath | attributeValue
  30. "key" | "TEST-136"
  31. "project.key" | "TEST"
  32. "id" | 11120
  33. "timeTracking.originalEstimateMinutes" | 5
  34. "status.name" | "To Do"
  35. "summary" | "summary content"
  36. }
  37. @Unroll
  38. def "Should throw exception when parameter is not resolvable"(String attributePath) {
  39. given:
  40. IssueAttributePathParameterResolver resolver = new IssueAttributePathParameterResolver()
  41. when:
  42. IssueAttributePathParameterMapping mapping = new IssueAttributePathParameterMapping("unused", attributePath)
  43. resolver.resolve(createIssueFromFile("TEST-136"), mapping)
  44. then:
  45. thrown JiraTriggerException
  46. where:
  47. //noinspection SpellCheckingInspection
  48. attributePath << [
  49. "timeTracking.originalEstimateSeconds",
  50. "typo"
  51. ]
  52. }
  53. }