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

0 votes
Answer 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
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

273 views 2 10
Read article

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