Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Field's script doesn't see issue links created during unit test setup Edited

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?

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Do Not Lose your Customer’s Trust

Missing deadlines is one of the biggest problems every team lead wants to avoid when dealing with managed services. When the customer contracts your company to help with IT services it is expected th...

24 views 0 0
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you