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

<component-import>

in runtime

1 answer

1 accepted

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

<plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-confluence-plugin</artifactId>
                <version>${amps.version}</version>
                <configuration>
                    <pluginArtifacts>
                        <pluginArtifact>
                            <groupId>...</groupId>
                            <artifactId>..</artifactId>
                            <version>..</version>
                        </pluginArtifact>
                    </pluginArtifacts>
                </configuration>
        </plugin>

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.setRequestMethod("GET");
            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) {
                response.append(inputLine);
            }
        } 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.setDoOutput(true);
                con.setRequestMethod("PUT");
                con.setRequestProperty("User-Agent", USER_AGENT_HEADER);
                con.setRequestProperty("Content-Type", "application/vnd.atl.plugins.plugin+json");
                out = new BufferedWriter(new OutputStreamWriter(con.getOutputStream()));
                out.write(response.toString());
                out.flush();
                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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,941 views 27 12
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