You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I'm following the ScriptRunner template for configuring unit tests of my Script Field, which is working in Jira. I'm debugging the unit tests in IntelliJ using the sample project config that launches a local Jira instance. This is what my test looks like:
@RunWith(ScriptRunnerTestRunner)
class TestingEnvironmentFieldIT extends AbstractScriptFieldSpecification {
//...
def "Test Case Name"() {
setup:
def project = getTestProject()
def issueParams = new IssueInputParametersImpl()
issueParams.with {
setProjectId(project.id)
setIssueTypeId(issueTypeID)
setReporterId(user.name)
setSummary("test ticket")
}
when:
def createValidationResult = issueService.validateCreate(currentUser, issueParams)
then:
assert createValidationResult.isValid()
when:
def issue = (MutableIssue)issueService.create(currentUser, createValidationResult).issue
assert issue.isCreated()
def linkedTicket = // created during global setup
assert linkedTicket != null
issueLinkManager.createIssueLink(linkedTicket.getId(), issue.getId(), testingLinkType.getId(), 0L, currentUser)
then:
def fieldValue = issue.getCustomFieldValue(fieldUnderTest)
assert fieldValue.contains("Expected Value")
}
}
And this is the code in my Script Field that I've stripped down to demonstrate the issue:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def linkManager = ComponentAccessor.getIssueLinkManager()
def linkedIssues = linkManager.getInwardLinks(((Issue)issue).getId())
return linkedIssues.collect { it.getSourceObject().getKey() }.join(", ")
I get an empty string back on the final assertion line. I'm confident the code to get the issue links works, and I'm even pretty confident the code to create issue links works, since I've tried querying the links in the unit test code and I see that the links are created. Why aren't they coming back in my unit test?