Author: vpakan(a)redhat.com
Date: 2010-04-22 07:53:35 -0400 (Thu, 22 Apr 2010)
New Revision: 21606
Added:
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsRulesEditorTest.java
Modified:
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
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/SWTBotEditorExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
Log:
Added Drools Rule Editor test.
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-22
09:29:00 UTC (rev 21605)
+++
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java 2010-04-22
11:53:35 UTC (rev 21606)
@@ -17,6 +17,7 @@
import org.jboss.tools.drools.ui.bot.test.smoke.ManageDroolsRuntime;
import org.jboss.tools.drools.ui.bot.test.smoke.ManageDroolsProject;
import org.jboss.tools.drools.ui.bot.test.smoke.ManageDroolsRules;
+import org.jboss.tools.drools.ui.bot.test.smoke.DroolsRulesEditorTest;
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;
@@ -29,7 +30,7 @@
/**
*
- * This is struts swtbot testcase for JBoss Tools.
+ * This is Drools swtbot test case for JBoss Tools.
*
* @author Vladimir Pakan
*
@@ -37,7 +38,8 @@
@RunWith(Suite.class)
@SuiteClasses({ManageDroolsRuntime.class,
ManageDroolsProject.class,
- ManageDroolsRules.class})
+ ManageDroolsRules.class,
+ DroolsRulesEditorTest.class})
public class DroolsAllBotTests extends SWTTestExt {
public static final String DROOLS_PROJECT_NAME = "droolsTest";
public static final String DROOLS_RUNTIME_NAME = "Drools Test Runtime";
Added:
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsRulesEditorTest.java
===================================================================
---
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsRulesEditorTest.java
(rev 0)
+++
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsRulesEditorTest.java 2010-04-22
11:53:35 UTC (rev 21606)
@@ -0,0 +1,96 @@
+ /*******************************************************************************
+ * 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.drools.ui.bot.test.smoke;
+
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.swt.finder.utils.Position;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.parts.ContentAssistBot;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
+import org.jboss.tools.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.drools.ui.bot.test.DroolsAllBotTests;
+import org.junit.Test;
+// import org.eclipse.ui.forms.editor.FormEditor;
+/**
+ * Tests Drools Rule Editor
+ * @author Vladimir Pakan
+ *
+ */
+public class DroolsRulesEditorTest extends SWTTestExt{
+ /**
+ * Tests Drools Rule Editor
+ */
+ private static final String CONTENT_ASSIST_IMPORT = "import";
+ private static final String CONTENT_ASSIST_MESSAGE = "Message";
+ @Test
+ public void testManageDroolsProject() {
+ codeCompletionCheck(DroolsAllBotTests.SAMPLE_DROOLS_RULE_NAME);
+ reteViewCheck(DroolsAllBotTests.SAMPLE_DROOLS_RULE_NAME);
+ }
+ /**
+ * Check code completion for Drools Rule
+ * @param droolsRuleName
+ */
+ private void codeCompletionCheck(String droolsRuleName){
+
+ packageExplorer.show();
+ packageExplorer.openFile(DroolsAllBotTests.DROOLS_PROJECT_NAME ,
+ DroolsAllBotTests.SRC_MAIN_RULES_TREE_NODE,droolsRuleName);
+ SWTBotEditorExt ruleEditor = bot.swtBotEditorExtByTitle(droolsRuleName);
+ ruleEditor.selectPage(IDELabel.DroolsEditor.TEXT_EDITOR_TAB);
+ ruleEditor.typeText(3, 0, "i");
+ ContentAssistBot contentAssist = ruleEditor.contentAssist();
+ contentAssist.checkContentAssist(DroolsRulesEditorTest.CONTENT_ASSIST_IMPORT, true);
+ ruleEditor.typeText(6, 0, "m");
+ contentAssist.checkContentAssist(DroolsRulesEditorTest.CONTENT_ASSIST_MESSAGE,
true);
+
+ SWTBotEclipseEditor ruleTextEditor = ruleEditor.toTextEditor();
+ String lineText = ruleTextEditor.getTextOnLine(3).trim();
+ assertTrue("Content Assist for " +
DroolsRulesEditorTest.CONTENT_ASSIST_IMPORT +
+ " was not inserted properly.\n" +
+ "Inserted text is: " + lineText + "\n" +
+ "Expected text is: " + DroolsRulesEditorTest.CONTENT_ASSIST_IMPORT,
+ lineText.equals(DroolsRulesEditorTest.CONTENT_ASSIST_IMPORT));
+
+ lineText = ruleTextEditor.getTextOnLine(6).trim();
+ String messageContentAssistText = DroolsRulesEditorTest.CONTENT_ASSIST_MESSAGE +
"( )";
+ assertTrue("Content Assist for " +
DroolsRulesEditorTest.CONTENT_ASSIST_MESSAGE +
+ " was not inserted properly.\n" +
+ "Inserted text is: " + lineText + "\n" +
+ "Expected text has to stard with: " + messageContentAssistText,
+ lineText.startsWith(messageContentAssistText));
+
+ Position cursorPosition = ruleTextEditor.cursorPosition();
+ assertTrue("Content Assist for " +
DroolsRulesEditorTest.CONTENT_ASSIST_MESSAGE +
+ " was not inserted properly.\n" +
+ "Position of cursor is wrong: " + cursorPosition + "\n" +
+ "Expected X cursor position is: " + 9,
+ cursorPosition.column == 9);
+
+ ruleEditor.close();
+
+ }
+ /**
+ * Check Rete View of Drools Rule
+ * @param droolsRuleName
+ */
+ private void reteViewCheck(String droolsRuleName){
+
+ packageExplorer.show();
+ packageExplorer.openFile(DroolsAllBotTests.DROOLS_PROJECT_NAME ,
+ DroolsAllBotTests.SRC_MAIN_RULES_TREE_NODE,droolsRuleName);
+ SWTBotEditorExt ruleEditor = bot.swtBotEditorExtByTitle(droolsRuleName);
+ ruleEditor.selectPage(IDELabel.DroolsEditor.RETE_TREE_TAB);
+
+ }
+}
+
Property changes on:
trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsRulesEditorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2010-04-22
09:29:00 UTC (rev 21605)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2010-04-22
11:53:35 UTC (rev 21606)
@@ -618,6 +618,19 @@
}
}
/**
+ * Display all active widgets within parent widget
+ * @param bot
+ * @param parent
+ */
+ public static void displayAllBotWidgets (SWTBot bot, Widget parent){
+ List<?> widgets = bot.widgets(new
SWTUtilExt.AlwaysMatchMatcher<Widget>(),parent);
+ for (Object object : widgets){
+ System.out.println(object +
+ " Text: " + SWTUtilExt.invokeMethod(object, "getText") +
+ " Tooltip: " + SWTUtilExt.invokeMethod(object,
"getToolTipText"));
+ }
+ }
+ /**
* Display all Toolbar Buttons of view
* @param view
*/
@@ -639,7 +652,13 @@
String result = "<null>";
try {
- result = SWTUtils.invokeMethod(object, "getText").toString();
+ Object oResult = SWTUtils.invokeMethod(object, "getText");
+ if (oResult != null){
+ result = oResult.toString();
+ }
+ else{
+ result = "<null>";
+ }
} catch (NoSuchMethodException e) {
result = "<null>";
} catch (IllegalAccessException e) {
Modified:
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 2010-04-22
09:29:00 UTC (rev 21605)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java 2010-04-22
11:53:35 UTC (rev 21606)
@@ -1,6 +1,8 @@
private package org.jboss.tools.ui.bot.ext.parts;
import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@@ -16,11 +18,14 @@
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.editors.text.TextEditor;
+import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.swtbot.swt.finder.results.Result;
/**
* This provides working Content assist functionality.
- * SWTBot (2.0.0#467) funcionality provided in SWTEclipseEditor doesn't work (at
least on GTK linux)
+ * SWTBot (2.0.0#467) functionality provided in SWTEclipseEditor doesn't work (at
least on GTK linux)
* @author jpeterka
*
*/
@@ -39,14 +44,16 @@
// ------------------------------------------------------------
// Constructor
// ------------------------------------------------------------
- /**
- * Basic constructor
- */
- public ContentAssistBot(SWTBotEditorExt editor) {
- this.editor = editor;
- this.bot = editor.bot();
- }
+ /**
+ * Basic constructor
+ */
+ public ContentAssistBot(SWTBotEditorExt editor) {
+ this.editor = editor;
+ this.bot = editor.bot();
+ }
+
+
// ------------------------------------------------------------
// Public
// ------------------------------------------------------------
@@ -77,17 +84,26 @@
* @param text
*/
public void logProposalList() {
- SWTBotShell shell = openProposalList();
- SWTBotTable table = getProposalTable(shell);
- List<String> list = getTableItems(table);
+ List<String> list = getProposalList();
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();
}
-
+ /**
+ * Logs proposal list contents, usual for debug purposes
+ *
+ * @param text
+ */
+ public List<String>getProposalList() {
+ List<String> result = null;
+ SWTBotShell shell = openProposalList();
+ SWTBotTable table = getProposalTable(shell);
+ result = getTableItems(table);
+ shell.close();
+
+ return result;
+ }
// ------------------------------------------------------------
// Private
// ------------------------------------------------------------
@@ -97,8 +113,31 @@
private void invokeContentAssist() {
String actionId = "ContentAssistProposal";
//final IAction action = ((ITextEditor)
partReference.getEditor(false)).getAction(actionId);
+ Object oEditor = editor.getReference().getEditor(false);
+ ITextEditor textEditor = null;
+ // When editor is instance of FormEditor we have to get editor from page specified by
pageIndex
+ if (oEditor instanceof FormEditor){
+ final FormEditor formEditor = (FormEditor)oEditor;
+ textEditor = syncExec(new Result<ITextEditor>() {
+ public ITextEditor run() {
+ ITextEditor textEditor = null;
+ Object oEditor2 = formEditor.getActiveEditor();
+ if (oEditor2 instanceof TextEditor){
+ textEditor = (ITextEditor)oEditor2;
+ }
+ return textEditor;
+ }
+ });
+
+ }
+ else{
+ textEditor = (ITextEditor)oEditor;
+ }
+/*
final IAction action = ((ITextEditor) editor.getReference().getEditor(
false)).getAction(actionId);
+*/
+ final IAction action = textEditor.getAction(actionId);
syncExec(new VoidResult() {
public void run() {
action.run();
@@ -189,4 +228,27 @@
}
return ccShell;
}
+ /**
+ * Check if contentAssistItemLabel is present within Content Assist and
+ * choose it when applyContentAssist is true
+ * @param contentAssistItemLabel
+ * @param applyContentAssist
+ */
+ public void checkContentAssist(String contentAssistItemLabel,boolean
applyContentAssist){
+ List<String> proposalList = getProposalList();
+
+ assertNotNull("Editor Content Assist doesn't containt item with label: "
+ contentAssistItemLabel +
+ ". It's null",
+ proposalList);
+
+ int itemIndex = proposalList.indexOf(contentAssistItemLabel);
+
+ assertTrue("Editor Content Assist doesn't containt item with label: " +
contentAssistItemLabel,
+ itemIndex > -1);
+
+ if (applyContentAssist){
+ useProposal(itemIndex);
+ }
+
+ }
}
Modified:
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 2010-04-22
09:29:00 UTC (rev 21605)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java 2010-04-22
11:53:35 UTC (rev 21606)
@@ -1,8 +1,26 @@
+ /*******************************************************************************
+ * 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.parts;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withText;
+
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
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.swtbot.swt.finder.widgets.SWTBotCTabItem;
import org.eclipse.ui.IEditorReference;
public class SWTBotEditorExt extends SWTBotEclipseEditor {
@@ -19,5 +37,32 @@
return caBot;
}
+ public void selectPage(int pageIndex){
+ try{
+ final CTabFolder tabFolder = this.findWidget(widgetOfType(CTabFolder.class));
+ final int tabFolderPageIndex = pageIndex;
+ bot.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ if (tabFolder.getItemCount() > tabFolderPageIndex){
+ tabFolder.setSelection(tabFolderPageIndex);
+ }
+ }
+ });
+ } catch (WidgetNotFoundException wnfe){
+ // do nothing there is no tabfolder in editor
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void selectPage(String pageLabel){
+ try{
+ final CTabFolder tabFolder = this.findWidget(widgetOfType(CTabFolder.class));
+ final CTabItem tabItem =
((CTabItem)this.bot.widget(allOf(widgetOfType(CTabItem.class),withText(pageLabel)),
+ tabFolder));
+ new SWTBotCTabItem(tabItem).activate();
+ } catch (WidgetNotFoundException wnfe){
+ // do nothing there is no tabfolder in editor
+ }
+ }
}
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-22
09:29:00 UTC (rev 21605)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java 2010-04-22
11:53:35 UTC (rev 21606)
@@ -380,4 +380,11 @@
public static final String BUTTON_RESUME_TOOLTIP = "Resume (F8)";
}
+
+ public static class DroolsEditor {
+
+ public static final String TEXT_EDITOR_TAB = "Text Editor";
+ public static final String RETE_TREE_TAB = "Rete Tree";
+
+ }
}