Author: jpeterka
Date: 2010-01-25 05:46:56 -0500 (Mon, 25 Jan 2010)
New Revision: 19902
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTDebugExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ObjectMultiPageEditorBot.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java
Modified:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/META-INF/MANIFEST.MF
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/ConfigurationFileTest.java
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/ConsoleTest.java
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/MappingFileTest.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/META-INF/MANIFEST.MF
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.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/helper/ContextMenuHelper.java
Log:
SWTBotExt Updates:
Support for Object Multipage Tab Editor added
Support for Code Assist added
Hibernate Tests updates:
Configuration File edit TC
Console Test TC
Mapping File Tests edit TC
Modified:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/META-INF/MANIFEST.MF 2010-01-25
09:13:54 UTC (rev 19901)
+++
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/META-INF/MANIFEST.MF 2010-01-25
10:46:56 UTC (rev 19902)
@@ -8,6 +8,8 @@
org.eclipse.core.runtime,
org.junit4,
org.apache.log4j;bundle-version="1.2.13",
+ org.jboss.tools.ui.bot.ext;bundle-version="1.0.0",
+ org.eclipse.jdt.ui,
org.eclipse.swtbot.eclipse.core;bundle-version="2.0.0",
org.eclipse.swtbot.eclipse.finder;bundle-version="2.0.0",
org.eclipse.swtbot.eclipse.spy;bundle-version="2.0.0",
@@ -16,10 +18,16 @@
org.eclipse.swtbot.swt.finder;bundle-version="2.0.0",
org.jboss.tools.ui.bot.ext;bundle-version="1.0.0",
org.eclipse.jdt.ui,
+ org.jboss.tools.jst.ui.bot.test;bundle-version="1.0.0",
+ org.jboss.tools.hibernate.ui;bundle-version="3.3.0",
+ org.jboss.tools.hibernate.xml.ui;bundle-version="3.1.0",
+ org.jboss.tools.common.model.ui;bundle-version="3.1.0",
+ org.eclipse.ui.ide;bundle-version="3.5.1",
+ org.jboss.tools.common.ui;bundle-version="3.1.0",
org.eclipse.datatools.connectivity;bundle-version="1.1.2"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Eclipse-RegisterBuddy: org.apache.log4j
Import-Package: org.eclipse.jdt.internal.ui
-Bundle-ClassPath: lib/hsqldb.jar,
- .
+Export-Package: org.jboss.tools.hibernate.ui.bot.testsuite
+Bundle-ClassPath: lib/hsqldb.jar,.
Modified:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/ConfigurationFileTest.java
===================================================================
---
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/ConfigurationFileTest.java 2010-01-25
09:13:54 UTC (rev 19901)
+++
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/ConfigurationFileTest.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -10,20 +10,36 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.bot.testcase;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathExpressionException;
+
import org.eclipse.swt.widgets.Button;
import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.hamcrest.Matcher;
import org.jboss.tools.hibernate.ui.bot.testsuite.HibernateTest;
import org.jboss.tools.hibernate.ui.bot.testsuite.Project;
+import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
+import org.jboss.tools.ui.bot.ext.parts.ObjectMultiPageEditorBot;
import org.jboss.tools.ui.bot.ext.types.EntityType;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.xml.sax.SAXException;
@RunWith(SWTBotJunit4ClassRunner.class)
public class ConfigurationFileTest extends HibernateTest {
@@ -69,10 +85,99 @@
/**
* TC 13
+ * @throws ParserConfigurationException
+ * @throws IOException
+ * @throws SAXException
+ * @throws XPathExpressionException
*/
@Test
- public void editFile() {
- // TODO
+ /*
+ * Edit Configuration file testcase. It checks: 1. Configuration file editor tabs
availability,...
+ */
+ public void editFile() throws ParserConfigurationException, SAXException, IOException,
XPathExpressionException {
+
+ eclipse.openFile(Project.PROJECT_NAME, "src", Project.CONF_FILE_NAME2);
+ SWTBotEditor editor = bot.editorByTitle(Project.CONF_FILE_NAME2);
+ ObjectMultiPageEditorBot multiBot = new
ObjectMultiPageEditorBot(Project.CONF_FILE_NAME2);
+
+ // 1. Tabs availability
+ String[] pages = {"Session
Factory","Security","Source"};
+ for ( String page : pages ) {
+ multiBot.selectPage(page);
+ bot.sleep(TIME_500MS);
+ }
+
+ // 2. Test creating elements and properties
+ // TODO creating element impl.
+
+ // 3. Create new security element
+ SWTBot localBot = editor.bot();
+ multiBot.selectPage(pages[1]);
+ SWTBotTree secTree = localBot.tree().select("Security");
+
+ ContextMenuHelper.clickContextMenu(secTree, "New", "Grant...");
+
+ // Fillin Role, Entity-Name and Check action All *
+ String roleName = "role1";
+ String entityName = "entity1";
+
+ bot.textWithLabel("Role*").setText("role1");
+ bot.textWithLabel("Entity-Name*").setText("entity1");
+ SWTBotShell shell = bot.shell("Add Grant");
+
+ assertNotNull(shell);
+ SWTBot shellBot = new SWTBot(shell.widget);
+
+ SWTBotTree tree = shellBot.tree();
+ SWTBotTreeItem[] items = tree.getAllItems();
+ items[0].check();
+
+ shellBot.button(IDELabel.Button.FINISH).click();
+
+ // Click on Source tab for check
+ multiBot.selectPage(pages[2]);
+ List<String> lines = editor.toTextEditor().getLines();
+
+ // XMLPath
+ /*
+ // Convert editor text into InputStreamReader
+ StringBuilder builder = new StringBuilder();
+ for (String line : lines ) {
+ builder.append(line);
+ builder.append("\n");
+ }
+ ByteArrayInputStream bs = new ByteArrayInputStream(builder.toString().getBytes());
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db;
+ db = dbf.newDocumentBuilder();
+ Document doc = db.parse(bs);
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ XPathExpression expr = xpath.compile("/person/security/grant");
+ Object result = expr.evaluate(doc, XPathConstants.NODESET);
+ NodeList nodes = (NodeList) result;
+ for ( int i = 0; i < nodes.getLength(); i++ )
+ System.out.println(nodes.item(i).getNodeValue());
+
+ */
+ // Search for security grant
+
+ boolean found = false;
+ String wanted = "<grant actions=\"*\" entity-name=\"" +
entityName + "\" role=\"" + roleName + "\"/>";
+ System.out.println("Looking for:" + wanted);
+
+ for (String line : lines) {
+ System.out.println(line);
+ if (line.trim().equals(wanted)) {
+ found = true;
+ System.out.println("Found");
+ }
+ }
+
+ editor.saveAndClose();
+ assertTrue("Security element not found in xml", found);
+ bot.sleep(TIME_10S);
}
}
Modified:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/ConsoleTest.java
===================================================================
---
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/ConsoleTest.java 2010-01-25
09:13:54 UTC (rev 19901)
+++
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/ConsoleTest.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -136,7 +136,7 @@
*/
@Test
public void editConsole() {
- // TODO
+ // TODO impl.
}
}
Modified:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/MappingFileTest.java
===================================================================
---
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/MappingFileTest.java 2010-01-25
09:13:54 UTC (rev 19901)
+++
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/src/org/jboss/tools/hibernate/ui/bot/testcase/MappingFileTest.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -10,11 +10,15 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.bot.testcase;
+import java.util.List;
+
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.jboss.tools.hibernate.ui.bot.testsuite.HibernateTest;
import org.jboss.tools.hibernate.ui.bot.testsuite.Project;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
+import org.jboss.tools.ui.bot.ext.parts.ObjectMultiPageEditorBot;
import org.jboss.tools.ui.bot.ext.types.EntityType;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.junit.AfterClass;
@@ -101,5 +105,35 @@
*/
@Test
public void editFile() {
+ // Open Hibernate Mapping File (ObjectMultiPageEditor on source tab)
+ eclipse.openFile(Project.PROJECT_NAME,"src",Project.PACKAGE_NAME,Project.CLASS1
+ ".hbm.xml");
+ ObjectMultiPageEditorBot pageBot = new ObjectMultiPageEditorBot(Project.CLASS1 +
".hbm.xml");
+ pageBot.selectPage("Source");
+
+ // Check code completion
+ SWTBotEditorExt editor = bot.editorByTitle(Project.CLASS1 + ".hbm.xml");
+
+ String search = "</id>";
+ List<String> lines = editor.getLines();
+
+ int index = 0;
+ for (String line : lines ) {
+ index++;
+ if (line.trim().equals(search)) break;
+ }
+
+ log.info("Line index: " + index);
+
+ // Insert tag for cc check
+ String newLine = "<property name=\"\"> ";
+ int col = newLine.indexOf("\"\"");
+ editor.selectRange(index, 0, 0);
+ editor.insertText("\n");
+ editor.insertText(newLine);
+ editor.selectRange(index, col + 1, 0);
+
+ // TODO autocomplete proposal check
+
+ editor.save();
}
}
Modified: trunk/jst/tests/org.jboss.tools.ui.bot.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/tests/org.jboss.tools.ui.bot.ext/META-INF/MANIFEST.MF 2010-01-25 09:13:54
UTC (rev 19901)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/META-INF/MANIFEST.MF 2010-01-25 10:46:56
UTC (rev 19902)
@@ -16,14 +16,19 @@
org.junit4;bundle-version="4.5.0",
org.apache.log4j;bundle-version="1.2.13",
org.eclipse.datatools.connectivity;bundle-version="1.1.2",
- org.eclipse.datatools.connectivity.db.generic;bundle-version="1.0.1"
+ org.eclipse.datatools.connectivity.db.generic;bundle-version="1.0.1",
+ org.jboss.tools.common.text.ext;bundle-version="3.1.0",
+ org.eclipse.ui.ide;bundle-version="3.5.1",
+ org.jboss.tools.common.model;bundle-version="3.1.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Eclipse-RegisterBuddy: org.apache.log4j
Export-Package: org.jboss.tools.ui.bot.ext,
org.jboss.tools.ui.bot.ext.entity,
org.jboss.tools.ui.bot.ext.helper,
+ org.jboss.tools.ui.bot.ext.parts,
org.jboss.tools.ui.bot.ext.types,
org.jboss.tools.ui.bot.ext.view
Bundle-Vendor: JBoss by Red Hat
-
+Import-Package: org.eclipse.ui.texteditor,
+ org.jboss.tools.common.editor
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java 2010-01-25
09:13:54 UTC (rev 19901)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -14,11 +14,13 @@
import org.apache.log4j.Logger;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
/**
* Extended version of SWTWorkbenchBot, logging added
@@ -68,5 +70,10 @@
log.info("Table selected");
return super.table();
}
+ @Override
+ public SWTBotEditorExt editorByTitle(String fileName) {
+ SWTBotEditor editor = super.editorByTitle(fileName);
+ return new SWTBotEditorExt(editor.toTextEditor().getReference(),
(SWTWorkbenchBot)this);
+ }
}
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTDebugExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTDebugExt.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTDebugExt.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -0,0 +1,35 @@
+package org.jboss.tools.ui.bot.ext;
+
+import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swtbot.swt.finder.results.Result;
+import org.eclipse.ui.IWorkbenchWindow;
+
+public class SWTDebugExt {
+
+ SWTBotExt bot = new SWTBotExt();
+ Logger log = Logger.getLogger(SWTDebugExt.class);
+
+ /**
+ * Print SWT data in hierarchy
+ */
+ public void swtInfo(Composite composite) {
+ final Composite c = composite;
+ syncExec(new Result<IWorkbenchWindow>() {
+
+ public IWorkbenchWindow run() {
+ printRecursive(c);
+ return null;
+ }
+ });
+ }
+
+ private void printRecursive(Composite composite) {
+ if (composite.getData() != null) {
+
+ composite.toString();
+ }
+ }
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTDebugExt.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-01-25
09:13:54 UTC (rev 19901)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -41,6 +41,7 @@
}
// Wait Constants
+ public static int TIME_500MS = 500;
public static int TIME_1S = 1000;
public static int TIME_5S = 5000;
public static int TIME_10S = 10000;
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ContextMenuHelper.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ContextMenuHelper.java 2010-01-25
09:13:54 UTC (rev 19901)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ContextMenuHelper.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -15,6 +15,8 @@
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
+import java.util.Arrays;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
@@ -166,4 +168,70 @@
}
}
+
+ /**
+ * Clicks the context menu matching the text.
+ *
+ * @param text
+ * the text on the context menu.
+ * @throws WidgetNotFoundException
+ * if the widget is not found.
+ */
+ public static void clickContextMenu(final AbstractSWTBot<?> bot,
+ final String... texts) {
+
+ // show
+ final MenuItem menuItem = UIThreadRunnable
+ .syncExec(new WidgetResult<MenuItem>() {
+ @SuppressWarnings("unchecked")
+ public MenuItem run() {
+ MenuItem menuItem = null;
+ Control control = (Control) bot.widget;
+ Menu menu = control.getMenu();
+ for (String text : texts) {
+ Matcher<?> matcher = allOf(instanceOf(MenuItem.class),
+ withMnemonic(text));
+ menuItem = show(menu, matcher,false);
+ if (menuItem != null) {
+ menu = menuItem.getMenu();
+ } else {
+ hide(menu);
+ break;
+ }
+ }
+
+ return menuItem;
+ }
+ });
+ if (menuItem == null) {
+ throw new WidgetNotFoundException("Could not find menu: "
+ + Arrays.asList(texts));
+ }
+
+ // click
+ click(menuItem);
+
+ // hide
+ UIThreadRunnable.syncExec(new VoidResult() {
+ public void run() {
+ hide(menuItem.getParent());
+ }
+ });
+ }
+
+ private static void click(final MenuItem menuItem) {
+ final Event event = new Event();
+ event.time = (int) System.currentTimeMillis();
+ event.widget = menuItem;
+ event.display = menuItem.getDisplay();
+ event.type = SWT.Selection;
+
+ UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() {
+ public void run() {
+ menuItem.notifyListeners(SWT.Selection, event);
+ }
+ });
+ }
+
+
}
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -0,0 +1,192 @@
+private package org.jboss.tools.ui.bot.ext.parts;
+
+import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * This provides working Content assist functionality.
+ * SWTBot (2.0.0#467) funcionality provided in SWTEclipseEditor doesn't work (at
least on GTK linux)
+ * @author jpeterka
+ *
+ */
+public class ContentAssistBot {
+ /**
+ * Performs content assist for given editor and string
+ *
+ * @param editor
+ * @param text
+ */
+
+ Logger log = Logger.getLogger(ContentAssistBot.class);
+ SWTBotEditorExt editor;
+ SWTBot bot;
+
+ // ------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------
+ /**
+ * Basic constructor
+ */
+ public ContentAssistBot(SWTBotEditorExt editor) {
+ this.editor = editor;
+ this.bot = editor.bot();
+ }
+
+ // ------------------------------------------------------------
+ // Public
+ // ------------------------------------------------------------
+ /**
+ * Use selected content proposal with given proposal text
+ */
+ public void useProposal(String text) {
+ SWTBotTable table = getProposalTable(openProposalList());
+ List<String> items = getTableItems(table);
+ if (items.contains(text)) {
+ final int index = items.indexOf(text);
+ seletctCCTableItem(table, index);
+ } else {
+ fail("ContentAssist doens't contain proposed text");
+ }
+ }
+ /**
+ * Use selected content proposal with given proposal index
+ */
+ public void useProposal(int index) {
+ SWTBotTable table = getProposalTable(openProposalList());
+ seletctCCTableItem(table, index);
+ }
+
+ /**
+ * Logs proposal list contents, usual for debug purposes
+ *
+ * @param text
+ */
+ public void logProposalList() {
+ SWTBotShell shell = openProposalList();
+ SWTBotTable table = getProposalTable(shell);
+ List<String> list = getTableItems(table);
+ log.info("Proposal item list: " + list.size() + " item(s)");
+ for (int i = 0; i < list.size(); i++) {
+ log.info("Item i:" + list.get(i));
+ }
+
+ shell.close();
+ }
+
+ // ------------------------------------------------------------
+ // Private
+ // ------------------------------------------------------------
+ /*
+ * Invokes ContentAssistProposal shell action
+ */
+ private void invokeContentAssist() {
+ String actionId = "ContentAssistProposal";
+ //final IAction action = ((ITextEditor)
partReference.getEditor(false)).getAction(actionId);
+ final IAction action = ((ITextEditor) editor.getReference().getEditor(
+ false)).getAction(actionId);
+ syncExec(new VoidResult() {
+ public void run() {
+ action.run();
+ }
+ });
+ }
+
+ /**
+ * Return list of table items. Requires activated proposal table
+ * @param table
+ * @return
+ */
+ private List<String> getTableItems(SWTBotTable table) {
+ int rows = table.rowCount();
+ List<String> list = new ArrayList<String>();
+ for (int i = 0; i < rows; i++) {
+ list.add(table.cell(i, 0));
+ }
+ return list;
+ }
+
+ /**
+ * Returns proposal table from propsal shell
+ * @param ccShell
+ * @return
+ */
+ private SWTBotTable getProposalTable(SWTBotShell ccShell) {
+ SWTBot ccBot = new SWTBot(ccShell.widget);
+ return ccBot.table();
+ }
+
+ /**
+ * Opens proposal table
+ * @return proposal bot shell
+ */
+ private SWTBotShell openProposalList() {
+ SWTBotShell[] shells1 = bot.shells();
+ invokeContentAssist();
+ SWTBotShell[] shells2 = bot.shells();
+ SWTBotShell ccShell = getContentAssistShell(shells1, shells2);
+ return ccShell;
+
+ }
+
+ /**
+ * Select table item from code completion table. It's workaround because
+ * SWTBotTable methods doesn't work property for this case
+ *
+ * @param botTable
+ * @param index
+ */
+ private void seletctCCTableItem(final SWTBotTable botTable, final int index) {
+ UIThreadRunnable.asyncExec(new VoidResult() {
+ public void run() {
+ Table table = botTable.widget;
+ table.setSelection(index);
+ Event event = new Event();
+ event.type = SWT.Selection;
+ event.widget = table;
+ event.item = table.getItem(index);
+ table.notifyListeners(SWT.Selection, event);
+ table.notifyListeners(SWT.DefaultSelection, event);
+ }
+ });
+ }
+
+ /**
+ * Return content assist shell as new shell from two collections of shells
+ *
+ * @param s1
+ * @param s2
+ * @return
+ */
+ private SWTBotShell getContentAssistShell(SWTBotShell[] s1, SWTBotShell[] s2) {
+ SWTBotShell ccShell = null;
+ for (SWTBotShell bs2 : s2) {
+ boolean found = false;
+ for (SWTBotShell bs1 : s1) {
+ if (bs2.widget.equals(bs1.widget)) {
+ found = true;
+ break;
+ }
+ }
+ if (found == false) {
+ ccShell = bs2;
+ break;
+ }
+ }
+ return ccShell;
+ }
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ObjectMultiPageEditorBot.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ObjectMultiPageEditorBot.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ObjectMultiPageEditorBot.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -0,0 +1,74 @@
+package org.jboss.tools.ui.bot.ext.parts;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.Result;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.common.editor.ObjectMultiPageEditor;
+
+/**
+ *
+ * @author jpeterka
+ *
+ */
+public class ObjectMultiPageEditorBot {
+
+ String partName;
+ IEditorReference ref;
+
+ public ObjectMultiPageEditorBot(String title) {
+ ref = getEditorReference(title);
+ }
+
+ private IEditorReference getEditorReference(final String title) {
+ // Search for editor
+ IEditorReference ref = UIThreadRunnable.syncExec(new Result<IEditorReference>()
{
+ public IEditorReference run() {
+ IEditorReference ref = null;
+ IEditorReference[] editorReferences = null;
+ editorReferences =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
+
+ try {
+ for (IEditorReference reference: editorReferences) {
+ IEditorInput input = reference.getEditorInput();
+ String name = input.getName();
+ if (name.equals(title)) {
+ return reference;
+ }
+ }
+ } catch (PartInitException ex) {
+ fail(ex.toString());
+ }
+ return ref;
+ }
+ });
+
+ assertNotNull(ref);
+ return ref;
+ }
+
+ public void selectPage(final String pageName) {
+ //assertTrue(ref.getPart(true) instanceof Hibernate3CompoundEditor);
+ assertTrue(ref.getPart(true) instanceof ObjectMultiPageEditor);
+
+ //final Hibernate3CompoundEditor editor =
(Hibernate3CompoundEditor)ref.getPart(true);
+ final ObjectMultiPageEditor editor = (ObjectMultiPageEditor)ref.getPart(true);
+
+ // Select page
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ editor.selectPageByName(pageName);
+ }
+ });
+ }
+}
+
+
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ObjectMultiPageEditorBot.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java 2010-01-25
10:46:56 UTC (rev 19902)
@@ -0,0 +1,23 @@
+package org.jboss.tools.ui.bot.ext.parts;
+
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.ui.IEditorReference;
+
+public class SWTBotEditorExt extends SWTBotEclipseEditor {
+
+
+ public SWTBotEditorExt(IEditorReference editorReference, SWTWorkbenchBot bot)
+ throws WidgetNotFoundException {
+ super(editorReference, bot);
+
+ }
+
+ public ContentAssistBot contentAssist() {
+ ContentAssistBot caBot = new ContentAssistBot(this);
+ return caBot;
+ }
+
+}
+
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain