/src/main/resources/com/onresolve/jira/groovy/test/TestCreateSubTask.groovy
Groovy | 133 lines | 91 code | 29 blank | 13 comment | 1 complexity | 842a173a8c2f056632769b2379e188be 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.fields.CustomField
-
- import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
- import com.atlassian.jira.issue.util.IssueChangeHolder
- import com.atlassian.jira.project.version.VersionManager
-
- 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.onresolve.jira.groovy.canned.workflow.postfunctions.CreateSubTask
- import com.atlassian.jira.issue.Issue
- import com.atlassian.jira.component.ComponentAccessor
- import com.atlassian.jira.ManagerFactory
-
- /**
- * User: jechlin2
- * Date: 13-Dec-2010
- * Time: 17:36:00
- */
- class TestCreateSubTask extends BaseSubTaskTest {
-
- Category log = Category.getInstance(this.class)
- MutableIssue newIssue
-
- @Before
- public void setUp() {
-
- tearDown()
-
- log.debug ("issueType: ${issueType.getName()}")
- assertNotNull(project)
-
- issue = componentManager.getIssueFactory().getIssue()
- issue.setProject(project.getGenericValue())
-
- issue.setSummary "my summary"
- issue.setAssigneeId "admin"
- issue.setReporterId "admin"
- issue.setIssueType issueType.getGenericValue()
- issue.setPriorityId('2')
-
- def issueSecurityLevelManager = ComponentAccessor.getIssueSecurityLevelManager()
- def issueSecuritySchemeManager = ManagerFactory.getIssueSecuritySchemeManager()
- def securitySchemes = issueSecuritySchemeManager.getSchemes(project.genericValue)
- assert (securitySchemes)
- def securityScheme = securitySchemes?.first()
- // todo: we never get here if no sec scheme
- // todo: all security levels should have the Anyone permission
- assertNotNull("Define a security scheme with at least a Private level", securityScheme)
- def secLevels = issueSecurityLevelManager.getSchemeIssueSecurityLevels(securityScheme.getLong("id"))
- def levelPrivate = secLevels.find {it.name == "Private"}
- assertNotNull(levelPrivate)
- issue.setSecurityLevel(levelPrivate)
-
- ProjectComponentManager projectComponentManager = componentManager.getProjectComponentManager()
- VersionManager versionManager = componentManager.getVersionManager()
-
- issue.setComponents(projectComponentManager.findAllForProject(project.id).collect{it.genericValue})
- issue.setAffectedVersions(versionManager.getVersions(project.id))
- issue.setFixVersions(versionManager.getVersions(project.id))
-
- issueManager.createIssue(adminUser, issue);
- log.debug ("Created issue: $issue")
- }
-
-
- // @After
- public void tearDown() {
- deleteAllIssues()
- }
-
- @Test
- public void testCreateSubtask() {
-
- 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);
-
- Map<String, Object> inputs = [
- issue: issue,
- (CreateSubTask.FIELD_SUBTASK_SUMMARY): 'abcd',
- (CreateSubTask.FIELD_TARGET_ISSUE_TYPE): '5', // subtask
- // todo: we should test additional actions, eg https://studio.plugins.atlassian.com/wiki/display/GRV/Script+Runner?focusedCommentId=66357419#comment-66357419
- // (CreateSubTask.FIELD_ADDITIONAL_SCRIPT): 'issue.summary = "Create subtask for " + originalIssue.summary', // subtask
- ] as Map<String, Object>
- log.debug ("inputs: $inputs")
-
- Map params = new CreateSubTask().doScript(inputs)
- assertNotNull(params['newIssue'])
- newIssue = params['newIssue'] as MutableIssue
- assertNotNull(newIssue)
-
- assertEquals("Private", newIssue.securityLevel?.get("name"))
-
- junit.framework.Assert.assertEquals (1, issue.getSubTaskObjects().size())
-
- Issue firstSub = issue.getSubTaskObjects().asList().first() as Issue
- log.debug("firstSub: $firstSub")
-
- // create another sub-task
-
- inputs = [
- issue: issue,
- (CreateSubTask.FIELD_SUBTASK_SUMMARY): 'efgh',
- (CreateSubTask.FIELD_TARGET_ISSUE_TYPE): '5', // subtask
- (CreateSubTask.FIELD_SUBTASK_ACTION) : '3 Reopen'
- ]
- params = new CreateSubTask().doScript(inputs)
- junit.framework.Assert.assertEquals (2, issue.getSubTaskObjects().size())
-
- MutableIssue secondSub = issue.getSubTaskObjects().asList().last() as MutableIssue
-
- // resolve the child and make sure the parent reopens it - as though parent was being transitioned to Open
- resolveIssue(secondSub)
- params = new CreateSubTask().doScript(inputs)
- secondSub = issue.getSubTaskObjects().asList().last() as MutableIssue
-
- // note if the reopened state is removed this will be Open, not reopened.
- assert ['Open', 'Reopened'].contains(secondSub.statusObject.name)
- }
- }