Dependent Confluence plugins integration testing
Asked by Dmitry_Zharikhin:

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

```
&lt;component-import&gt;
```

in runtime


Answers:
author: Dmitry_Zharikhin
body: So, to make plugins available from test you need to use

```
&lt;plugin&gt;                &lt;groupId&gt;com.atlassian.maven.plugins&lt;/groupId&gt;                &lt;artifactId&gt;maven-confluence-plugin&lt;/artifactId&gt;                &lt;version&gt;${amps.version}&lt;/version&gt;                &lt;configuration&gt;                    &lt;pluginArtifacts&gt;                        &lt;pluginArtifact&gt;                            &lt;groupId&gt;...&lt;/groupId&gt;                            &lt;artifactId&gt;..&lt;/artifactId&gt;                            &lt;version&gt;..&lt;/version&gt;                        &lt;/pluginArtifact&gt;                    &lt;/pluginArtifacts&gt;                &lt;/configuration&gt;        &lt;/plugin&gt;
```

```

```

```
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&amp;os_username={1}&amp;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");        }    }
```

```

```

```

```


Tags: dependency

integration