Author: ljelinko
Date: 2012-04-19 08:08:40 -0400 (Thu, 19 Apr 2012)
New Revision: 40335
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ServersView.java
Log:
Added methods restart and getServerStatus
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ServersView.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ServersView.java 2012-04-19
11:27:07 UTC (rev 40334)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ServersView.java 2012-04-19
12:08:40 UTC (rev 40335)
@@ -2,6 +2,7 @@
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
@@ -9,6 +10,8 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.jboss.tools.ui.bot.ext.SWTTestExt;
import org.jboss.tools.ui.bot.ext.Timing;
+import org.jboss.tools.ui.bot.ext.condition.NonSystemJobRunsCondition;
+import org.jboss.tools.ui.bot.ext.condition.TaskDuration;
import org.jboss.tools.ui.bot.ext.gen.ActionItem.View.ServerServers;
import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
@@ -30,24 +33,24 @@
SWTBotTreeItem server = findServerByName(tree,serverName);
if (server!=null) {
ContextMenuHelper.prepareTreeItemForContextMenu(tree, server);
- new SWTBotMenu(ContextMenuHelper.getContextMenu(tree,
IDELabel.Menu.ADD_AND_REMOVE, false)).click();
- try {
- SWTBotShell shell = bot.shell(IDELabel.Menu.ADD_AND_REMOVE);
- shell.activate();
- SWTBotButton btRemoveAll=shell.bot().button("<< Remove All");
- if (btRemoveAll.isEnabled()) {
- btRemoveAll.click();
- log.info("Removing all projects from server
'"+serverName+"'");
- }
- open.finish(shell.bot(), IDELabel.Button.FINISH);
- util.waitForNonIgnoredJobs();
- util.waitForAll(Timing.time3S());
- } catch (WidgetNotFoundException ex) {
- ex.printStackTrace();
- bot.shell("Server").activate();
- bot.button(IDELabel.Button.OK).click();
- }
-
+ new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.ADD_AND_REMOVE,
false)).click();
+ try {
+ SWTBotShell shell = bot.shell(IDELabel.Menu.ADD_AND_REMOVE);
+ shell.activate();
+ SWTBotButton btRemoveAll=shell.bot().button("<< Remove All");
+ if (btRemoveAll.isEnabled()) {
+ btRemoveAll.click();
+ log.info("Removing all projects from server
'"+serverName+"'");
+ }
+ open.finish(shell.bot(), IDELabel.Button.FINISH);
+ util.waitForNonIgnoredJobs();
+ util.waitForAll(Timing.time3S());
+ } catch (WidgetNotFoundException ex) {
+ ex.printStackTrace();
+ bot.shell("Server").activate();
+ bot.button(IDELabel.Button.OK).click();
+ }
+
}
}
/**
@@ -60,10 +63,10 @@
SWTBotTreeItem server = findServerByName(tree,serverName);
if (server!=null) {
ContextMenuHelper.prepareTreeItemForContextMenu(tree, server);
- new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.STOP,
false)).click();
- util.waitForNonIgnoredJobs();
- util.waitForAll(Timing.time10S());
-
+ new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.STOP,
false)).click();
+ util.waitForNonIgnoredJobs();
+ util.waitForAll(Timing.time10S());
+
}
}
/**
@@ -76,15 +79,47 @@
SWTBotTreeItem server = findServerByName(tree,serverName);
if (server!=null) {
ContextMenuHelper.prepareTreeItemForContextMenu(tree, server);
- new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.DELETE,
false)).click();
- SWTBotShell shell = bot.shell("Delete Server");
- shell.activate();
- open.finish(shell.bot(), IDELabel.Button.OK);
- log.info("Removed server: " + serverName);
-
+ new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.DELETE,
false)).click();
+ SWTBotShell shell = bot.shell("Delete Server");
+ shell.activate();
+ open.finish(shell.bot(), IDELabel.Button.OK);
+ log.info("Removed server: " + serverName);
+
}
}
+
/**
+ * restarts server with given name
+ * @param serverName
+ */
+ public void restartServer(final String serverName) {
+ SWTBot bot = show().bot();
+ SWTBotTree tree = bot.tree();
+ SWTBotTreeItem server = findServerByName(tree,serverName);
+
+ ContextMenuHelper.prepareTreeItemForContextMenu(tree, server);
+ new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, "Restart",
false)).click();
+
+ bot.waitWhile(new NonSystemJobRunsCondition(), TaskDuration.NORMAL.getTimeout());
+ bot.waitUntil(new ICondition() {
+
+ @Override
+ public boolean test() throws Exception {
+ return "Started".equals(getServerStatus(serverName));
+ }
+
+ @Override
+ public void init(SWTBot bot) {
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "The server does not have status 'Started'";
+ }
+ });
+ }
+
+ /**
* starts application server by given name
* @param serverName
*/
@@ -104,29 +139,29 @@
SWTBotTreeItem server = findServerByName(tree,serverName);
if (server!=null) {
ContextMenuHelper.prepareTreeItemForContextMenu(tree, server);
- new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.START,
false)).click();
- if (username!=null) {
- try {
- SWTBot shell = bot.shell("Enter Password").bot();
- shell.textWithLabel("User ID:").setText(username);
- if (password!=null)
- shell.textWithLabel("Password (optional):").setText(password);
- shell.button(IDELabel.Button.OK).click();
- }
- catch (Exception ex){
- log.error(ex);
- }
- }
- util.waitForNonIgnoredJobs(Timing.time(600 * 1000));
- util.waitForAll(Timing.time3S());
+ new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.START,
false)).click();
+ if (username!=null) {
+ try {
+ SWTBot shell = bot.shell("Enter Password").bot();
+ shell.textWithLabel("User ID:").setText(username);
+ if (password!=null)
+ shell.textWithLabel("Password (optional):").setText(password);
+ shell.button(IDELabel.Button.OK).click();
+ }
+ catch (Exception ex){
+ log.error(ex);
+ }
+ }
+ util.waitForNonIgnoredJobs(Timing.time(600 * 1000));
+ util.waitForAll(Timing.time3S());
}
else{
- throw new RuntimeException("Unable to start server witn name: " +
serverName +
- "\nThis server is not defined within Servers view");
+ throw new RuntimeException("Unable to start server witn name: " + serverName
+
+ "\nThis server is not defined within Servers view");
}
}
public SWTBotTreeItem findServerByName(SWTBotTree tree, String name) {
-
+
for (SWTBotTreeItem i : tree.getAllItems()) {
if (i.getText().startsWith(name)) {
return i;
@@ -134,48 +169,74 @@
}
return null;
}
+
+ public boolean serverExists(String serverName){
+ SWTBot bot = show().bot();
+
+ try {
+ // if there are no servers the following text appears
+ bot.link("No servers available. Define a new server from the <a>new server
wizard</a>...");
+ return false;
+ } catch (WidgetNotFoundException e){
+ // ok, there are some servers, let's check the name
+ }
+
+ SWTBotTreeItem server = findServerByName(bot.tree(), serverName);
+ return server != null;
+ }
+
+ public String getServerStatus(String serverName){
+ SWTBot bot = show().bot();
+ SWTBotTreeItem server = findServerByName(bot.tree(), serverName);
+
+ String label = server.getText();
+ int startIndex = label.indexOf('[') + 1;
+ int endIndex = label.indexOf(',');
+ return label.substring(startIndex, endIndex);
+ }
+
/**
* removes project with given name from all servers
* @param projectName
*/
public void removeProjectFromServers(String projectName){
-
- SWTBotTree serverTree = show().bot().tree();
- // Expand All
- for (SWTBotTreeItem serverTreeItem : serverTree.getAllItems()){
- serverTreeItem.expand();
- // if JSF Test Project is deployed to server remove it
- SWTBotTreeItem[] serverTreeItemChildren = serverTreeItem.getItems();
- if (serverTreeItemChildren != null && serverTreeItemChildren.length >
0){
- int itemIndex = 0;
- boolean found = false;
- do{
- String treeItemlabel = serverTreeItemChildren[itemIndex].getText();
- found = treeItemlabel.startsWith(projectName);
- } while (!found && ++itemIndex < serverTreeItemChildren.length);
- // Server Tree Item has Child with Text equal to JSF TEst Project
- if (found){
- log.info("Found project to be removed from server: " +
serverTreeItemChildren[itemIndex].getText());
-
ContextMenuHelper.prepareTreeItemForContextMenu(serverTree,serverTreeItemChildren[itemIndex]);
- new SWTBotMenu(ContextMenuHelper.getContextMenu(serverTree,
IDELabel.Menu.REMOVE, false)).click();
- SWTBotShell shell = bot.shell("Server");
- shell.activate();
- open.finish(shell.bot(), IDELabel.Button.OK);
- log.info("Removed project from server: " +
serverTreeItemChildren[itemIndex].getText());
- util.waitForNonIgnoredJobs();
- } else {
- log.info("Project '"+projectName+"' not found on any
server");
- }
- }
- }
- }
+
+ SWTBotTree serverTree = show().bot().tree();
+ // Expand All
+ for (SWTBotTreeItem serverTreeItem : serverTree.getAllItems()){
+ serverTreeItem.expand();
+ // if JSF Test Project is deployed to server remove it
+ SWTBotTreeItem[] serverTreeItemChildren = serverTreeItem.getItems();
+ if (serverTreeItemChildren != null && serverTreeItemChildren.length > 0){
+ int itemIndex = 0;
+ boolean found = false;
+ do{
+ String treeItemlabel = serverTreeItemChildren[itemIndex].getText();
+ found = treeItemlabel.startsWith(projectName);
+ } while (!found && ++itemIndex < serverTreeItemChildren.length);
+ // Server Tree Item has Child with Text equal to JSF TEst Project
+ if (found){
+ log.info("Found project to be removed from server: " +
serverTreeItemChildren[itemIndex].getText());
+ ContextMenuHelper.prepareTreeItemForContextMenu(serverTree,serverTreeItemChildren[itemIndex]);
+ new SWTBotMenu(ContextMenuHelper.getContextMenu(serverTree, IDELabel.Menu.REMOVE,
false)).click();
+ SWTBotShell shell = bot.shell("Server");
+ shell.activate();
+ open.finish(shell.bot(), IDELabel.Button.OK);
+ log.info("Removed project from server: " +
serverTreeItemChildren[itemIndex].getText());
+ util.waitForNonIgnoredJobs();
+ } else {
+ log.info("Project '"+projectName+"' not found on any
server");
+ }
+ }
+ }
+ }
/**
* removes projects from pre-configured server
* @param projectName
*/
public void removeAllProjectsFromServer() {
removeAllProjectsFromServer(SWTTestExt.configuredState.getServer().name);
-
+
}
}