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

Wired Integration Test: How to inject objects?

Frank July 12, 2021

I want to write an integration test for my plugin. Following the Atlassian tutorial, I can get a simple integration test run successfully. As soon as I need some classes from the Confluence environment for my test, I am stuck. According to the second section of the above mentioned tutorial, I can use the constructor of the test class to get these injected. I tried that, using the following code:

public class MyTest {
private final UserManager userManager;
private final ActiveObjects ao;

//@Inject
@Autowired
public MyTest(@ComponentImport UserManager userManager, @ComponentImport ActiveObjects ao) {
this.userManager = userManager;
this.ao = ao;
}

@Test
public void runTest() { }
}

the test fails when run from the Atlassian Plugin Test Console, and in the browser developer console, I find the following in the response for the test API call sent from the console:

...
fThrownException: {detailMessage: "Test class should have exactly one public zero-argument constructor",…}
  detailMessage: "Test class should have exactly one public zero-argument constructor"
...

I tried both Annotations, `@Autowired` and `@Inject`, getting the same result.

I also tried to add an empty constructor in addition to the one shown above so that I have two constructors in the class now:

 public MyTest() {
  this.userManager = null;
  this.ao = null;
}

This avoids the error, but no test is executed, hence this does not help.

Any idea how I can get references to environment objects like UserManager or ActiveObjects in an integration test? 

EDIT:

As I found no solution, I gave up on using the Atlassian provided integrated integration tests, and as an alternative set up a separate project for my integration tests just testing the REST calls using REST Assured.

1 answer

1 accepted

0 votes
Answer accepted
Fabian Lim
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 24, 2021

Thanks for the update.  Closing this ticket.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events