Archive for the ‘atlassian’ Category.

Atlassian® as a Web-App Framework

News Flash: I’m a big fan of Atlassian®.

Not only are all of their apps highly useful, but they are, for the most part, pretty consistent when it comes to installation and plugin management.

Essentially, you extract a zip of the app, edit a [app-name]-init.properties file and include a path where you’d like the app’s home directory to live, and start the app. At this point, the app is running with some pre-bundled plugins and provides a plugins folder within the specified home directory where you can drop in new plugins.

Simple.

Now if you’re like me, at some point you’ll think that it would be pretty awesome if there was an easy way to make your own webapps behave in this same way including full spring support, auto-home directory creation, bundled plugins, etc, etc.

Lucky for you, I’ve done all the ground work, and I’ve packaged it up into something I call the Atlas Webapp Kit

Although I’ve called it the Atlas Webapp Kit, I am in no way associated with Atlassian®.
This Project is solely a result of my own tinkering.

Source

The result of this project will be a war file that can be used as a starting point to build an Atlassian®-like webapp.

The source code can be checked out from subversion:

svn co http://svn.sysbliss.com/public/atlassian-webappkit/trunk

Alternatively, you can download a source gzip file.

Lastly, you can download a binary of the war file.

Project Structure

The project is structured as a maven multi-module project with a parent module and two children:

  • atlas-webappkit – the parent pom
    • atlas-webappkit-core – all of the java code for the app
    • atlas-webappkit-webapp – the webapp descriptors and such

The Parent POM

Rather than waste bits by listing the parent pom, just take a look at it’s source.
It’s pretty basic in that it lists our child modules, sets up dependency and plugin versions and lists the repositories needed.
That’s it.

The Webapp

refplatform-webapp-structure

We’re starting with the webapp since it’s pretty simple and will provide us with some context when we get to the core project.

First let’s do a quick overview of the files since there are only a few of them:

  • bundled-plugins.xml – a simple descriptor used by the maven assembly plugin to zip up any plugins we want to bundle
  • applicationContextBootstrap.xml – a spring beans file for use during the bootstrap process
  • applicationContextPlugins.xml – a spring beans file for initializing the plugins framework
  • log4j.properties – you should know what this is
  • refplatform-init.properties – the properties file that holds our home directory path
  • context.xml – the file to map our url/context in tomcat
  • web.xml – the main web app descriptor
  • index.jsp – just a placeholder jsp

Since we are doing a couple of interesting things during the build, I think it’s worthwhile to have a look at the pom.xml for the webapp module….


Webapp POM

The top of the pom is pretty normal, just inherits the parent pom and sets the project details and so we’ll skip to the interesting stuff.

Defining Bundled Plugins

Lines 23-82 are used to configure the maven-dependency plugin which we’re using to resolve the plugin artifacts we want to bundle with our app and copy them to the ${pluginBundleDirectory}

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-bundled-plugins</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${pluginBundleDirectory}</outputDirectory>
                            <artifactItems>
 
                                <artifactItem>
                                    <groupId>org.apache.felix</groupId>
                                    <artifactId>org.apache.felix.webconsole</artifactId>
                                    <version>1.2.10</version>
                                </artifactItem>
 
                                !!! Others Removed To Save Space !!!
 
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Lines 84-102 use the maven assembly plugin to create a zip file containing the bundled plugins we just copied and put it in the classpath of the resulting war

Notice on line 87 we specify the finalName as atlassian. This will result in our zip file being named atlassian-bundled-plugins.zip
We’ll need to use this name later to extract the bundle.

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <finalName>atlassian</finalName>
                    <descriptors>
                        <descriptor>src/main/assembly/bundled-plugins.xml</descriptor>
                    </descriptors>
                    <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>create-bundled-plugins</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

The next section of the full pom sets up cargo for testing and is not listed here.

Creating our context

Remember the context.xml file? It’s used to map our context url to our webapp, however since our final war contains a version number which may change, we need to use some maven “magic” to ensure tomcat maps it properly.

Notice our context.xml uses the ${project.version} maven variable

context.xml

1
2
<?xml version="1.0" encoding="UTF-8"?>
    <Context path="/atlas-webappkit" docBase="webapps/atlas-webappkit-webapp-${project.version}"/>

And on lines 126-141 of our pom, we use the maven-war-plugin to process and filter the context.xml which does the variable substitution for us

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-war-plugin</artifactId>
                 <configuration>
                     <webResources>
                         <webResource>
                             <directory>${basedir}/src/main/webapp/META-INF</directory>
                             <includes>
                                 <include>context.xml</include>
                             </includes>
                             <targetPath>META-INF</targetPath>
                             <filtering>true</filtering>
                         </webResource>
                     </webResources>
                 </configuration>
             </plugin>

Dependencies

Since we’ve split out all the actual java code to a separate module, our dependency list for the webapp is tiny.
We just need our core jar and log4j

145
146
147
148
149
150
151
152
153
154
155
156
157
158
    <dependencies>
        <dependency>
            <groupId>com.atlassian.refplatform</groupId>
            <artifactId>atlas-webappkit-core</artifactId>
            <version>${parent.version}</version>
        </dependency>
 
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.9</version>
        </dependency>
 
    </dependencies>

And finally, we need to define the pluginBundleDirectory property that we used above to bundle plugins.

160
161
162
    <properties>
        <pluginBundleDirectory>target/bundled-plugins</pluginBundleDirectory>
    </properties>

The Webapp Descriptor (web.xml)

Now that our pom is all in order let’s look at the web.xml file.

The top of the web.xml is pretty standard as it defines the web-app tag and our application name.

Lines 11-16 define our list of Spring beans files we want to load. Notice that we’re only including the applicationContextPlugins.xml and not the bootstrap file.
Also note that this is where you can define any other app-specifc spring files to be loaded.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
             version="2.4">
 
        <description>The Atlassian Reference Application</description>
        <display-name>Atlassian RefApp</display-name>
 
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:/applicationContextPlugins.xml
            </param-value>
        </context-param>

Servlet Filters

Lines 19-62 setup some servlet filters. Each filter uses the class RefPlatformServletFilterModuleContainerFilter
This filter is used by the Atlassian® Plugins Framework to build a filter chain from any plugins that include servlet filters.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    <filter>
        <filter-name>filter-plugin-dispatcher-after-encoding</filter-name>
        <filter-class>com.atlassian.refplatform.web.servlet.RefPlatformServletFilterModuleContainerFilter</filter-class>
        <init-param>
            <param-name>location</param-name>
            <param-value>after-encoding</param-value>
        </init-param>
    </filter>
 
    <filter>
        <filter-name>filter-plugin-dispatcher-before-decoration</filter-name>
        <filter-class>com.atlassian.refplatform.web.servlet.RefPlatformServletFilterModuleContainerFilter</filter-class>
        <init-param>
            <param-name>location</param-name>
            <param-value>before-decoration</param-value>
        </init-param>
    </filter>
 
 
    <filter>
        <filter-name>filter-plugin-dispatcher-before-dispatch</filter-name>
        <filter-class>com.atlassian.refplatform.web.servlet.RefPlatformServletFilterModuleContainerFilter</filter-class>
        <init-param>
            <param-name>location</param-name>
            <param-value>before-dispatch</param-value>
        </init-param>
    </filter>
 
 
    <filter-mapping>
        <filter-name>filter-plugin-dispatcher-after-encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
    <filter-mapping>
        <filter-name>filter-plugin-dispatcher-before-decoration</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
 
    <filter-mapping>
        <filter-name>filter-plugin-dispatcher-before-dispatch</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Listeners

Lines 64-73 setup 2 listeners. The first listener is a bootstrap listener which will be used to load the applicationContextBootstrap.xml context and bootstrap the application.
The next listener is a special Spring context loader that will be used to merge our bootstrap context with the rest of the files listed at the top of the web.xml
The second listener is also where we’ll initialize the plugins framework.

64
65
66
67
68
69
70
71
72
73
    <!-- ============ Listeners ============== -->
    <!-- Loads the Bootstrap context for minimal app startup -->
    <listener>
        <listener-class>com.atlassian.refplatform.web.listener.BootstrapLoaderListener</listener-class>
    </listener>
 
    <!-- Loads the Spring servlet context if / when the app has been setup -->
    <listener>
        <listener-class>com.atlassian.refplatform.web.listener.BootstrappedContextLoaderListener</listener-class>
    </listener>

Servlets and Mappings

At the end of our web.xml file we define a single servlet and a mapping for it as well as our welcome list.

The servlet is provided by the Atlassian® Plugins Framework and is used to enable any servlets that other plugins may contribute.
The servlet is mapped to /plugins/servlet/* This will be the base url where all other plugin servlets will be located.

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    <servlet>
        <servlet-name>plugins</servlet-name>
        <servlet-class>com.atlassian.plugin.servlet.ServletModuleContainerServlet</servlet-class>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>plugins</servlet-name>
        <url-pattern>/plugins/servlet/*</url-pattern>
    </servlet-mapping>
 
 
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
 
    </web-app>

Spring Context Files

The base platform requires 2 spring contexts; One for our bootstrapping process, and the other for the Atlassian® Plugins Framework.

applicationContextBootstrap.xml

This file holds all the beans we’ll need during the bootstrapping process of our application. Since all we need to do during bootstrap is ensure the application’s home directory exists, this file is rather small.

It’s also good to note that this file is loaded by the BootstrapLoaderListener servlet listener and not a “normal” context loader listener.

In this file we define 2 beans, the homeLocator, and the bootstrapManager that is wired up with the homeLocator. We’ll get into the specifics of these a bit later.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:plugin="http://atlassian.com/schema/spring/plugin"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://atlassian.com/schema/spring/plugin http://atlassian.com/schema/spring/plugin.xsd">
 
        <bean id="homeLocator" class="com.atlassian.refplatform.core.DefaultHomeLocator" plugin:available="true">
            <property name="propertiesFile" value="refplatform-init.properties"/>
            <property name="initPropertyName" value="refplatform.home"/>
            <property name="configFileName" value="refplatform.cfg.xml"/>
        </bean>
 
 
        <bean id="bootstrapManager" class="com.atlassian.refplatform.web.setup.DefaultBootstrapManager">
            <property name="homeLocator">
                <ref local="homeLocator"/>
            </property>
        </bean>
 
    </beans>
The bootstrap context only contains the required beans to create the home directory.
In a “real” app, you may add more beans to this file to handle things like database setup, etc.

applicationContextPlugins.xml

This file holds all the beans required by the Atlassian® Plugins Framework and gets loaded by our special BootstrappedContextLoaderListener.

Most of the beans listed in this file are provided by the plugins framework and have to do with iniializing the OSGi system. For that reason, I’ll only cover the customized beans in this file.

Lines 11-24 define the pluginManager. This is a very simple extension of the DefaultPluginManager provided by Atlassian® and is the class used to initialize the entire plugin system.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
    <bean id="pluginManager" class="com.atlassian.refplatform.plugins.RefPlatformPluginManager" plugin:available="true">
        <constructor-arg index="0" ref="pluginStateStore"/>
        <constructor-arg index="1">
            <list>
                <ref bean="classpathPluginLoader"/>
                <ref bean="bundledPluginLoader"/>
                <ref bean="directoryPluginLoader"/>
            </list>
        </constructor-arg>
        <constructor-arg index="2" ref="moduleDescriptorFactory"/>
        <constructor-arg index="3" ref="pluginEventManager"/>
        <constructor-arg index="4" ref="hostContainer"/>
        <constructor-arg index="5" ref="pluginDirectoryLocator"/>
    </bean>

Lines 26-28 define the pluginDirectoryLocator. This interface/class provides methods for looking up the various plugin paths that the framework needs. i.e. bundled, plugins, and cache directories.

This is a convenience class that we’ll use in other beans instead of passing a bunch of strings around.

Note the reference to the homeLocator bean we defined in the previous bootstrap context.
26
27
28
    <bean id="pluginDirectoryLocator" class="com.atlassian.refplatform.plugins.DefaultPluginDirectoryLocator">
        <constructor-arg ref="homeLocator"/>
    </bean>

A little futher down on line 83 we define the bundledPluginLoader. This is a factory bean that returns a provided BundledPluginLoader. We have created our own factory here that can make use of our pluginDirectoryLocator.

Note that the last constructor arg is the name of our bundled plugins zip file. If you change the finalName property in the pom (maven-seembly-plugin), you’ll need to update this arg as well.

83
84
85
86
87
88
89
90
91
92
93
94
    <bean id="bundledPluginLoader" class="com.atlassian.refplatform.plugins.loader.BundledPluginLoaderFactory">
        <constructor-arg index="0" ref="pluginDirectoryLocator"/>
        <constructor-arg index="1">
            <list>
                <ref bean="osgiPluginFactory"/>
                <ref bean="osgiBundleFactory"/>
                <ref bean="xmlDynamicPluginFactory"/>
            </list>
        </constructor-arg>
        <constructor-arg index="2" ref="pluginEventManager"/>
        <constructor-arg index="3" value="atlassian-bundled-plugins.zip"/>
    </bean>

Jumping to line 146 we define the servletContextFactory bean. This is just a simple implementation that can be autowired with and return the servletContext.

146
    <bean id="servletContextFactory" class="com.atlassian.refplatform.web.servlet.RefPlatformServletContextFactory" autowire="byType"/>

Line 150 defines the hostContainer This is a class reuiqred by the plugins framework to create and return plugin modules. Our implementation simply pulls them out of the spring context.

150
    <bean id="hostContainer" class="com.atlassian.refplatform.plugins.RefPlatformHostContainer"/>

Finally, lines 154-168 define some string values for use in other beans. All of these strings are created through various spring factory beans.

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    <bean id="applicationKey" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="com.atlassian.refplatform.util.RefPlatformUtils.APPLICATION_KEY"/>
    </bean>
 
    <bean id="pluginDescriptorFilename" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="com.atlassian.refplatform.plugins.DefaultPluginDirectoryLocator.PLUGIN_DESCRIPTOR"/>
    </bean>
 
    <bean id="pluginCacheDirectory" factory-bean="pluginDirectoryLocator" factory-method="getPluginCachesDirectory"/>
 
    <bean id="pluginDirectory" factory-bean="pluginDirectoryLocator" factory-method="getPluginsDirectory"/>
 
    <bean id="characterEncoding" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="com.atlassian.refplatform.util.RefPlatformUtils.DEFAULT_CHARACTER_ENCODING"/>
    </bean>

That wraps up the webapp module. Now on to the core module

The Core Module

refplatform-core-structure

As you can see, the core module contains a lot of files but don’t worry as most of these are simply default implementations/extensions of classes provided by the Atlassian® Plugins Framework.

I’ll save you the excruciatingly boring overview of every file and just jump right to the pom.

This makes the post look a bit uglier, but come on, take the .7 second and scroll dear reader, scroll.


Core POM

Once again, the top of the pom is pretty normal, just inherits the parent pom and sets the project details.

Running ANT inside of Maven? This is a joke, right??

No joke… On lines 16-44 we’re including the maven-ant-run plugin and telling it to run the build-utils.ant file located in our etc folder.

This is going to generate a new java source file in our generated-sources folder called BuildUtils.java

This class will be used by our other classes to grab the version number and build date of our app mainly for logging purposes.

pom.xml

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-version-class</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <ant antfile="src/main/etc/build-utils.ant" inheritAll="false" inheritRefs="false">
                                    <property name="version" value="${project.version}"/>
                                    <property name="src.dir" value="${project.build.directory}/generated-sources"/>
                                </ant>
                            </tasks>
                            <sourceRoot>
                                ${project.build.directory}/generated-sources
                            </sourceRoot>
                        </configuration>
 
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

etc/build-utils.ant

The build-utils.ant file is a very simple script that simply echoes a small java source file to our generated-sources folder which will then be compiled by maven.

The script has a single target named generate-version which is the default target. The script expects the version and path to generated-sources to be passed in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<project basedir=".." default="generate-version">
    <target name="generate-version">
        <tstamp>
            <format property="build.date" pattern="MM/dd/yyyy HH:mm:ss"/>
        </tstamp>
 
        <mkdir dir="${src.dir}/com/atlassian/refplatform/core/util/"/>
        <echo file="${src.dir}/com/atlassian/refplatform/core/util/BuildUtils.java">package com.atlassian.refplatform.core.util;
            /** Automatically generated by ant. */
            public class BuildUtils {
            private static final String VERSION = "${version}";
            private static final String BUILD_DATE = "${build.date}";
 
            public static String getCurrentBuildDate()
            {
            return BUILD_DATE;
            }
 
            public static String getCurrentVersion()
            {
            return VERSION;
            }
 
            }
 
        </echo>
    </target>
</project>

Core Dependencies

The rest of our pom just contains the required dependencies for our core project.

These contain the Spring Framework, the Atlassian-Spring bridge, the Atlassian® Plugins Framework and some base plugins we need.

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    <dependencies>
 
        <dependency>
            <groupId>com.atlassian.spring</groupId>
            <artifactId>atlassian-spring</artifactId>
        </dependency>
 
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-core</artifactId>
        </dependency>
 
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-webfragment</artifactId>
        </dependency>
 
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-webresource</artifactId>
        </dependency>
 
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-servlet</artifactId>
        </dependency>
 
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-osgi</artifactId>
        </dependency>
 
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-spring</artifactId>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
        </dependency>
 
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
    </dependencies>

Onto the code… I’ll start with the BootstrapLoaderListener which is the starting point of our app.

BootstrapLoaderListener

This class runs when our webapp context is initialized. It’s responsible for doing any setup that our app needs to run. In our case it ensures our home directory exists, however this is the class to customize if you need to do database setup or other tasks.

Let’s take a look at the only functional method: contextInitialized:

line 25: Create a Spring context by loading our applicationContextBootstrap.xml file

line 28: Bootstrap the app with the help of our BootstrapUtils class.

30
31
32
33
34
35
36
37
38
39
40
41
    public void contextInitialized(ServletContextEvent event) {
        ApplicationContext bootstrapContext = new ClassPathXmlApplicationContext(new String[]{"applicationContextBootstrap.xml"});
 
        try {
            BootstrapUtils.init(bootstrapContext, event.getServletContext());
        } catch (BootstrapException e) {
            log.error("An error was encountered while bootstrapping atlas-webappkit (see below): n" + e.getMessage(), e);
        }
 
        startupLog.info("Starting Atlassian RefPlatform " + BuildUtils.getCurrentVersion());
 
    }

BootstrapUtils

In the previous code, we delegated the bootstrapping to a BootstrapUtils class.

This is a convenience class to encapsulate the initialization of the bootstrapManager and the homeLocator and provides a place to store/retrieve our bootstrap spring context

Not a very interesting class, but the init method is worth reviewing.

line 27: Get our homeLocator and try to set the home path from the servlet context if available.

line 29: Store the bootstrap spring context so other classes can get to it easily.

lines 30-35:Get the bootstrapManager from the context and initialize it.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    public static void init(ApplicationContext bootstrapContext, ServletContext servletContext) throws BootstrapException
    {
        ((HomeLocator)bootstrapContext.getBean("homeLocator")).lookupServletHomeProperty(servletContext);
 
        setBootstrapContext(bootstrapContext);
        BootstrapManager bootstrapManager = getBootstrapManager();
        if (bootstrapManager == null){
            throw new BootstrapException("Could not initialise boostrap manager");
        }
 
        bootstrapManager.init();
 
        if (!bootstrapManager.isBootstrapped()){
            throw new BootstrapException("Unable to bootstrap application: " + bootstrapManager.getBootstrapFailureReason());
        }
    }

HomeLocator

It’s now time to review the HomeLocator. We have the HomeLocator interface and an implementation called DefaultHomeLocator.

This class is responsible for, as it’s name suggests, locating the application’s home directory. To do this it looks in the following places in the following order:

  1. A System Property named refplatform.home (defined in applicationContextBootstrap.xml)
  2. The refplatform.home property defined in refplatform-init.properties
  3. The refplatform.home property defined as a servletContext init parameter.

Since this class simply returns the value found in one of these places and does not actually create the directory I won’t bother listing it’s contents here.

BootstrapManager

Like the HomeLocator, the BootstrapManager is and interface with a DefaultBootstrapManager implementation.

For our purposes, the BootstrapManager is simply responsible for getting the home path from the HomeLocator and creating the directory if it doesn’t already exist.

We’ve de-coupled all of this functionality so that custom implementations can be easily provided in case more steps are needed in the bootstrap process.

Again, this class is not listed here since it’s fairly straightforward. See the source provided for the full details.

BootstrappedContextLoaderListener

In the context of running the app, at this point the bootstrap is complete and an empty home directory has been created if needed. Now it’s time to init the plugin system and load any app-sepcific Spring contexts

This is the function of the BootstrappedContextLoaderListener which is an extension of the provided ContainerContextLoaderListener.

Our custom implementation provides some extra functionality to merge our bootstrap context with the other provided Spring contexts and initializes the plugin system.

lines 28-42 – canInitialiseContainer: simply ensure we’ve been bootstrapped before loading the contexts

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    @Override
    public boolean canInitialiseContainer() {
        BootstrapManager bootstrapManager = BootstrapUtils.getBootstrapManager();
 
        if (bootstrapManager == null) {
            return false;
        }
 
        if (!bootstrapManager.isBootstrapped()) {
            return false;
        }
 
 
        return true;
    }

lines 44-47 – override the getNewSpringContainerContext method to return a custom BootstrappedContainerContext (listed later)

44
45
46
47
    @Override
    protected SpringContainerContext getNewSpringContainerContext() {
        return new BootstrappedContainerContext();
    }

lines 52-55 – override the createContextLoader method to return a custom BootstrappedContextLoader (listed later)

52
53
54
55
    @Override
    public ContextLoader createContextLoader() {
        return new BootstrappedContextLoader();
    }

lines 57-65 – a little more interesting… Our context is initialized and so we pull our pluginManager bean out of the context and call it’s init method which kicks off the entire plugin framework initialization

58
59
60
61
62
63
64
65
66
    @Override
    protected void postInitialiseContext(ServletContextEvent event) {
        super.postInitialiseContext(event);
 
        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
        RefPlatformPluginManager pluginManager = (RefPlatformPluginManager) ctx.getBean("pluginManager");
 
        pluginManager.init();
    }

BootstrappedContainerContext

This is a simple extension of the provided SpringContainerContext in whic we simply override the refresh method so that we can use our custom BootstrappedContextLoader to reload the application context

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    public synchronized void refresh()
    {
        ContextLoader loader = new BootstrappedContextLoader();
 
        // if we have an existing spring context, ensure we close it properly
        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
 
        if (ctx != null)
        {
            loader.closeWebApplicationContext(getServletContext());
        }
 
        loader.initWebApplicationContext(getServletContext());
 
        if (getApplicationContext() == null)
        {
            setApplicationContext(WebApplicationContextUtils.getWebApplicationContext(getServletContext()));
        }
 
        contextReloaded();
    }

BootstrappedContextLoader

This is a simple extension of the Spring provided ContextLoader class that overrides the loadParentContext and uses our BootstrapUtils class to return our previously loaded bootstrap context. This essentially makes the bootstrap context beans available to all other contexts.

17
18
19
20
21
    @Override
    protected ApplicationContext loadParentContext(ServletContext servletContext) throws BeansException
    {
        return BootstrapUtils.getBootstrapContext();
    }

The other custom classes

During the explanation of the applicationContextPlugins.xml file, I mentioned a few other custom classes that we haven;t covered. Specifically these are:

  • BundledPluginLoaderFactory
  • RefPlatformHostContainer
  • RefPlatformPluginManager

I’m not going to go into detail on these classes since they are simple extensions of Atlassian® provided default classes that just add the ability to make use of our PluginDirectoryLocator.

That being said, it is worth covering the PluginDirectoryLocator itself…

DefaultPluginDirectoryLocator

This class is responsible for determining and creating the bundled plugins, user added plugins, and plugins cache directories.

This class gets the homeLocator injected into it to use as the base path for all of the above mentioned folders.

Although the implementation is very simple, I wanted to list it since this is the place you can customize where plugins get added/stored.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    private static final String BUNDLED_PLUGINS_DIRECTORY = "bundled-plugins";
    private static final String DIRECTORY_PLUGINS_DIRECTORY = "plugins";
    private static final String PLUGIN_CACHES_DIR_NAME = "caches";
    public static final String PLUGIN_DESCRIPTOR = "atlassian-plugin.xml";
 
    private final HomeLocator homeLocator;
 
    public DefaultPluginDirectoryLocator(final HomeLocator homeLocator)
    {
        this.homeLocator = homeLocator;
    }
 
    public File getPluginsDirectory()
    {
        return getHomeSubDirectory(homeLocator, DIRECTORY_PLUGINS_DIRECTORY);
    }
 
    public File getBundledPluginsDirectory()
    {
        return getHomeSubDirectory(homeLocator, BUNDLED_PLUGINS_DIRECTORY);
    }
 
    public File getPluginCachesDirectory()
    {
        return getHomeSubDirectory(homeLocator, PLUGIN_CACHES_DIR_NAME);
    }
 
    public String getPluginDescriptorFilename() {
        return PLUGIN_DESCRIPTOR;
    }
 
    private File getHomeSubDirectory(HomeLocator homeLocator, String subDirectory)
    {
        File homePath = new File(homeLocator.getHomePath());
        File directory = new File(homePath, subDirectory);
 
        if (!directory.exists())
        {
            directory.mkdir();
        }
 
        return directory;
    }

Non-Used Classes

In the source tree there are 2 classes that aren’t currently used.

  • RefPlatformModuleDescriptorFactory
  • AbstractRefPlatformModuleDescrptor

These classes are here in case you want to add “built-in” plugins to your app.

To do so, simply replace the

<bean id="moduleDescriptorFactory" class="com.atlassian.plugin.DefaultModuleDescriptorFactory">

in the applicationContextPlugins.xml file with

<bean id="moduleDescriptorFactory" class="com.atlassian.refplatform.plugins.descriptor.RefPlatformModuleDescriptorFactory">

In the RefPlatformModuleDescriptorFactory you can then add any custom module descriptors you want to provide to your app

    public RefPlatformModuleDescriptorFactory(HostContainer hostContainer) {
        super(hostContainer);
 
        //you can add any custom plugins here:
        // addModuleDescriptor("myCustomPlugin",MyCustomModuleDescriptor.class);
    }

Each module descriptor you add should extend AbstractRefPlatformModuleDescriptor

For a (very) little more on module descriptors, see: http://confluence.atlassian.com/display/PLUGINFRAMEWORK/Quick+Start+Guide+to+Embedding

Building the app

So now that we have all the build and source files, you should be able to easily build and run this with a few short maven steps:

  1. Run the install goal on atlas-webappkit-core
  2. Run the package goal on atlas-webappkit-webapp
  3. Run the cargo:start goal on atlas-webappkit-webapp

After cargo starts up you’ll be able to see the junk jsp at http://localhost:8080/atlas-webappkit/index.jsp

Added bonus… you can access the Felix Web Console at http://localhost:8080/atlas-webappkit/plugins/servlet/system/console/

Topics Not Covered

At this point you now have an app that can bootstrap itself, create a home directory, create the plugin directories, extract any bundled plugins, load the bundled plugins, load user added plugins, and process any Spring files. HOORAY!

There are however a few things not covered by this post that I’m going to leave for other posts or for you to figure out on your own:

  • Assembling a zipped tomcat with the war already exploded and ready to run
  • Enabling the webapp to show a first-time setup wizard
  • Using AMPS to build plugins for your custom app
  • Adding other various Atlassian® plugins (i.e. rest support)

Although the above topics were left out, I hope you’ve found this post helpful.

As always, any comments, suggestions or improvements are very welcomed.

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • StumbleUpon

Testing Atlassian Rest Plugins

With the latest versions of the Atlassian products, you can now add your own rest component plugins.

This is really cool, however, while testing rest plugins is actually pretty easy, figuring out exactly how to do it can drive a person crazy. And so I thought I’d write this post in hopes of saving others hours of research time.

The Project

For this example we’re just going to create a really simple rest resource that returns a list of the projects in JIRA.
I’m not going to walk through plugin development step-by-step but I’ll get us started…

Create a project

Let’s create our project using the Atlassian Plugin SDK.
Just open a terminal and navigate to your base workspace folder. Then run:

atlas-create-jira-plugin

When asked for the plugin name, call it jira-projects-rest

Add some Maven Dependencies

We’ll need a few libraries to help us test, just add the following to the pom dependency list

        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <version>1.0.2</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.3</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
	    <groupId>com.sun.jersey</groupId>
	    <artifactId>jersey-test-framework</artifactId>
	    <version>1.1.2-ea</version>
	    <scope>test</scope>
	</dependency>

Add the rest descriptor

Once the project is created, edit the atlassian-plugin.xml and add our rest component:

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.artifactId}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <application-version min="4.0"/>
        <bundle-instructions>
            <Import-Package>org.apache.commons.collections,*;resolution:=optional</Import-Package>
        </bundle-instructions>
    </plugin-info>
 
    <rest key="projectsService" path="/projectfinder" version="1.0">
        <description>Provides a service that lists JIRA projects</description>
    </rest>
 
    <component key="projectFinder"
        name="Project Finder"
        class="com.sysbliss.jira.plugins.util.ProjectFinder"/>
 
</atlassian-plugin>

The guts

So in the plugin descriptor you’ll notice we have a component named “projectFinder”.
This is a simple helper class that’s not really required, but it helps to decouple our service wrapper and would make sense in a more complex plugin.

The ProjectFinder is responsible for looking up and returning our project list:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.sysbliss.jira.plugins.util;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
 
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
 
public class ProjectFinder {
 
    private final ProjectManager projectManager;
 
    public ProjectFinder(final ProjectManager projectManager) {
	this.projectManager = projectManager;
    }
 
    public List<Project> getProjects() {
	List<Project> projects = projectManager.getProjectObjects();
	if (projects == null) {
	    projects = Collections.<Project> emptyList();
	}
 
	return projects;
 
    }
}

The service wrapper

So now we need a service wrapper. This basically contains 2 classes:

  • ProjectsResource – The class that will be our jersey Resource
  • RestProject – a JAXB class that represents a single project

ProjectsResource.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
package com.sysbliss.jira.plugins.rest;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
 
import com.atlassian.jira.project.Project;
import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
import com.sysbliss.jira.plugins.util.ProjectFinder;
 
@Path("")
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class ProjectsResource {
 
    private final ProjectFinder projectFinder;
 
    public ProjectsResource(final ProjectFinder projectFinder) {
	this.projectFinder = projectFinder;
    }
 
    @GET
    @Path("projects")
    @AnonymousAllowed
    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public Response getProjects() {
 
	final List<Project> projectList = projectFinder.getProjects();
	final List<RestProject> restProjectList = new ArrayList<RestProject>();
	for (final Project project : projectList) {
	    restProjectList.add(new RestProject(project.getName()));
	}
 
	final GenericEntity<List<RestProject>> entities = new GenericEntity<List<RestProject>>(restProjectList) {};
 
	return Response.ok(entities).build();
    }
}

Let’s move on to the RestProject that represents a JIRA project.
For this example, I’m just going to include the name field, but you could add all the other stuff if needed.

RestProject.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
package com.sysbliss.jira.plugins.rest;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
 
import net.jcip.annotations.Immutable;
 
@Immutable
@XmlRootElement
public class RestProject {
 
    @XmlElement
    public final String name;
 
    public RestProject() {
	this.name = "";
    }
 
    public RestProject(final String name) {
	this.name = name;
    }
}

Unit Testing

Although I gave you the implementation code first, this was actually written test-first and I highly advise all others to do the same

At this point if all is well, we have a simple rest service in JIRA that returns a list containing RestProject objects.
The first thing we want to test is our ProjectFinder class. These will be unit tests.

Since we will need to mock out JIRA Project objects, it’s handy to write a little test utility for that.
Note: All the test classes use the Mockito framework for making mocks.

ProjectMockUtils.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
package com.sysbliss.jira.plugins.test.util;
 
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
 
import java.util.Collection;
 
import com.atlassian.jira.project.Project;
 
 
public class ProjectMockUtils {
 
    public static Project createMockProject(final Long id, final String name, final String key) {
	final Project project = mock(Project.class);
 
	when(project.getId()).thenReturn(id);
	when(project.getName()).thenReturn(name);
	when(project.getKey()).thenReturn(key);
 
	return project;
    }
}

And now on to the unit tests. These are pretty simple and shouldn’t require too much explanation…
Note: The unit tests are using the TestNG framework.

ProjectFinderTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
package com.sysbliss.jira.plugins;
 
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
 
import java.util.ArrayList;
import java.util.List;
 
import org.testng.annotations.Test;
 
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.sysbliss.jira.plugins.test.util.ProjectMockUtils;
import com.sysbliss.jira.plugins.util.ProjectFinder;
 
public class ProjectFinderTest {
 
    @Test
    public void projectsAreFound() {
	final List<Project> projects = new ArrayList<Project>();
	projects.add(ProjectMockUtils.createMockProject(1L, "Project 1", "PRJ1"));
	projects.add(ProjectMockUtils.createMockProject(2L, "Project 2", "PRJ2"));
 
	final ProjectManager projectManager = mock(ProjectManager.class);
	when(projectManager.getProjectObjects()).thenReturn(projects);
 
	final ProjectFinder finder = new ProjectFinder(projectManager);
 
	final List<Project> found = finder.getProjects();
 
	assert found.size() == 2 : "Expected 2 projects but got " + found.size();
    }
 
}

So that’s that. I’m keeping it to that one method for this example. In real life, you’d have a bunch of boundry tests, etc, etc.

Next, and equally as exciting, almost the same exact test for the resource wrapper.

ProjectsResourceTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
package com.sysbliss.jira.plugins;
 
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.ws.rs.core.Response;
 
import org.testng.annotations.Test;
 
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.sysbliss.jira.plugins.rest.RestProject;
import com.sysbliss.jira.plugins.rest.ProjectsResource;
import com.sysbliss.jira.plugins.test.util.ProjectMockUtils;
import com.sysbliss.jira.plugins.util.ProjectFinder;
 
public class ProjectsResourceTest {
 
    @Test
    public void resourceProjectsAreFound() {
 
	final List<Project> projects = new ArrayList<Project>();
	projects.add(ProjectMockUtils.createMockProject(1L, "Project 1", "PRJ1"));
	projects.add(ProjectMockUtils.createMockProject(2L, "Project 2", "PRJ2"));
 
	final ProjectManager projectManager = mock(ProjectManager.class);
	when(projectManager.getProjectObjects()).thenReturn(projects);
 
	final ProjectFinder finder = new ProjectFinder(projectManager);
 
	final ProjectsResource resource = new ProjectsResource(finder);
 
	final Response response = resource.getProjects();
 
	final GenericEntity<List<RestProject>> entities = (GenericEntity<List<RestProject>>) response.getEntity();
 
	final List<RestProject> restProjects = entities.getEntity();
 
	assert (restProjects.size() == 2) : "Expected 2 projects but got " + restProjects.size();
    }
 
}

The above test is a little more interesting in the fact that it’s using our jersey resource to test that our resource classes are working properly and that we are getting the correct model objects from the Response class.

So that’s it for the unit tests. Pretty simple and doesn’t require any external connections to anything.
On to the interesting parts….

Integration Testing

The new Atlassian Plugins SDK provides some really cool stuff to help with integration testing and coupled with a few little “tricks” it’s pretty painless.

The Goal

The goal of our integration test harness is to deploy our plugin into a running JIRA instance, provide a known set of data, and actually make http requests to our new resource to verify that everything is working properly.

Before we can get started writing our test, we need to do a little setup.

Creating a dataset

We’re going to need a known set of data in our JIRA instance; namely, 2 empty projects.
The first step in creating the data is to boot up JIRA. Once again, the plugins SDK makes this easy….

Running JIRA

In a terminal, navigate to the project root and run:

atlas-run

If you’ve never run this previously, get some coffee…. maven’s going to do some web surfing for a while.
Once maven has completed, the SDK will boot up JIRA and deploy our plugin. At this point, we don’t really care about our rest resource…. we’re just going to make use of JIRA.

So now just open a browser and point it at: http://localhost:2990/jira

This will bring up JIRA and put you at the dashboard. Login using admin/admin as user/pass.

Create Projects

Finally, go to the JIRA administration section and create 2 projects. It doesn’t matter what they’re called, and they don’t need to have any issues or anything, just be sure there are 2 and only 2 projects created.

After the projects are created, use the backup to xml tool to export the data to an xml file.
The file should be saved as: [project-root]/src/test/xml/it-data.xml

That’s it. Now just CTRL-C in the terminal to shutdown JIRA.

Test Properties

We’re going to be making use of the JiraWebTest class (more on that in a bit) which requires us to make a properties file for integration testing.

Create a file: [project-root]/src/test/resources/localtest.properties
The contents of the file should be:

jira.protocol = http
jira.host = localhost
jira.port = 2990
jira.context = /jira
jira.edition = all
# Please note jira.xml.data.location needs to be the full path
jira.xml.data.location = src/test/xml/
 
jira.release.info = unknown
#
# If the browser path is set then when a test fails the func test framework will try and start
# the browser with a temporary file of captured web output.  if its not set then no harm
# and System.out will be used to dump the web response.
#
browser.path=firefox

Now our integration harness setup is complete and we can finally move on to the interesting stuff.

The Test Suite

Since we’re going to make use of the JiraWebTest, we are forced to use JUnit for the integration tests.
This requires us to create a JUnit Test Suite which is liste below.

Note: ALL integration tests must be in a test package that starts with it.[rest.of.package]

AllTests.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
package it.com.sysbliss.jira.plugins;
 
import junit.framework.Test;
import junit.framework.TestSuite;
 
public class AllTests {
 
    public static Test suite() {
	final TestSuite suite = new TestSuite("Integration Test for it.com.sysbliss.jira.plugins");
 
	suite.addTestSuite(ProjectsRestTest.class);
 
	return suite;
    }
 
}

What’s this JiraWebTest anyway?

JiraWebTest is a class provided by the jira-func-test package that should have been added to your pom.xml by the plugins SDK when you created the project.

It’s a class that your test classes can extend that provides extra functionality when running integration tests.
That extra functionality comes at a price though, like being forced to use JUnit… But wait, that’s not all! You can read an entire post about the pros and cons of the web test framework.

That being said, we are going to make as little use of this class as possible in hope something better comes along, however it does provide something very useful: The ability to load our exported test data.

And so, we’ll put up with it for now.

Finally, the integration test!

So here I’ll just proved the entire class and provide explanations after it.

ProjectsRestTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
package it.com.sysbliss.jira.plugins;
 
import java.io.ByteArrayInputStream;
import java.io.InputStream;
 
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
 
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
 
import com.atlassian.jira.webtests.JIRAWebTest;
import com.sysbliss.jira.plugins.rest.RestProject;
import com.sysbliss.jira.plugins.rest.RestProjects;
 
public class ProjectsRestTest extends JIRAWebTest {
 
    public ProjectsRestTest(final String name) {
	super(name);
    }
 
    @Override
    public void setUp() {
	super.setUp();
	restoreData("it-data.xml");
    }
 
    @Override
    public void tearDown() {
	super.tearDown();
    }
 
    public void testRestProjectsFound() throws Exception {
	final Client client = Client.create();
	final WebResource resource = client.resource("http://localhost:2990/jira/rest/projectversions/1.0/projects.xml");
 
	final List<RestProject> projects = resource.get(new GenericType<List<RestProject>>() {});
	assertEquals(2, projects.size());
    }
}

Extend JiraWebTest

line 18:
we simply extend JiraWebTest to give us our data loading functionality

line 21:
make sure you call super() !

lines 24-28:

  • override the setUp method
  • call super.setUp()
  • call restoreData(“it-data.xml”); – this loads our test data before each test

lines 30-33:
Make sure you override tearDown and call super.tearDown();

lines 36-37:

  • create a jersey Client
  • create a WebResource with our resource url

line 39:
Execute our GET request and cast the response to our model using the GenericType provided by jax-rs

line 40:
We can now use our model objects to assert that our request returned the 2 project objects we have in our test data.

Running the tests

whew, we’re finally ready to actually run the tests… plugins SDK anyone?

Drop out to a terminal in the project root and run:

atlas-integration-test

Sit back and enjoy as you watch the following whiz (well, maybe half-walk/half-jog) by you:

  • Project is compiled and unit tests are run
  • JIRA is started and the plugin is automatically deployed
  • admin logs into JIRA and imports our test data
  • we are welcomed to the Hotel California
  • framework verifys JIRA is ready to run the integration tests
  • The integration tests are run
  • JIRA shuts down

The crowd rejoices

Although this article is a bit verbose, once you set this up, doing it again for other projects is a breeze and the feeling you get seeing the “build successful” at the end never get old.

Hope this was helpful…

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • StumbleUpon