PageRenderTime 59ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/groovy/com/ceilfors/jenkins/plugins/jiratrigger/changelog/ChangelogMatcherTest.groovy

https://gitlab.com/github-cloud-corp/jira-trigger-plugin
Groovy | 144 lines | 113 code | 28 blank | 3 comment | 5 complexity | d6fbf1e7c6878463522e92a855982389 MD5 | raw file
  1. package com.ceilfors.jenkins.plugins.jiratrigger.changelog
  2. import com.atlassian.jira.rest.client.api.domain.ChangelogGroup
  3. import com.atlassian.jira.rest.client.api.domain.ChangelogItem
  4. import com.atlassian.jira.rest.client.api.domain.FieldType
  5. import spock.lang.Specification
  6. /**
  7. * @author ceilfors
  8. */
  9. class ChangelogMatcherTest extends Specification {
  10. private class BasicChangelogMatcher extends ChangelogMatcher {
  11. BasicChangelogMatcher(FieldType fieldType, String field, String newValue, String oldValue,
  12. boolean comparingNewValue, boolean comparingOldValue) {
  13. super(fieldType, field, newValue, oldValue, comparingNewValue, comparingOldValue)
  14. }
  15. }
  16. def "Should compare field value"(String fieldId, String matcherField, boolean result) {
  17. given:
  18. ChangelogGroup changelogGroup = new ChangelogGroup(null, null, [
  19. new ChangelogItem(FieldType.JIRA, fieldId, "", "", "", "")
  20. ])
  21. when:
  22. def matcher = new BasicChangelogMatcher(FieldType.JIRA, matcherField, "", "", false, false)
  23. then:
  24. matcher.matches(changelogGroup) == result
  25. where:
  26. fieldId | matcherField | result
  27. "status" | "status" | true
  28. "status" | "description" | false
  29. "description" | "status" | false
  30. "description" | "description" | true
  31. }
  32. def "Should handle multiple changelog item"(List<String> fieldIds, boolean result) {
  33. given:
  34. ChangelogGroup changelogGroup = new ChangelogGroup(null, null, fieldIds.collect {
  35. new ChangelogItem(FieldType.JIRA, it, null, null, null, null)
  36. })
  37. when:
  38. def matcher = new BasicChangelogMatcher(FieldType.JIRA, "status", "", "", false, false)
  39. then:
  40. matcher.matches(changelogGroup) == result
  41. where:
  42. fieldIds | result
  43. ["status", "description"] | true
  44. ["description", "status"] | true
  45. ["description", "summary"] | false
  46. ["description", "status", "summary"] | true
  47. }
  48. def "Should compare new value when comparingNewValue flag is on"(
  49. String newValue, String matcherNewValue, boolean result) {
  50. given:
  51. ChangelogGroup changelogGroup = new ChangelogGroup(null, null, [
  52. new ChangelogItem(FieldType.JIRA, "status", "", "", "", newValue)
  53. ])
  54. when:
  55. def matcher = new BasicChangelogMatcher(FieldType.JIRA, "status", matcherNewValue, "", true, false)
  56. then:
  57. matcher.matches(changelogGroup) == result
  58. where:
  59. newValue | matcherNewValue | result
  60. "new value" | "new value" | true
  61. "new value" | "NEW VALUE" | true
  62. "2" | "1" | false
  63. "@@" | "!!" | false
  64. "" | "" | true
  65. null | "" | true
  66. }
  67. def "Should not compare new value when comparingNewValue flag is off"(
  68. String newValue, String matcherNewValue, boolean result) {
  69. given:
  70. ChangelogGroup changelogGroup = new ChangelogGroup(null, null, [
  71. new ChangelogItem(FieldType.JIRA, "status", "", "", "", newValue)
  72. ])
  73. when:
  74. def matcher = new BasicChangelogMatcher(FieldType.JIRA, "status", matcherNewValue, "", false, false)
  75. then:
  76. matcher.matches(changelogGroup)
  77. where:
  78. newValue | matcherNewValue | result
  79. "2" | "1" | true
  80. "@@" | "!!" | true
  81. }
  82. def "Should compare old value when comparingOldValue flag is on"(
  83. String oldValue, String matcherOldValue, boolean result) {
  84. given:
  85. ChangelogGroup changelogGroup = new ChangelogGroup(null, null, [
  86. new ChangelogItem(FieldType.JIRA, "status", "", oldValue, "", "")
  87. ])
  88. when:
  89. def matcher = new BasicChangelogMatcher(FieldType.JIRA, "status", "", matcherOldValue, false, true)
  90. then:
  91. matcher.matches(changelogGroup) == result
  92. where:
  93. oldValue | matcherOldValue | result
  94. "old value" | "old value" | true
  95. "old value" | "OLD VALUE" | true
  96. "2" | "1" | false
  97. "@@" | "!!" | false
  98. "" | "" | true
  99. null | "" | true
  100. }
  101. def "Should not compare old value when comparingOldValue flag is off"(
  102. String oldValue, String matcherOldValue, boolean result) {
  103. given:
  104. ChangelogGroup changelogGroup = new ChangelogGroup(null, null, [
  105. new ChangelogItem(FieldType.JIRA, "status", "", oldValue, "", "")
  106. ])
  107. when:
  108. def matcher = new BasicChangelogMatcher(FieldType.JIRA, "status", "", matcherOldValue, false, false)
  109. then:
  110. matcher.matches(changelogGroup) == result
  111. where:
  112. oldValue | matcherOldValue | result
  113. "2" | "1" | true
  114. "@@" | "!!" | true
  115. }
  116. }