/src/main/resources/com/onresolve/jira/groovy/test/TestCloneIssue.groovy
Groovy | 137 lines | 92 code | 30 blank | 15 comment | 5 complexity | 6958cd50e3c0a77edd05e7735d15780b MD5 | raw file
- package com.onresolve.jira.groovy.test
-
- import com.atlassian.jira.bc.project.component.ProjectComponentManager
- import com.atlassian.jira.issue.CustomFieldManager
- import com.atlassian.jira.issue.ModifiedValue
- import com.atlassian.jira.issue.MutableIssue
- import com.atlassian.jira.issue.comments.Comment
- import com.atlassian.jira.issue.fields.CustomField
- import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
- import com.atlassian.jira.issue.util.IssueChangeHolder
- import com.atlassian.jira.project.version.VersionManager
- import com.onresolve.jira.groovy.canned.workflow.postfunctions.CloneIssue
- import org.apache.log4j.Category
- import org.junit.After
- import org.junit.Before
- import org.junit.Test
- import static junit.framework.Assert.assertEquals
- import static junit.framework.Assert.assertNotNull
- import com.atlassian.jira.issue.link.IssueLinkTypeManager
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.component.ComponentAccessor
- import com.atlassian.jira.issue.label.LabelManager
-
- /**
- * User: jechlin2
- * Date: 13-Dec-2010
- * Time: 17:36:00
- */
- class TestCloneIssue extends BaseSubTaskTest {
-
- Category log = Category.getInstance(this.class)
- MutableIssue newIssue
-
- TestCloneIssue() {
- // def gcl = this.class.classLoader.parent
- // gcl.clearCache()
- }
-
- @Before
- public void setUp() {
-
- tearDown()
-
- log.debug ("setUp")
-
- log.debug ("issueType: ${issueType.getName()}")
- assertNotNull(project)
-
- this.issue = componentManager.getIssueFactory().getIssue()
- this.issue.setProject(project.getGenericValue())
-
- this.issue.setSummary "my summary"
- this.issue.setReporterId "admin"
- this.issue.setIssueType issueType.getGenericValue()
- this.issue.setPriorityId('2')
- ProjectComponentManager projectComponentManager = componentManager.getProjectComponentManager()
- VersionManager versionManager = componentManager.getVersionManager()
-
- this.issue.setComponents(projectComponentManager.findAllForProject(project.id).collect{it.genericValue})
- this.issue.setAffectedVersions(versionManager.getVersions(project.id))
- this.issue.setFixVersions(versionManager.getVersions(project.id))
-
- issueManager.createIssue(adminUser, issue);
- log.debug ("Created issue: ${this.issue}")
-
- ["mylabel", "xyzlabel"].each {
- labelManager.addLabel(componentManager.jiraAuthenticationContext.user, issue.id, it, false)
- }
- }
-
-
- // @After
- public void tearDown() {
- deleteAllIssues()
- }
-
- @Test
- public void testCloneIssue() {
- // why - comments are not cloned
- Comment comment = componentManager.getCommentManager().create(issue, adminUser.name, "My comment", false)
- assertNotNull(componentManager.projectManager.getProjectByKey('JRTWO'))
-
- // add an attachment
- def attachmentManager = componentManager.getAttachmentManager()
-
- def file = File.createTempFile("abc", ".txt")
- file.withWriter {Writer w ->
- w.write("some text")
- }
- attachmentManager.createAttachment(file, file.name, "text/plain", adminUser, issue.genericValue)
- file.delete()
-
- CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
- CustomField cf = customFieldManager.getCustomFieldObjectByName('GlobalCfTtype')
- assertNotNull (cf)
- IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
- cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), "new cf value"),changeHolder);
-
- IssueLinkTypeManager issueLinkTypeManager = (IssueLinkTypeManager) componentManager.getComponentInstanceOfType(IssueLinkTypeManager.class)
- Long clonersId = issueLinkTypeManager.getIssueLinkTypes().find{it.name == "Cloners"}.id
-
- Map<String, Object> inputs = [
- issue: issue,
- (CloneIssue.FIELD_TARGET_PROJECT): 'JRTWO',
- (CloneIssue.FIELD_LINK_TYPE): clonersId as String,
- (CloneIssue.FIELD_ADDITIONAL_SCRIPT): 'issue.setDescription("custom desc")'
- ] as Map<String, Object>
- log.debug ("inputs: $inputs")
-
- Map params = new CloneIssue().doScript(inputs)
- assertNotNull(params['newIssue'])
- newIssue = params['newIssue'] as MutableIssue
-
- // check the custom field is copied across
- assertEquals("new cf value", newIssue.getCustomFieldValue(cf))
-
- // check the component is cloned
- assertNotNull newIssue.components.find {it.name == "Comp1"}
-
- // check the affectVersion is cloned
- assertNotNull newIssue.affectedVersions.find {it.name == "Version1"}
- assertNotNull newIssue.fixVersions.find {it.name == "Version1"}
-
- // check links
- junit.framework.Assert.assertEquals(1, issueLinkManager.getInwardLinks(newIssue.getId()).size())
-
- // check overrides
- assertEquals("custom desc", newIssue.getDescription())
-
- def attachments = attachmentManager.getAttachments(newIssue)
-
- assertEquals (1, attachments.size())
- assertEquals (file.name, attachments.first().filename)
-
- assert ["mylabel", "xyzlabel"] == labelManager.getLabels(newIssue.id)*.getLabel()
- }
- }