Dependent Confluence plugins integration testing

We have several dependent confluence plugins. We need to test it works the same despite deploy ordering of these plugins. Have any ideas how to deal with it?

Now, I'm trying to use UPM REST API to enable/disable plugins from test code in runtime. But I also have a troble with getting components of these plugins(from OSGi container) for test at runtime. I mean something like


in runtime

1 answer

1 accepted

0 votes
Accepted answer

So, to make plugins available from test you need to use


To enable/disable plugin, you need to know it's key (from atlassian-plugin.xml) and I used next:
static final Pattern PLUGIN_ENABLED_PATTERN = Pattern.compile("\"enabled\":(true|false)");
    final static String USER_AGENT_HEADER = "Mozilla/5.0";
    final static String UPM_DEPLOY_LINK = "/rest/plugins/1.0/{0}-key?os_authType=basic&os_username={1}&os_password={2}";
    final static String PLUGIN_KEY_PREFIX = "com.confluence.plugin.";

    final static String USER = "admin";
    final static String PASSWORD = "admin";

    public TestUtils(ApplicationProperties applicationProperties) {
        this.applicationProperties = applicationProperties;

    private String getResponce(URL url) throws Exception {
        BufferedReader in = null;
        HttpURLConnection con = null;
        StringBuilder response = new StringBuilder();
        try {
            con = (HttpURLConnection) url.openConnection();
            con.setRequestProperty("User-Agent", USER_AGENT_HEADER);
            con.setRequestProperty("Content-Type", "application/json");
            int responseCode = con.getResponseCode();
            in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
        } finally {
            if (in != null) in.close();
            if (con != null) con.disconnect();
        return response.toString();

    void setPluginEnabled(String key, boolean enabled) throws Exception {
        URL url = new URL(applicationProperties.getBaseUrl() + MessageFormat.format(UPM_DEPLOY_LINK, PLUGIN_KEY_PREFIX + key, USER, PASSWORD));
        StringBuilder response = new StringBuilder(getResponce(url));
        HttpURLConnection con = null;
        BufferedWriter out = null;
        Matcher m = PLUGIN_ENABLED_PATTERN.matcher(response);
        if (m.find()) {
            try {
                response.replace(m.start(1), m.end(1), String.valueOf(enabled));
                con = (HttpURLConnection) url.openConnection();
                con.setRequestProperty("User-Agent", USER_AGENT_HEADER);
                con.setRequestProperty("Content-Type", "application/vnd.atl.plugins.plugin+json");
                out = new BufferedWriter(new OutputStreamWriter(con.getOutputStream()));
                int responseCode = con.getResponseCode();
            } finally {
                if (out != null) out.close();
                if (con != null) con.disconnect();
//            getPluginEnabled(key);
        } else {
            throw new Exception("Plugin status not found");


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,526 views 25 14
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you