Author: vpakan(a)redhat.com
Date: 2010-04-16 11:33:11 -0400 (Fri, 16 Apr 2010)
New Revision: 21540
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ConsoleView.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProblemsView.java
Modified:
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/ManageDroolsProject.java
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/ManageDroolsRuntime.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java
Log:
Added Drools Tests related to Managing Drools Project
Modified:
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java
===================================================================
---
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java 2010-04-16
15:25:51 UTC (rev 21539)
+++
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -10,11 +10,14 @@
******************************************************************************/
package org.jboss.tools.drools.ui.bot.test;
+import java.io.File;
+
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.jboss.tools.drools.ui.bot.test.smoke.ManageDroolsRuntime;
import org.jboss.tools.drools.ui.bot.test.smoke.ManageDroolsProject;
import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.SWTUtilExt;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -36,9 +39,34 @@
public static final String DROOLS_PROJECT_NAME = "droolsTest";
public static final String DROOLS_RUNTIME_NAME = "Drools Test Runtime";
public static String DROOLS_RUNTIME_LOCATION = null;
+ public static String CREATE_DROOLS_RUNTIME_LOCATION = null;
+ public static String SRC_MAIN_JAVA_TREE_NODE = "src/main/java";
+ public static String COM_SAMPLE_TREE_NODE = "com.sample";
+ public static String DROOLS_TEST_JAVA_TREE_NODE = "DroolsTest.java";
+ private static String testDroolsRuntimeName = null;
+ public static String getTestDroolsRuntimeName() {
+ return testDroolsRuntimeName;
+ }
+
+ public static void setTestDroolsRuntimeName(String testDroolsRuntimeName) {
+ DroolsAllBotTests.testDroolsRuntimeName = testDroolsRuntimeName;
+ }
+
+ public static String getTestDroolsRuntimeLocation() {
+ return testDroolsRuntimeLocation;
+ }
+
+ public static void setTestDroolsRuntimeLocation(String testDroolsRuntimeLocation) {
+ DroolsAllBotTests.testDroolsRuntimeLocation = testDroolsRuntimeLocation;
+ }
+
+ private static String testDroolsRuntimeLocation = null;
@BeforeClass
public static void setUpTest() {
- DROOLS_RUNTIME_LOCATION = System.getProperty("java.io.tmpdir");
+ DroolsAllBotTests.DROOLS_RUNTIME_LOCATION =
System.getProperty("java.io.tmpdir");
+ DroolsAllBotTests.CREATE_DROOLS_RUNTIME_LOCATION =
DroolsAllBotTests.DROOLS_RUNTIME_LOCATION + File.separator + "drools";
+ // Create directory for Drools Runtime which will be created as a part of test
+ new File(DroolsAllBotTests.CREATE_DROOLS_RUNTIME_LOCATION).mkdir();
properties = util.loadProperties(Activator.PLUGIN_ID);
try{
SWTBotView welcomeView = eclipse.getBot().viewByTitle(IDELabel.View.WELCOME);
@@ -51,7 +79,7 @@
@AfterClass
public static void tearDownTest() {
- // Ready for later usage
- }
-
+ // delete created drools runtime
+ SWTUtilExt.deleteDirectory(DroolsAllBotTests.CREATE_DROOLS_RUNTIME_LOCATION);
+ }
}
\ No newline at end of file
Modified:
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/ManageDroolsProject.java
===================================================================
---
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/ManageDroolsProject.java 2010-04-16
15:25:51 UTC (rev 21539)
+++
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/ManageDroolsProject.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -11,18 +11,19 @@
package org.jboss.tools.drools.ui.bot.test.smoke;
+import java.io.File;
+
import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
import org.jboss.tools.ui.bot.ext.types.EntityType;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
-import org.jboss.tools.ui.bot.ext.types.JobName;
import org.jboss.tools.ui.bot.ext.types.ViewType;
-import org.jboss.tools.ui.bot.test.WidgetVariables;
+import org.jboss.tools.ui.bot.ext.view.ProblemsView;
import org.jboss.tools.drools.ui.bot.test.DroolsAllBotTests;
import org.junit.Test;
-import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
/**
* Test managing of Drools Project
* @author Vladimir Pakan
@@ -35,8 +36,12 @@
@Test
public void testManageDroolsProject() {
createDroolsProject (DroolsAllBotTests.DROOLS_PROJECT_NAME);
+ runNewDroolsProject (DroolsAllBotTests.DROOLS_PROJECT_NAME);
}
-
+ /**
+ * Creates new Drools project
+ * @param droolsProjectName
+ */
private void createDroolsProject(String droolsProjectName){
eclipse.showView(ViewType.PACKAGE_EXPLORER);
eclipse.createNew(EntityType.DROOLS_PROJECT);
@@ -60,19 +65,48 @@
}
bot.button(IDELabel.Button.NEXT).click();
bot.button(IDELabel.Button.FINISH).click();
- SWTTestExt.util.waitForAllExcept(100*1000L, new
String[]{JobName.USAGE_DATA_EVENT_CONSUMER});
- SWTBot innerBot = bot.viewByTitle(WidgetVariables.PACKAGE_EXPLORER).bot();
- SWTBotTree tree = innerBot.tree();
- boolean isOk = false;
- try {
- tree.getTreeItem(droolsProjectName);
- isOk = true;
- } catch (WidgetNotFoundException e) {
- }
+ SWTTestExt.util.waitForAll(20*1000L);
+ jbt.delay();
+
assertTrue("Project "
+ droolsProjectName
- + " was not created properly.",isOk);
+ + " was not created
properly.",SWTEclipseExt.isProjectInPackageExplorer(bot,droolsProjectName));
+ String projectPath = File.separator + droolsProjectName;
+ SWTBotTreeItem[] errors = ProblemsView.getFilteredErrorsTreeItems(bot,null
,projectPath, null,null);
+ assertTrue("Project "
+ + droolsProjectName
+ + " was not created properly. There are these errors: "
+ + SWTEclipseExt.getFormattedTreeNodesText(bot.tree(), errors),
+ errors == null || errors.length == 0);
+ SWTBotTreeItem[] warnings = ProblemsView.getFilteredWarningsTreeItems(bot,null
,projectPath, null,null);
+ assertTrue("Project "
+ + droolsProjectName
+ + " was not created properly. There are these warnings: "
+ + SWTEclipseExt.getFormattedTreeNodesText(bot.tree(), warnings),
+ warnings == null || warnings.length == 0);
+
}
-
+ /**
+ * Runs newly created Drools project and check result
+ * @param droolsProjectName
+ */
+ private void runNewDroolsProject(String droolsProjectName){
+ console.clearConsole();
+ bot.sleep(5000L);
+
+ SWTBotTreeItem tiTestFile =
packageExplorer.selectTreeItem(DroolsAllBotTests.DROOLS_TEST_JAVA_TREE_NODE,
+ new String[] {DroolsAllBotTests.DROOLS_PROJECT_NAME,
+ DroolsAllBotTests.SRC_MAIN_JAVA_TREE_NODE,
+ DroolsAllBotTests.COM_SAMPLE_TREE_NODE});
+
+ eclipse.runTreeItemAsJavaApplication(tiTestFile);
+
+ String consoleText = console.getConsoleText(3*1000L,60*1000L,true);
+
+ assertTrue("DroolsTest.java class didn't run properly.\n" +
+ "Console Text was: " + consoleText + "\n" +
+ "Expected console text is: " + "Hello World\nGoodbye cruel
world\n",
+ "Hello World\nGoodbye cruel world\n".equals(consoleText));
+ }
}
Modified:
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/ManageDroolsRuntime.java
===================================================================
---
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/ManageDroolsRuntime.java 2010-04-16
15:25:51 UTC (rev 21539)
+++
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/ManageDroolsRuntime.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -11,6 +11,10 @@
package org.jboss.tools.drools.ui.bot.test.smoke;
+import static org.jboss.tools.ui.bot.ext.SWTTestExt.bot;
+import static org.jboss.tools.ui.bot.ext.SWTTestExt.console;
+import static org.jboss.tools.ui.bot.ext.SWTTestExt.eclipse;
+
import java.io.File;
import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
@@ -30,17 +34,17 @@
*
*/
public class ManageDroolsRuntime extends SWTTestExt{
- private String testDroolsRuntimeName = null;
- private String testDroolsRuntimeLocation = null;
/**
* Test manage Drools Runtime
*/
@Test
public void testManageDroolsRuntime() {
addDroolsRuntime(DroolsAllBotTests.DROOLS_RUNTIME_NAME,DroolsAllBotTests.DROOLS_RUNTIME_LOCATION);
- editDroolsRuntime(testDroolsRuntimeName,testDroolsRuntimeLocation, "edited"
, "testedit");
- removeDroolsRuntime(testDroolsRuntimeName);
-
createDroolsRuntime(DroolsAllBotTests.DROOLS_RUNTIME_NAME,DroolsAllBotTests.DROOLS_RUNTIME_LOCATION);
+ editDroolsRuntime(DroolsAllBotTests.getTestDroolsRuntimeName(),
+ DroolsAllBotTests.getTestDroolsRuntimeLocation(),
+ "edited" , "testedit");
+ removeDroolsRuntime(DroolsAllBotTests.getTestDroolsRuntimeName());
+
createDroolsRuntime(DroolsAllBotTests.DROOLS_RUNTIME_NAME,DroolsAllBotTests.CREATE_DROOLS_RUNTIME_LOCATION);
}
/**
* Adds Drools Runtime
@@ -63,13 +67,14 @@
assertTrue("Drools Runtime with name [" + runtimeName +
"] and location [" + runtimeLocation +
"] was not added properly.",droolsRuntimeAdded);
- testDroolsRuntimeName = runtimeName;
- testDroolsRuntimeLocation = runtimeLocation;
+ DroolsAllBotTests.setTestDroolsRuntimeName(runtimeName);
+ DroolsAllBotTests.setTestDroolsRuntimeLocation(runtimeLocation);
}
/**
* Selects Drools Preferences within Preferences Dialog
*/
private void selectDroolsPreferences(){
+ jbt.delay();
bot.menu(IDELabel.Menu.WINDOW).menu(IDELabel.Menu.PREFERENCES).click();
bot.shell(IDELabel.Shell.PREFERENCES).activate();
SWTBotTreeItem tiDroolsGroup =
bot.tree().expandNode(IDELabel.PreferencesDialog.DROOLS_GROUP);
@@ -104,8 +109,8 @@
assertTrue("Drools Runtime with name [" + runtimeName +
"] and location [" + runtimeLocation +
"] was not renamed properly.",droolsRuntimeEdited);
- testDroolsRuntimeName = editedDroolsRuntimeName;
- testDroolsRuntimeLocation = editedDroolsRuntimeLocation;
+ DroolsAllBotTests.setTestDroolsRuntimeName(editedDroolsRuntimeName);
+ DroolsAllBotTests.setTestDroolsRuntimeLocation(editedDroolsRuntimeLocation);
}
/**
@@ -124,14 +129,14 @@
assertTrue("Drools Runtime with name [" + runtimeName +
"] was not removed properly.",droolsRuntimeRemoved);
// Remove temporary directory created within editDroolsRuntime() method
- if (!testDroolsRuntimeLocation.equals(DroolsAllBotTests.DROOLS_RUNTIME_NAME)){
- File tempDir = new File (testDroolsRuntimeLocation);
+ if
(!DroolsAllBotTests.getTestDroolsRuntimeLocation().equals(DroolsAllBotTests.DROOLS_RUNTIME_NAME)){
+ File tempDir = new File (DroolsAllBotTests.getTestDroolsRuntimeLocation());
if (tempDir.isDirectory()){
tempDir.delete();
}
}
- testDroolsRuntimeName = null;
- testDroolsRuntimeLocation = null;
+ DroolsAllBotTests.setTestDroolsRuntimeName(null);
+ DroolsAllBotTests.setTestDroolsRuntimeLocation(null);
}
/**
* Creates Drools Runtime
@@ -139,29 +144,27 @@
* @param runtimeLocation
*/
private void createDroolsRuntime(String runtimeName, String runtimeLocation){
- String newDroolsRuntimeLocation = runtimeLocation + File.separator +
"drools";
- new File(newDroolsRuntimeLocation).mkdir();
- DroolsRuntimeManager.createDefaultRuntime(newDroolsRuntimeLocation);
+ DroolsRuntimeManager.createDefaultRuntime(runtimeLocation);
DroolsRuntime droolsRuntime = new DroolsRuntime();
droolsRuntime.setName(runtimeName);
- droolsRuntime.setPath(newDroolsRuntimeLocation);
+ droolsRuntime.setPath(runtimeLocation);
droolsRuntime.setDefault(true);
DroolsRuntimeManager.setDroolsRuntimes(new DroolsRuntime[]{droolsRuntime});
// Test if Drools runtime is defined
- assertTrue("Drools Runtime was not properly created on location: " +
newDroolsRuntimeLocation,
- new File (newDroolsRuntimeLocation + File.separator +
"drools-api.jar").exists());
+ assertTrue("Drools Runtime was not properly created on location: " +
runtimeLocation,
+ new File (runtimeLocation + File.separator +
"drools-api.jar").exists());
selectDroolsPreferences();
SWTBotTable table = bot.table();
boolean droolsRuntimeCreated =
SWTEclipseExt.isItemInTableColumn(table,runtimeName,IDELabel.DroolsRuntimeDialog.COLUMN_NAME_INDEX)
- &&
SWTEclipseExt.isItemInTableColumn(table,newDroolsRuntimeLocation,IDELabel.DroolsRuntimeDialog.COLUMN_LOCATION_INDEX);
+ &&
SWTEclipseExt.isItemInTableColumn(table,runtimeLocation,IDELabel.DroolsRuntimeDialog.COLUMN_LOCATION_INDEX);
bot.button(IDELabel.Button.OK).click();
SWTEclipseExt.hideWarningIfDisplayed(bot);
assertTrue("Drools Runtime with name [" + runtimeName +
- "] and location [" + newDroolsRuntimeLocation +
+ "] and location [" + runtimeLocation +
"] was not created properly.",droolsRuntimeCreated);
- testDroolsRuntimeName = runtimeName;
- testDroolsRuntimeLocation = newDroolsRuntimeLocation;
+ DroolsAllBotTests.setTestDroolsRuntimeName(runtimeName);
+ DroolsAllBotTests.setTestDroolsRuntimeLocation(runtimeLocation);
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java 2010-04-16
15:25:51 UTC (rev 21539)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -16,6 +16,8 @@
import java.io.File;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Properties;
import org.apache.log4j.Logger;
@@ -47,7 +49,6 @@
import org.jboss.tools.ui.bot.ext.types.PerspectiveType;
import org.jboss.tools.ui.bot.ext.types.ViewType;
import org.jboss.tools.ui.bot.ext.types.IDELabel.PreferencesDialog;
-import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;
/**
* Provides Eclipse common operation based on SWTBot element operations
@@ -61,13 +62,18 @@
private SWTUtilExt util;
private SWTBotExt bot;
// private SWTUtilExt swtUtilExt;
- private Logger log = Logger.getLogger(SWTEclipseExt.class);
+ private static Logger log = Logger.getLogger(SWTEclipseExt.class);
+ public static final long DEFAULT_UI_TIMEOUT = 1000L;
+ public enum StringConditionType {
+ EQUALS, CONTAINS, STARTS_WITH;
+ }
+
public SWTWorkbenchBot getBot() {
return bot;
}
- public Logger getLog() {
+ public static Logger getLog() {
return log;
}
@@ -239,24 +245,7 @@
* @param path
*/
public SWTBotEditor openFile(String projectName, String... path) {
- SWTBot viewBot = bot.viewByTitle(IDELabel.View.PACKAGE_EXPLORER).bot();
- bot.viewByTitle(IDELabel.View.PACKAGE_EXPLORER).show();
- bot.viewByTitle(IDELabel.View.PACKAGE_EXPLORER).setFocus();
- SWTBotTree tree = viewBot.tree();
- SWTBotTreeItem item = tree.expandNode(projectName);
- StringBuilder builder = new StringBuilder(projectName);
-
- // Go through path
- for (String nodeName : path) {
- item = item.expandNode(nodeName);
- builder.append("/" + nodeName);
- }
-
- item.select().doubleClick();
- log.info("File Opened:" + builder.toString());
-
- SWTBotEditor editor = bot.activeEditor();
- return editor;
+ return SWTEclipseExt.openFile(bot, projectName, path);
}
// ------------------------------------------------------------
@@ -276,7 +265,7 @@
*
* @return
*/
- public SWTBotTreeItem selectTreeLocation(SWTBot bot, String... path) {
+ public static SWTBotTreeItem selectTreeLocation(SWTBot bot, String... path) {
SWTBot viewBot = bot;
@@ -347,7 +336,7 @@
public void waitForClosedShell(SWTBotShell shell) {
while (shell.isActive()) {
- bot.sleep(200);
+ bot.sleep(SWTEclipseExt.DEFAULT_UI_TIMEOUT);
log.info("Waiting for closing shell...");
}
}
@@ -743,7 +732,6 @@
SWTEclipseExt.getMenuFromSubmenu(
bot.menu(IDELabel.Menu.RUN).menu(IDELabel.Menu.RUN_AS),
IDELabel.Menu.RUN_AS_JAVA_APPLICATION).click();
- System.out.println("stop");
}
/**
@@ -777,4 +765,139 @@
});
return new SWTBotMenu(menuItem);
}
+ /**
+ * Opens file from Package Explorer static version
+ * @param bot
+ * @param path
+ * @return SWTBotEditor
+ */
+ public static SWTBotEditor openFile(SWTBotExt bot, String projectName, String... path)
{
+ SWTBot viewBot = bot.viewByTitle(IDELabel.View.PACKAGE_EXPLORER).bot();
+ bot.viewByTitle(IDELabel.View.PACKAGE_EXPLORER).show();
+ bot.viewByTitle(IDELabel.View.PACKAGE_EXPLORER).setFocus();
+ SWTBotTree tree = viewBot.tree();
+ SWTBotTreeItem item = tree.expandNode(projectName);
+ StringBuilder builder = new StringBuilder(projectName);
+
+ // Go through path
+ for (String nodeName : path) {
+ item = item.expandNode(nodeName);
+ builder.append("/" + nodeName);
+ }
+
+ item.select().doubleClick();
+ log.info("File Opened:" + builder.toString());
+
+ SWTBotEditor editor = bot.activeEditor();
+ return editor;
+ }
+
+ /**
+ * Collapse all expanded tree items
+ * @param tree
+ */
+ public static void collapseAll (SWTBotTree tree,SWTBotExt bot){
+ for (SWTBotTreeItem treeItem : tree.getAllItems()){
+ if (treeItem.isExpanded()){
+ treeItem.collapse();
+ }
+ }
+ bot.sleep(SWTEclipseExt.DEFAULT_UI_TIMEOUT);
+ }
+ /**
+ * Returns all tree items which are children of parent tree item
+ * @param bot
+ * @param tree
+ * @param parent
+ * @param expand
+ * @return
+ */
+ public static List<SWTBotTreeItem> getAllTreeItemsRecursive (SWTBotExt bot,
SWTBotTree tree , SWTBotTreeItem parent, boolean expand){
+
+ LinkedList<SWTBotTreeItem> treeItems = new LinkedList<SWTBotTreeItem>();
+
+ if (parent != null){
+ if (expand) {
+ parent.expand();
+ bot.sleep(SWTEclipseExt.DEFAULT_UI_TIMEOUT);
+ }
+
+ SWTBotTreeItem[] nodeChildren = parent.getItems();
+ if (nodeChildren != null){
+ for (SWTBotTreeItem child : nodeChildren){
+ if (child.getText().length() > 0){
+ treeItems.add(child);
+
treeItems.addAll(SWTEclipseExt.getAllTreeItemsRecursive(bot,tree,child,expand));
+ }
+ }
+ }
+ }
+ else{
+ treeItems =
(LinkedList<SWTBotTreeItem>)SWTEclipseExt.getAllTreeItemsRecursive(bot, tree,
expand);
+ }
+
+ return treeItems;
+ }
+ /**
+ * Returns all tree items recursive
+ * @param bot
+ * @param tree
+ * @param expand
+ * @return
+ */
+ public static List<SWTBotTreeItem> getAllTreeItemsRecursive (SWTBotExt bot,
SWTBotTree tree, boolean expand){
+
+ LinkedList<SWTBotTreeItem> treeItems = new LinkedList<SWTBotTreeItem>();
+
+ SWTBotTreeItem[] nodeChildren = tree.getAllItems();
+ if (nodeChildren != null){
+ for (SWTBotTreeItem child : nodeChildren){
+ if (child.getText().length() > 0){
+ treeItems.add(child);
+
treeItems.addAll(SWTEclipseExt.getAllTreeItemsRecursive(bot,tree,child,expand));
+ }
+ }
+ }
+
+ return treeItems;
+ }
+
+ public static String getFormattedTreeNodeText (SWTBotTree tree, SWTBotTreeItem item){
+ StringBuilder stringBuilder = new StringBuilder("");
+
+ if (item != null){
+ for (int column = 0 ; column < tree.columnCount(); column++){
+ if (column > 0){
+ stringBuilder.append(" - ");
+ }
+ String columnText = item.cell(column);
+ if (columnText == null){
+ columnText = "<null>";
+ } else if (columnText == null){
+ columnText = "<empty>";
+ }
+ stringBuilder.append(columnText);
+ }
+ }
+
+ return stringBuilder.toString();
+
+ }
+
+ public static String getFormattedTreeNodesText (SWTBotTree tree, SWTBotTreeItem[]
items){
+ StringBuilder stringBuilder = new StringBuilder("");
+
+ if (items != null){
+ for (SWTBotTreeItem item : items){
+ if (stringBuilder.length() > 0){
+ stringBuilder.append("\n");
+ }
+ stringBuilder.append(SWTEclipseExt.getFormattedTreeNodeText(tree,item));
+ }
+ }
+
+ return stringBuilder.toString();
+
+ }
+
}
\ No newline at end of file
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java 2010-04-16
15:25:51 UTC (rev 21539)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -14,7 +14,9 @@
import org.apache.log4j.Logger;
import org.eclipse.swtbot.swt.finder.SWTBotTestCase;
+import org.jboss.tools.ui.bot.ext.view.ConsoleView;
import org.jboss.tools.ui.bot.ext.view.PackageExplorer;
+import org.jboss.tools.ui.bot.ext.view.ProblemsView;
import org.jboss.tools.ui.bot.ext.view.ProjectExplorer;
import org.jboss.tools.ui.bot.ext.view.ServersView;
/**
@@ -34,7 +36,9 @@
// Views
public static final PackageExplorer packageExplorer = new PackageExplorer();
public static final ProjectExplorer projectExplorer = new ProjectExplorer();
- public static final ServersView servers = new ServersView();
+ public static final ServersView servers = new ServersView();
+ public static final ProblemsView problems = new ProblemsView();
+ public static final ConsoleView console = new ConsoleView();
public static Properties properties;
/**
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java 2010-04-16
15:25:51 UTC (rev 21539)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -157,6 +157,7 @@
public static final String DATA_SOURCE_EXPLORER = "Data Source Explorer";
public static final String SERVERS = "Servers";
public static final String WEB_PROJECTS = "Web Projects";
+ public static final String PROBLEMS = "Problems";
}
public class ViewGroup {
@@ -341,4 +342,17 @@
public static final String NAME = "Project name:";
}
-}
+
+ public static class ProblemsTree {
+
+ public static final String WARNINGS = "Warnings";
+ public static final String ERRORS = "Errors";
+
+ }
+
+ public static class ConsoleView {
+
+ public static final String BUTTON_CLEAR_CONSOLE_TOOLTIP = "Clear
Console";
+
+ }
+ }
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java 2010-04-16
15:25:51 UTC (rev 21539)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -18,7 +18,7 @@
*
*/
public enum ViewType {
- PACKAGE_EXPLORER, PROJECT_EXPLORER, WELCOME, DATA_SOURCE_EXPLORER,SERVERS,WEB_PROJECTS;
+ PACKAGE_EXPLORER, PROJECT_EXPLORER, WELCOME,
DATA_SOURCE_EXPLORER,SERVERS,WEB_PROJECTS,PROBLEMS;
public String getGroupLabel() {
@@ -29,6 +29,7 @@
case DATA_SOURCE_EXPLORER: viewLabel = IDELabel.ViewGroup.DATA_MANAGEMENT; break;
case SERVERS: viewLabel = IDELabel.ViewGroup.SERVER; break;
case WEB_PROJECTS: viewLabel = IDELabel.ViewGroup.JBOSS_TOOLS_WEB; break;
+ case PROBLEMS: viewLabel = IDELabel.ViewGroup.GENERAL; break;
default: fail("Unknown View Type");
}
return viewLabel;
@@ -42,6 +43,7 @@
case DATA_SOURCE_EXPLORER: viewLabel = IDELabel.View.DATA_SOURCE_EXPLORER; break;
case SERVERS: viewLabel = IDELabel.View.SERVERS; break;
case WEB_PROJECTS: viewLabel = IDELabel.View.WEB_PROJECTS; break;
+ case PROBLEMS: viewLabel = IDELabel.View.PROBLEMS; break;
default: fail("Unknown View Type");
}
return viewLabel;
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ConsoleView.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ConsoleView.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ConsoleView.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -0,0 +1,103 @@
+ /*******************************************************************************
+ * Copyright (c) 2007-2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ui.bot.ext.view;
+
+import org.jboss.tools.ui.bot.ext.gen.ActionItem.View.GeneralConsole;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.SWTOpenExt;
+import org.jboss.tools.ui.bot.ext.gen.IView;
+import org.jboss.tools.ui.bot.ext.types.IDELabel;
+/**
+ * Manage Console View related tasks
+ * @author Vlado Pakan
+ *
+ */
+public class ConsoleView extends SWTBotExt {
+ protected IView viewObject;
+ protected final SWTOpenExt open;
+ public static final int PROBLEMS_DESCRIPTION_COLUMN_INDEX = 0;
+ public static final int PROBLEMS_RESOURCE_COLUMN_INDEX = 1;
+ public static final int PROBLEMS_PATH_COLUMN_INDEX = 2;
+ public static final int PROBLEMS_TYPE_COLUMN_INDEX = 4;
+ Logger log = Logger.getLogger(ConsoleView.class);
+ public ConsoleView() {
+ viewObject = GeneralConsole.LABEL;
+ open = new SWTOpenExt(this);
+ }
+
+ /**
+ * shows Explorer view
+ */
+ public void show() {
+ open.viewOpen(viewObject);
+ }
+ /**
+ * Returns actual console text
+ * @return
+ */
+ public String getConsoleText(){
+
+ show();
+ SWTBot viewBot = viewByTitle(viewObject.getName()).bot();
+ String consoleText = null;
+ try{
+ consoleText = viewBot.styledText().getText();
+ }catch (WidgetNotFoundException wnfe){
+ consoleText = null;
+ }
+
+ return consoleText;
+
+ }
+ /**
+ * Clears console content
+ */
+ public void clearConsole(){
+
+ show();
+ SWTBot viewBot = viewByTitle(viewObject.getName()).bot();
+ try{
+ SWTBotButton clearConsole =
viewBot.buttonWithTooltip(IDELabel.ConsoleView.BUTTON_CLEAR_CONSOLE_TOOLTIP).click();
+ clearConsole.click();
+ }catch (WidgetNotFoundException wnfe){
+ // Do nothing Clear Console button is not available
+ }
+ }
+
+ public String getConsoleText (long sleepTime , long timeOut , boolean
quitWhenNoChange){
+
+ long estimatedTime = 0;
+ SWTBot viewBot = viewByTitle(viewObject.getName()).bot();
+ String prevConsoleText = getConsoleText();
+ String consoleText = prevConsoleText;
+ log.info("Waiting for console text with TimeOut: " + timeOut);
+ while ((estimatedTime <= timeOut)
+ && (!quitWhenNoChange
+ || prevConsoleText == null
+ || prevConsoleText.length() == 0
+ || !prevConsoleText.equals(consoleText))){
+ prevConsoleText = consoleText;
+ viewBot.sleep(sleepTime);
+ estimatedTime += sleepTime;
+ consoleText = getConsoleText();
+ }
+ log.info("Waiting for console text finished");
+
+ return consoleText;
+
+ }
+
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ConsoleView.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java 2010-04-16
15:25:51 UTC (rev 21539)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -57,6 +57,7 @@
* @return
*/
public SWTBotTreeItem selectTreeItem(String treeItemText, String[] path) {
+ show();
return
SWTEclipseExt.getTreeItemOnPath(viewByTitle(viewObject.getName()).bot().tree(),
treeItemText, path)
.select();
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProblemsView.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProblemsView.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProblemsView.java 2010-04-16
15:33:11 UTC (rev 21540)
@@ -0,0 +1,218 @@
+ /*******************************************************************************
+ * Copyright (c) 2007-2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ui.bot.ext.view;
+
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt.StringConditionType;
+import org.jboss.tools.ui.bot.ext.gen.ActionItem.View.GeneralProblems;
+
+import java.util.LinkedList;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
+import org.jboss.tools.ui.bot.ext.SWTOpenExt;
+import org.jboss.tools.ui.bot.ext.gen.IView;
+import org.jboss.tools.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.ui.bot.ext.types.ViewType;
+/**
+ * Manage Problems View related tasks
+ * @author Vlado Pakan
+ *
+ */
+public class ProblemsView extends SWTBotExt {
+ protected IView viewObject;
+ protected final SWTOpenExt open;
+ public static final int PROBLEMS_DESCRIPTION_COLUMN_INDEX = 0;
+ public static final int PROBLEMS_RESOURCE_COLUMN_INDEX = 1;
+ public static final int PROBLEMS_PATH_COLUMN_INDEX = 2;
+ public static final int PROBLEMS_TYPE_COLUMN_INDEX = 4;
+ Logger log = Logger.getLogger(ProblemsView.class);
+ public ProblemsView() {
+ viewObject = GeneralProblems.LABEL;
+ open = new SWTOpenExt(this);
+ }
+
+ /**
+ * shows Explorer view
+ */
+ public void show() {
+ open.viewOpen(viewObject);
+ }
+ /**
+ * Returns all warnings nodes filtered by input parameters
+ * @param bot
+ * @param descriptionContains
+ * @param pathStartsWith
+ * @param resourceText
+ * @param typeText
+ * @return
+ */
+ public static SWTBotTreeItem[] getFilteredWarningsTreeItems(SWTBotExt bot, String
descriptionContains, String pathStartsWith,
+ String resourceText,String typeText){
+
+ SWTBotTreeItem[] warningsTreeItems = null;
+ SWTBotTreeItem warningsNode = ProblemsView.getWarningsNode(bot);
+ SWTBotTree tree = bot.tree();
+ if (warningsNode != null){
+ warningsNode.expand();
+ bot.sleep(SWTEclipseExt.DEFAULT_UI_TIMEOUT);
+ warningsTreeItems =
ProblemsView.getProblemsTreeItemsContainingText(bot,tree,warningsNode,
+ descriptionContains, pathStartsWith, resourceText, typeText,
+ false);
+ }
+
+ return warningsTreeItems;
+ }
+
+ /**
+ * Returns all errors nodes filtered by input parameters
+ * @param bot
+ * @param descriptionContains
+ * @param pathStartsWith
+ * @param resourceText
+ * @param typeText
+ * @return
+ */
+ public static SWTBotTreeItem[] getFilteredErrorsTreeItems(SWTBotExt bot, String
descriptionContains, String pathStartsWith,
+ String resourceText,String typeText){
+
+ SWTBotTreeItem[] errorsTreeItems = null;
+ SWTBotTreeItem errorsNode = ProblemsView.getErrorsNode(bot);
+ SWTBotTree tree = bot.tree();
+ if (errorsNode != null){
+ errorsNode.expand();
+ bot.sleep(SWTEclipseExt.DEFAULT_UI_TIMEOUT);
+ errorsTreeItems =
ProblemsView.getProblemsTreeItemsContainingText(bot,tree,errorsNode,
+ descriptionContains, pathStartsWith, resourceText, typeText,
+ false);
+ }
+
+ return errorsTreeItems;
+
+ }
+
+ /**
+ * Returns Errors Node from Problems View static version
+ * @param bot
+ * @return
+ */
+ public static SWTBotTreeItem getErrorsNode (SWTBotExt bot){
+ SWTBotTreeItem errorsNode = null;
+ SWTBot problemsBot = SWTEclipseExt.showView(bot,ViewType.PROBLEMS);
+ try{
+ SWTBotTreeItem[] filteredTreeItems =
ProblemsView.getProblemsTreeItemsContainingText(bot,problemsBot.tree(),null,
+ IDELabel.ProblemsTree.ERRORS,"","","",
+ false);
+ if (filteredTreeItems != null && filteredTreeItems.length > 0){
+ errorsNode = filteredTreeItems[0];
+ }
+ } catch (WidgetNotFoundException wnfe){
+ // do nothing
+ }
+ return errorsNode;
+ }
+ /**
+ * Returns Warnings Node from Problems View static version
+ * @param bot
+ * @return
+ */
+ public static SWTBotTreeItem getWarningsNode (SWTBotExt bot){
+ SWTBotTreeItem warningsNode = null;
+ SWTBot problemsBot = SWTEclipseExt.showView(bot,ViewType.PROBLEMS);
+ try{
+ SWTBotTreeItem[] filteredTreeItems =
ProblemsView.getProblemsTreeItemsContainingText(bot,problemsBot.tree(),null,
+ IDELabel.ProblemsTree.WARNINGS,"","","",
+ false);
+ if (filteredTreeItems != null && filteredTreeItems.length > 0){
+ warningsNode = filteredTreeItems[0];
+ }
+ } catch (WidgetNotFoundException wnfe){
+ // do nothing
+ }
+ return warningsNode;
+ }
+ /**
+ * Returns Tree Items from specified tree with specified attributes
+ * When attribute is null then is ignored
+ * @param bot
+ * @param tree
+ * @param parent - when null go thorough all tree items
+ * @param descriptionContains
+ * @param pathStartsWith
+ * @param resourceText
+ * @param typeText
+ * @param expand
+ * @return
+ */
+ public static SWTBotTreeItem[] getProblemsTreeItemsContainingText (SWTBotExt
bot,SWTBotTree tree, SWTBotTreeItem parent,
+ String descriptionContains, String pathStartsWith,
+ String resourceText,String typeText,
+ boolean expand){
+
+ LinkedList<SWTBotTreeItem> treeItems = new LinkedList<SWTBotTreeItem>();
+ for (SWTBotTreeItem treeItem : SWTEclipseExt.getAllTreeItemsRecursive(bot, tree,
parent, expand)){
+ if (ProblemsView.testProblemsTreeItemForStringCondition(treeItem,
descriptionContains,
+ ProblemsView.PROBLEMS_DESCRIPTION_COLUMN_INDEX,
StringConditionType.CONTAINS)
+ && ProblemsView.testProblemsTreeItemForStringCondition(treeItem,
pathStartsWith,
+ ProblemsView.PROBLEMS_PATH_COLUMN_INDEX, StringConditionType.STARTS_WITH)
+ && ProblemsView.testProblemsTreeItemForStringCondition(treeItem,
resourceText,
+ ProblemsView.PROBLEMS_RESOURCE_COLUMN_INDEX, StringConditionType.EQUALS)
+ && ProblemsView.testProblemsTreeItemForStringCondition(treeItem,
typeText,
+ ProblemsView.PROBLEMS_TYPE_COLUMN_INDEX, StringConditionType.EQUALS)){
+ treeItems.add(treeItem);
+ }
+ }
+
+ return treeItems.toArray(new SWTBotTreeItem[treeItems.size()]);
+
+ }
+ /**
+ * Tests Tree Item for condition dependent on specified parameters
+ * @param treeItem
+ * @param testString - when null returns true
+ * @param column - tested column index
+ * @param conditionType
+ * @return
+ */
+ public static boolean testProblemsTreeItemForStringCondition (SWTBotTreeItem treeItem,
+ String testString, int column, StringConditionType conditionType){
+
+ boolean isOK = false;
+
+ if (testString != null){
+ String itemString = treeItem.cell(column);
+ if (itemString != null){
+ if (conditionType.equals(StringConditionType.STARTS_WITH)){
+ isOK = itemString.startsWith(testString);
+ }else if (conditionType.equals(StringConditionType.EQUALS)){
+ isOK = itemString.equals(testString);
+ }else if (conditionType.equals(StringConditionType.CONTAINS)){
+ isOK = itemString.indexOf(testString) > -1;
+ }
+
+ }
+ else{
+ isOK = false;
+ }
+ }
+ else{
+ isOK = true;
+ }
+
+ return isOK;
+
+ }
+
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProblemsView.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain