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
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"); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.