PageRenderTime 21ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/groovy/com/ceilfors/jenkins/plugins/jiratrigger/JiraCommentTriggerTest.groovy

https://gitlab.com/CORP-RESELLER/jira-trigger-plugin
Groovy | 73 lines | 56 code | 14 blank | 3 comment | 0 complexity | 0a537c679b9feb5d49dce8005af8c0e7 MD5 | raw file
  1. package com.ceilfors.jenkins.plugins.jiratrigger
  2. import com.atlassian.jira.rest.client.api.domain.Comment
  3. import hudson.model.AbstractProject
  4. import hudson.model.ItemGroup
  5. import org.junit.Rule
  6. import org.jvnet.hudson.test.JenkinsRule
  7. import spock.lang.Specification
  8. import spock.lang.Unroll
  9. import static com.ceilfors.jenkins.plugins.jiratrigger.TestUtils.createIssue
  10. /**
  11. * @author ceilfors
  12. */
  13. @SuppressWarnings("GroovyAssignabilityCheck")
  14. class JiraCommentTriggerTest extends Specification {
  15. def project
  16. @Rule
  17. public JenkinsRule jenkinsRule = new JenkinsRule()
  18. def setup() {
  19. given:
  20. def projectParent = Mock(ItemGroup)
  21. projectParent.getFullName() >> ""
  22. project = Mock(AbstractProject)
  23. project.getParent() >> projectParent
  24. project.getName() >> "project"
  25. }
  26. @Unroll
  27. def "Triggers build when comment body matches the comment pattern"(String commentBody, String commentPattern) {
  28. given:
  29. def comment = new Comment(null, commentBody, null, null, null, null, null, null)
  30. JiraCommentTrigger trigger = new JiraCommentTrigger(commentPattern: commentPattern)
  31. when:
  32. trigger.start(project, false)
  33. trigger.run(createIssue("TEST-123"), comment)
  34. then:
  35. 1 * project.scheduleBuild(_, _, _)
  36. where:
  37. commentBody | commentPattern
  38. "please build me" | "please build me"
  39. "please build me" | "(?i)please build me"
  40. "PLEASE BUILD ME" | "(?i)please build me"
  41. "start\n\nplease build me\n\nend" | "(?s).*please build me.*"
  42. }
  43. @Unroll
  44. def "Does not trigger build when comment body matches the comment pattern"(String commentBody, String commentPattern) {
  45. given:
  46. def comment = new Comment(null, commentBody, null, null, null, null, null, null)
  47. JiraCommentTrigger trigger = new JiraCommentTrigger(commentPattern: commentPattern)
  48. when:
  49. trigger.start(project, false)
  50. trigger.run(createIssue("TEST-123"), comment)
  51. then:
  52. 0 * project.scheduleBuild(_, _, _)
  53. where:
  54. commentBody | commentPattern
  55. "please do not build me" | "please build me"
  56. " please build me" | "please build me"
  57. "please build me\n" | "please build me"
  58. }
  59. }