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

It seems ComponentAccessor is not initialised in Jira integration tests

José Marañón [Awnaba Software S.L.]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 16, 2012

I am creating integration tests for a Jira plugin. I am using atlassian-plugin-sdk-3.8 (that targets Jira version 4.4.1).

The tests fail when they try to use ComponentAccessor functionality, with this stack trace:

-------------------------------------------------------------------------------
Test set: it.com.epelo.jiraplugins.loaders.JiraProjectHandlerTest
-------------------------------------------------------------------------------
Tests run: 3, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 96.595 sec <<< FAILURE!
testCreateProjectExists(it.com.epelo.jiraplugins.loaders.JiraProjectHandlerTest) Time elapsed: 6.403 sec <<< ERROR!
java.lang.IllegalStateException: ComponentAccessor has not been initialised.
at com.atlassian.jira.component.ComponentAccessor.getWorker(ComponentAccessor.java:816)
at com.atlassian.jira.component.ComponentAccessor.getComponentOfType(ComponentAccessor.java:109)
at com.atlassian.jira.component.ComponentAccessor.getProjectManager(ComponentAccessor.java:114)
at it.com.epelo.jiraplugins.loaders.JiraProjectHandlerTest.testGetProjectManager(JiraProjectHandlerTest.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at com.atlassian.jira.functest.framework.FuncTestCase.runTest(FuncTestCase.java:266)
at junit.framework.TestCase.runBare(TestCase.java:134)
at com.atlassian.jira.functest.framework.FuncTestCase.runBare(FuncTestCase.java:300)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:91)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

The failure is caused by this test:

@Test
public void testGetProjectManager() {

// In order to give Jira time to initialize everything before we start
// handling things...There was an error saying that the
// ComponentAccessor was not initialised
navigation.gotoPage("/secure/project/ViewProjects.jspa");
ProjectManager pm= ComponentAccessor.getProjectManager();

}

As the code shows, I even included a previous step to navigate to a page, thinking that would make everything initialised in jira, without success.

Thanks in advance!

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 14, 2012

When running unit tests, you need to mock API calls. The FuncTestCase stuff is for mocking user actions via UI and asserting the result from the UI, it won't help you with server side integration tests. see related question how-to-do-integration-testing-of-one-class-inside-a-running-instance-of-jira.

0 votes
lrobertson39
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2012

Hi Jose,

Are you still awaiting a response for this? Could you please include the section of your code which would indicate how you are using the ComponentAccessor class object and what methods you are calling on it? (If you dont declare the ComponentAccessor, you may be using the ComponentManager)

José Marañón [Awnaba Software S.L.]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 14, 2012

Hi Luke,

I would be very interested in getting a response to this question.

The section of code that causes the error is this:

ProjectManager pm= ComponentAccessor.getProjectManager();

This is executing inside a test method of a class that extends com.atlassian.jira.functest.framework.FuncTestCase;

Thanks for your interest in this question.

José Marañón

lrobertson39
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 15, 2012

Hi Jose,

As Andy answered below, the best way is to Mock these objects, however I too am unsure as to how you would go about doing this for integration tests. Although if you are extending the com.atlassian.jira.functest.framework.FuncTestCase it would suggest that you are writing unit tests?

Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 15, 2012

Uh no, FuncTestCases are integration test cases, the problem is they from 'out here' to 'in there' using http requests between. To run a test 'in there' is the trick. To reiterate 'out here' you have no running environment. You can use atlas-run yes, but that just spins up a local copy of 'in there', your test cases remain 'out here', Im pretty sure you will not get useful success trying to access ComponentAccessor like that, it only works 'in there' ?!

0 votes
José Marañón [Awnaba Software S.L.]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 29, 2012

Hi Petter,

No, I do not have a solution to this problem yet.

I guess that the cause is that the Atlassian SDK starts the container, Jira and the plugin in a JVM independent of the one that actually runs the tests. That would be the reason the tests do not "see" an active Jira instance.

My need is to test how some classes interact with the underlying Jira instance, without running a full functional test of the plugin.

Any idea will be welcome!

0 votes
Petter Machado August 28, 2012

Hi José, did you get anywhere with this? I'm facing a similar problem with JqlQueryBuilder...

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events