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

Bitbucket plugin export-package issue

Mathieu Yargeau August 4, 2016

I am trying to do very simple integration tests, but I am unable to export the plugin package to use it in the tests. I am trying to follow the example given by the skeleton created by the atlas-create-bitbucket-plugin command, and the documentation page, but it is not working.

 

The class I am trying to test is in the folder 'src\main\java\com\company\RequestValidator\main'

Package name of RepoInit.java: 'com.company.RequestValidator.main'

 

My integration test file is in the folder: '\src\test\java\it\com\company\RequestValidator'

 

Skeleton integration test 'RepoInitTest.java'

package it.com.company.RequestValidator;
import static org.junit.Assert.assertEquals;
import org.junit.runner.RunWith;
import com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner;
import com.company.RequestValidator.main.RepoInit;
 
@RunWith(AtlassianPluginsTestRunner.class)
public class RepoInitTest
{
	private final RepoInit repoInit;


    public RepoInitTest(RepoInit repoInit)
	{
		this.repoInit = repoInit;
	}
 
    @Test
	public void testRepoCreated()
	{
		assertEquals("Not matching!", "r", "r");
    }
}

 

pom.xml

<modelVersion>4.0.0</modelVersion>
    <groupId>com.company</groupId>
    <artifactId>RequestValidator</artifactId>
    <version>2.2.0</version>
 
    <build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>bitbucket-maven-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <products>
                        <product>
                            <id>bitbucket</id>
                            <instanceId>bitbucket</instanceId>
                            <version>${bitbucket.version}</version>
                            <dataVersion>${bitbucket.data.version}</dataVersion>
                        </product>
                    </products>
                    
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <!-- Add package to export here -->
                        <Export-Package>
                            RequestValidator.main,
                        </Export-Package>
                        <!-- Add package import here -->
                        <Import-Package>
                            org.springframework.osgi.*;resolution:="optional",
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            *
                        </Import-Package>
                        <!-- Ensure plugin is Spring powered -->
                        <Spring-Context>*</Spring-Context>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

 

atlassian-plugin.xml (the one for my tests in folder '\src\test\resources')

<atlassian-plugin key="${project.groupId}.${project.artifactId}-tests" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
    </plugin-info>
    <!-- from our base plugin -->
    <component-import key="repoInit" interface="com.company.RequestValidator.main.RepoInit"/>
    <!-- from the product container -->
    <component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties" />
    
</atlassian-plugin>

 

I tried several things (too many to list), for several hours, but cannot run any integration tests (with atlas-debug command and then using the console or atlas-integration-test command)

 

This gives me the error

[INFO] [talledLocalContainer] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repo-init-test' defined in URL [bundle://22.0:0/META-INF/spring/atlassian-plugins-components.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.company.RequestValidator.main.RepoInit]: : No qualifying bean of type [com.company.RequestValidator.main.RepoInit] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.company.RequestValidator.main.RepoInit] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

 

However, during my trial and error, I had errors where no beans were defined (fixed by adding the reference in Atlassian-plugin.xml), errors about not being able to load 'com.company.RequestValidator-tests' (timeout, without any other stack errors in the log).

 

Desperate, I copied the example, but it still does not work, what am I doing wrong?

 

Now, I am getting this error

[INFO] [talledLocalContainer] 2016-08-05 11:03:02,369 WARN  [spring-startup]  c.a.plugin.manager.PluginEnabler Plugin 'com.company.RequestValidator-tests' did not enable within 5 seconds.The plugin  should not take this long to enable. Will only attempt to load plugin for another '25' seconds.

[INFO] [talledLocalContainer] 2016-08-05 11:03:27,394 ERROR [spring-startup] c.a.plugin.osgi.factory.OsgiPlugin Plugin 'com.company.RequestValidator-tests' never resolved service '&repoInit' with filter '(objectClass=com.company.RequestValidator.main.RepoInit)'

[INFO] [talledLocalContainer] 2016-08-05 11:03:27,427 ERROR [spring-startup] c.a.plugin.manager.PluginEnabler Unable to start the following plugins due to timeout while waiting for plugin to enable: com.company.RequestValidator-tests

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Josh Wheeler
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 5, 2016

While I've never been able to get any sort of tests to work in the Atlassian framework, the error `org.springframework.beans.factory.UnsatisfiedDependencyException` is a good place to start. What the error is saying, from my limited understanding of Spring, is that Spring couldn't resolve the constructor parameter `RepoInit repoInit` in `RepoInitTest.java`. This is where I've spent hours banging my head against the wall. Atlassian, at the moment, is moving to "transformerless" plugins where you can use Atlassian's flavor of Spring annotations for dependency injection instead of multiple `<component-import>` statements in your `atlassian-plugin.xml` file. I, personally, have never been able to get this to work (my last attempt was several months ago), but you're welcome to try and decipher the Atlassian Spring Scanner documentation.  My suggestion, would be to use the "transformed" approach, as it's the only one I've ever successfully used. To do this, you only have to modify one line in your `pom.xml`:

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;com.atlassian.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;bitbucket-maven-plugin&lt;/artifactId&gt;
            &lt;version&gt;${amps.version}&lt;/version&gt;
            &lt;extensions&gt;true&lt;/extensions&gt;
            &lt;configuration&gt;
                &lt;products&gt;
                    &lt;product&gt;
                        &lt;id&gt;bitbucket&lt;/id&gt;
                        &lt;instanceId&gt;bitbucket&lt;/instanceId&gt;
                        &lt;version&gt;${bitbucket.version}&lt;/version&gt;
                        &lt;dataVersion&gt;${bitbucket.data.version}&lt;/dataVersion&gt;
                    &lt;/product&gt;
                &lt;/products&gt;
                 
                &lt;instructions&gt;
					&lt;!-- The entry below enables/disables Atlassian Spring Scanner --&gt;
                    &lt;!-- &lt;Atlassian-Plugin-Key&gt;${atlassian.plugin.key}&lt;/Atlassian-Plugin-Key&gt; --&gt;
                    &lt;!-- Add package to export here --&gt;
                    &lt;Export-Package&gt;
                        RequestValidator.main,
                    &lt;/Export-Package&gt;
                    &lt;!-- Add package import here --&gt;
                    &lt;Import-Package&gt;
                        org.springframework.osgi.*;resolution:="optional",
                        org.eclipse.gemini.blueprint.*;resolution:="optional",
                        *
                    &lt;/Import-Package&gt;
                    &lt;!-- Ensure plugin is Spring powered --&gt;
                    &lt;Spring-Context&gt;*&lt;/Spring-Context&gt;
                &lt;/instructions&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

By commenting out the `<Atlassian-Plugin-Key>` in the `com.atlassian.maven.plugins.bitbucket-maven-plugin` should allow for the transformer to do it's job and do the dependency injection for you.


As a side note, if you'd like to try the Atlassian Spring Scanner method, you'll have to remove the `<component-import>` statements from the `atlassian-plugin.xml` file and mark the constructor with `@Autowired` and each injected dependency with `@ComponentImport` (the doc says that if you have any `<component-import>` statements, it'll break Atlassian Spring Scanner). Also, depending on whether Atlassian Spring Scanner uses version one or two in Bitbucket, you might have to add `@Scanned` to the class.

Please let me know if any of this helps!

Mathieu Yargeau August 5, 2016

Commenting that line in pom.xml was still giving me errors, but they were different, about a RespositoryHookService bean not found. The repository hook service is the first parameter of the RepoInit class I am trying to import. I had to add all component-import tags in the test atlassian-plugin.xml file (the same that were in the original plugin's atlassian-plugin.xml). SpringFramework method was not working for me, unless I was doing it wrong. After doing that, I was able to run the `atlassian-integration-test` command correclty. However, when starting it with `atlas-debug` and going in the Atlassian Plugin Test Console (so that I can modify that tests and run them again without having to stop and start a new server), I have the error `"POST /rest/fastdev/1.0/reload/withtests HTTP/1.1" c.a.p.r.c.s.j.XsrfResourceFilter XSRF checks failed for request: http://localhost:7990/bitbucket/rest/fastdev/1.0/reload/withtests , origin: http://localhost:7990 , referrer: http://localhost:7990/bitbucket/plugins/servlet/it-test-console`

Josh Wheeler
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 5, 2016

Ha ha, wow. A XSRF (Cross-site request forgery) error when running locally - that's impressive. Can you post your code on Bitbucket/Github? Without looking at your code, the best idea I have at the moment is to read the doc Run Wired Tests with the Plugin Test Console.  If you're unable to post your code I'd still be interested in seeing if I can duplicate the error.

P.S. I updated the Atlassian Spring Scanner part of my answer above to mark the imports with `@ComponentImport` instead of `@Component`

TAGS
AUG Leaders

Atlassian Community Events