1 package com.atlassian.webdriver.confluence.page;
2
3
4 import com.atlassian.pageobjects.binder.WaitUntil;
5 import com.atlassian.webdriver.utils.by.ByJquery;
6 import com.google.common.collect.ImmutableSet;
7 import org.openqa.selenium.By;
8 import org.openqa.selenium.WebElement;
9
10 import java.util.HashMap;
11 import java.util.HashSet;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15
16
17
18
19
20 public class PluginsPage extends ConfluenceAbstractPage
21 {
22 private static final String PLUGIN_KEY = "pluginKey=";
23 private static final String URI = "/admin/viewplugins.action";
24 private final Map<String, WebElement> loadedPlugins;
25 private String activePluginKey;
26 private final Set<String> pluginsWithErrors;
27 private final Set<String> disabledPlugins;
28
29 public PluginsPage()
30 {
31 loadedPlugins = new HashMap<String, WebElement>();
32 pluginsWithErrors = new HashSet<String>();
33 disabledPlugins = new HashSet<String>();
34 }
35
36 public String getUrl()
37 {
38 return URI;
39 }
40
41 public PluginsPage selectPlugin(String pluginKey)
42 {
43 if (pluginIsLoaded(pluginKey))
44 {
45 loadedPlugins.get(pluginKey).click();
46 return pageBinder.bind(PluginsPage.class);
47 }
48
49 return null;
50 }
51
52 public boolean pluginIsLoaded(String pluginKey)
53 {
54 return loadedPlugins.containsKey(pluginKey);
55 }
56
57 public boolean pluginIsDisabled(String pluginKey)
58 {
59 return disabledPlugins.contains(pluginKey);
60 }
61
62 public boolean pluginHasErrors(String pluginKey)
63 {
64 return pluginsWithErrors.contains(pluginKey);
65 }
66
67 public Set<String> getPluginsWithLoadingErrors()
68 {
69 return ImmutableSet.copyOf(pluginsWithErrors);
70 }
71
72 public Set<String> getDisabledPlugins()
73 {
74 return ImmutableSet.copyOf(disabledPlugins);
75 }
76
77 public String getActivePluginKey()
78 {
79 return activePluginKey;
80 }
81
82 @WaitUntil
83 public void waitForLoadedPlugins()
84 {
85
86 WebElement table = driver.findElement(ByJquery.$("td.pagebody table table > tbody"));
87
88 List<WebElement> pluginAnchors = table.findElements(ByJquery.$("tr td a[href^=viewplugins]"));
89 List<WebElement> pluginAnchorsWithErrors = table.findElements(ByJquery.$("tr td:contains(Errors loading plugin) a"));
90 List<WebElement> disabledPluginAnchors = table.findElements(ByJquery.$("tr td:contains(Plugin disabled) a"));
91
92 WebElement activePluginAnchor = table.findElement(ByJquery.$("tr td > strong > a"));
93 String activePluginUrl = activePluginAnchor.getAttribute("href");
94 int activePluginKeyIndex = activePluginUrl.indexOf(PLUGIN_KEY);
95 this.activePluginKey = activePluginUrl.substring(activePluginKeyIndex + PLUGIN_KEY.length());
96
97 for (WebElement pluginAnchor : pluginAnchors)
98 {
99 String pluginUrl = pluginAnchor.getAttribute("href");
100 int pluginKeyIndex = pluginUrl.indexOf(PLUGIN_KEY);
101 String pluginKey = pluginUrl.substring(pluginKeyIndex + PLUGIN_KEY.length());
102
103 loadedPlugins.put(pluginKey, pluginAnchor);
104 }
105
106 for (WebElement pluginAnchor : pluginAnchorsWithErrors)
107 {
108 String pluginUrl = pluginAnchor.getAttribute("href");
109 int pluginKeyIndex = pluginUrl.indexOf(PLUGIN_KEY);
110 String pluginKey = pluginUrl.substring(pluginKeyIndex + PLUGIN_KEY.length());
111
112 pluginsWithErrors.add(pluginKey);
113 }
114
115 for (WebElement pluginAnchor : disabledPluginAnchors)
116 {
117 String pluginUrl = pluginAnchor.getAttribute("href");
118 int pluginKeyIndex = pluginUrl.indexOf(PLUGIN_KEY);
119 String pluginKey = pluginUrl.substring(pluginKeyIndex + PLUGIN_KEY.length());
120
121 disabledPlugins.add(pluginKey);
122 }
123
124 }
125
126 }