PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/resources/com/onresolve/jira/groovy/test/TestCloneIssue.groovy

https://bitbucket.org/sorin/jira-plugin-intellij
Groovy | 137 lines | 92 code | 30 blank | 15 comment | 5 complexity | 6958cd50e3c0a77edd05e7735d15780b MD5 | raw file
  1. package com.onresolve.jira.groovy.test
  2. import com.atlassian.jira.bc.project.component.ProjectComponentManager
  3. import com.atlassian.jira.issue.CustomFieldManager
  4. import com.atlassian.jira.issue.ModifiedValue
  5. import com.atlassian.jira.issue.MutableIssue
  6. import com.atlassian.jira.issue.comments.Comment
  7. import com.atlassian.jira.issue.fields.CustomField
  8. import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
  9. import com.atlassian.jira.issue.util.IssueChangeHolder
  10. import com.atlassian.jira.project.version.VersionManager
  11. import com.onresolve.jira.groovy.canned.workflow.postfunctions.CloneIssue
  12. import org.apache.log4j.Category
  13. import org.junit.After
  14. import org.junit.Before
  15. import org.junit.Test
  16. import static junit.framework.Assert.assertEquals
  17. import static junit.framework.Assert.assertNotNull
  18. import com.atlassian.jira.issue.link.IssueLinkTypeManager
  19. import com.atlassian.jira.ComponentManager
  20. import com.atlassian.jira.component.ComponentAccessor
  21. import com.atlassian.jira.issue.label.LabelManager
  22. /**
  23. * User: jechlin2
  24. * Date: 13-Dec-2010
  25. * Time: 17:36:00
  26. */
  27. class TestCloneIssue extends BaseSubTaskTest {
  28. Category log = Category.getInstance(this.class)
  29. MutableIssue newIssue
  30. TestCloneIssue() {
  31. // def gcl = this.class.classLoader.parent
  32. // gcl.clearCache()
  33. }
  34. @Before
  35. public void setUp() {
  36. tearDown()
  37. log.debug ("setUp")
  38. log.debug ("issueType: ${issueType.getName()}")
  39. assertNotNull(project)
  40. this.issue = componentManager.getIssueFactory().getIssue()
  41. this.issue.setProject(project.getGenericValue())
  42. this.issue.setSummary "my summary"
  43. this.issue.setReporterId "admin"
  44. this.issue.setIssueType issueType.getGenericValue()
  45. this.issue.setPriorityId('2')
  46. ProjectComponentManager projectComponentManager = componentManager.getProjectComponentManager()
  47. VersionManager versionManager = componentManager.getVersionManager()
  48. this.issue.setComponents(projectComponentManager.findAllForProject(project.id).collect{it.genericValue})
  49. this.issue.setAffectedVersions(versionManager.getVersions(project.id))
  50. this.issue.setFixVersions(versionManager.getVersions(project.id))
  51. issueManager.createIssue(adminUser, issue);
  52. log.debug ("Created issue: ${this.issue}")
  53. ["mylabel", "xyzlabel"].each {
  54. labelManager.addLabel(componentManager.jiraAuthenticationContext.user, issue.id, it, false)
  55. }
  56. }
  57. // @After
  58. public void tearDown() {
  59. deleteAllIssues()
  60. }
  61. @Test
  62. public void testCloneIssue() {
  63. // why - comments are not cloned
  64. Comment comment = componentManager.getCommentManager().create(issue, adminUser.name, "My comment", false)
  65. assertNotNull(componentManager.projectManager.getProjectByKey('JRTWO'))
  66. // add an attachment
  67. def attachmentManager = componentManager.getAttachmentManager()
  68. def file = File.createTempFile("abc", ".txt")
  69. file.withWriter {Writer w ->
  70. w.write("some text")
  71. }
  72. attachmentManager.createAttachment(file, file.name, "text/plain", adminUser, issue.genericValue)
  73. file.delete()
  74. CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
  75. CustomField cf = customFieldManager.getCustomFieldObjectByName('GlobalCfTtype')
  76. assertNotNull (cf)
  77. IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
  78. cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), "new cf value"),changeHolder);
  79. IssueLinkTypeManager issueLinkTypeManager = (IssueLinkTypeManager) componentManager.getComponentInstanceOfType(IssueLinkTypeManager.class)
  80. Long clonersId = issueLinkTypeManager.getIssueLinkTypes().find{it.name == "Cloners"}.id
  81. Map<String, Object> inputs = [
  82. issue: issue,
  83. (CloneIssue.FIELD_TARGET_PROJECT): 'JRTWO',
  84. (CloneIssue.FIELD_LINK_TYPE): clonersId as String,
  85. (CloneIssue.FIELD_ADDITIONAL_SCRIPT): 'issue.setDescription("custom desc")'
  86. ] as Map<String, Object>
  87. log.debug ("inputs: $inputs")
  88. Map params = new CloneIssue().doScript(inputs)
  89. assertNotNull(params['newIssue'])
  90. newIssue = params['newIssue'] as MutableIssue
  91. // check the custom field is copied across
  92. assertEquals("new cf value", newIssue.getCustomFieldValue(cf))
  93. // check the component is cloned
  94. assertNotNull newIssue.components.find {it.name == "Comp1"}
  95. // check the affectVersion is cloned
  96. assertNotNull newIssue.affectedVersions.find {it.name == "Version1"}
  97. assertNotNull newIssue.fixVersions.find {it.name == "Version1"}
  98. // check links
  99. junit.framework.Assert.assertEquals(1, issueLinkManager.getInwardLinks(newIssue.getId()).size())
  100. // check overrides
  101. assertEquals("custom desc", newIssue.getDescription())
  102. def attachments = attachmentManager.getAttachments(newIssue)
  103. assertEquals (1, attachments.size())
  104. assertEquals (file.name, attachments.first().filename)
  105. assert ["mylabel", "xyzlabel"] == labelManager.getLabels(newIssue.id)*.getLabel()
  106. }
  107. }