Author: vpakan(a)redhat.com
Date: 2011-06-09 10:14:31 -0400 (Thu, 09 Jun 2011)
New Revision: 31962
Added:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SelectTextInSourcePaneException.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/OpenOnHelper.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/smoke/OpenOnTest.java
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java
Log:
Added testing of Open Ons functionality within VPE.
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2011-06-09
13:42:17 UTC (rev 31961)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2011-06-09
14:14:31 UTC (rev 31962)
@@ -32,6 +32,7 @@
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
@@ -799,5 +800,77 @@
File.separator +
projectName;
}
+ /**
+ * Selects textToSelect within Source Pane of editor with title editorTitle
+ * @param bot
+ * @param editorTitle
+ * @param textToSelect
+ * @param selectionOffset
+ * @param selectionLength
+ * @return SWTBotEclipseEditor
+ */
+ public static SWTBotEclipseEditor selectTextInSourcePane(SWTBotExt bot,
+ String editorTitle, String textToSelect ,
+ int selectionOffset , int selectionLength) {
+ return selectTextInSourcePane(bot, editorTitle, textToSelect,
+ selectionOffset, selectionLength, 0);
+ }
+ /**
+ * Selects textToSelect within Source Pane of editor with title editorTitle
+ * @param bot
+ * @param editorTitle
+ * @param textToSelect
+ * @param selectionOffset
+ * @param selectionLength
+ * @param textToSelectIndex
+ * @return SWTBotEclipseEditor
+ */
+ public static SWTBotEclipseEditor selectTextInSourcePane(SWTBotExt bot,
+ String editorTitle, String textToSelect ,
+ int selectionOffset , int selectionLength , int textToSelectIndex) {
+
+ SWTBotEclipseEditor editor = bot.editorByTitle(editorTitle).toTextEditor();
+ String editorText = editor.getText();
+ boolean found = false;
+ int iStartIndex = 0;
+ int iRow = 0;
+ if (editorText != null && editorText.length() > 0 &&
editorText.contains(textToSelect)){
+ String[] editorLines = editorText.split("\n");
+ int iOccurenceIndex = 0;
+ while (!found && iRow < editorLines.length){
+ String lineText = editorLines[iRow];
+ iStartIndex = 0;
+ while (!found && lineText.contains(textToSelect)){
+ if (iOccurenceIndex == textToSelectIndex){
+ found = true;
+ iStartIndex += lineText.indexOf(textToSelect);
+ }
+ else{
+ iOccurenceIndex++;
+ int iNewStartIndex = lineText.indexOf(textToSelect) + textToSelect.length();
+ iStartIndex += iNewStartIndex;
+ lineText = lineText.substring(iNewStartIndex);
+ }
+ }
+ if (!found){
+ iRow++;
+ }
+ }
+
+ }
+
+ if (found) {
+ editor.selectRange(iRow, iStartIndex + selectionOffset, selectionLength);
+ }
+ else{
+ throw new SelectTextInSourcePaneException ("Wrong parameters specified for
method selectTextInSourcePane.\n" +
+ "Unable to select required text '" + textToSelect +
+ "' within editor with title " + editorTitle + ".\n" +
+ "Editor text is: " + editorText);
+ }
+
+ return editor;
+
+ }
}
\ No newline at end of file
Added:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SelectTextInSourcePaneException.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SelectTextInSourcePaneException.java
(rev 0)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SelectTextInSourcePaneException.java 2011-06-09
14:14:31 UTC (rev 31962)
@@ -0,0 +1,20 @@
+package org.jboss.tools.ui.bot.ext;
+/**
+ * an exception thrown when it's nopt possible to select required text within Source
pane of VPE
+ * @author vpakan
+ *
+ */
+public class SelectTextInSourcePaneException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ public SelectTextInSourcePaneException(String message, Throwable t) {
+ super(message,t);
+ }
+ public SelectTextInSourcePaneException(String message) {
+ super(message);
+ }
+
+}
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SelectTextInSourcePaneException.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/OpenOnHelper.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/OpenOnHelper.java
(rev 0)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/OpenOnHelper.java 2011-06-09
14:14:31 UTC (rev 31962)
@@ -0,0 +1,71 @@
+ /*******************************************************************************
+ * Copyright (c) 2007-2011 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.helper;
+
+import static org.junit.Assert.assertTrue;
+
+import java.awt.event.KeyEvent;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.SWTUtilExt;
+import org.jboss.tools.ui.bot.ext.Timing;
+
+/**
+ * Helper for Open On functionality testing
+ * @author Vladimir Pakan
+ *
+ */
+public class OpenOnHelper {
+ protected static final Logger log = Logger.getLogger(OpenOnHelper.class);
+ /**
+ * Applies Open On (F3) on textToSelect within editor with editorTitle
+ * and checks if expectedOpenedFileName was opened
+ * @param editorTitle
+ * @param textToSelect
+ * @param selectionOffset
+ * @param selectionLength
+ * @param textToSelectIndex
+ * @param expectedOpenedFileName
+ */
+ public static SWTBotEditor checkOpenOnFileIsOpened(SWTBotExt bot,
+ String editorTitle, String textToSelect ,
+ int selectionOffset , int selectionLength , int textToSelectIndex,
+ String expectedOpenedFileName){
+
+ SWTBotEditor openedEditor = null;
+
+ SWTBotEclipseEditor sourceEditor = SWTUtilExt.selectTextInSourcePane(bot,
editorTitle, textToSelect,
+ selectionOffset, selectionLength, textToSelectIndex);
+
+ bot.sleep(Timing.time1S());
+
+ sourceEditor.setFocus();
+
+ bot.sleep(Timing.time1S());
+
+ KeyboardHelper.typeKeyCodeUsingAWT(KeyEvent.VK_F3);
+
+ bot.sleep(Timing.time3S());
+
+ openedEditor = bot.activeEditor();
+
+ assertTrue("Opened file has to have title " + expectedOpenedFileName +
" but has " + openedEditor.getTitle(),
+ openedEditor.getTitle().equalsIgnoreCase(expectedOpenedFileName));
+
+ return openedEditor;
+
+ }
+
+}
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/OpenOnHelper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java 2011-06-09
13:42:17 UTC (rev 31961)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java 2011-06-09
14:14:31 UTC (rev 31962)
@@ -82,6 +82,7 @@
public static final String COPY = "Copy";
public static final String PASTE = "Paste";
public static final String UNDO = "Undo";
+ public static final String CLOSE_ALL = "Close All";
}
public class Button {
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java 2011-06-09
13:42:17 UTC (rev 31961)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java 2011-06-09
14:14:31 UTC (rev 31962)
@@ -77,6 +77,7 @@
import org.jboss.tools.vpe.ui.bot.test.palette.PaletteEditorTest;
import org.jboss.tools.vpe.ui.bot.test.smoke.EditorSynchronizationTest;
import org.jboss.tools.vpe.ui.bot.test.smoke.JSPPageCreationTest;
+import org.jboss.tools.vpe.ui.bot.test.smoke.OpenOnTest;
import org.jboss.tools.vpe.ui.bot.test.smoke.RenameFacesConfigFileTest;
import org.jboss.tools.vpe.ui.bot.test.smoke.RenameJSPFileTest;
import org.jboss.tools.vpe.ui.bot.test.smoke.RenameXHTMLFileTest;
@@ -169,6 +170,7 @@
suite.addTestSuite(IncludeTagTest.class);
suite.addTestSuite(AjaxInvisibleTagsTest.class);
suite.addTestSuite(LogTagTest.class);
+ suite.addTestSuite(OpenOnTest.class);
suite.addTestSuite(XhtmlFilePerformanceTest.class);
return new TestSetup(suite);
}
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/smoke/OpenOnTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/smoke/OpenOnTest.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/smoke/OpenOnTest.java 2011-06-09
14:14:31 UTC (rev 31962)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 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.vpe.ui.bot.test.smoke;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.helper.OpenOnHelper;
+import org.jboss.tools.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.ui.bot.test.JBTSWTBotTestCase;
+import org.jboss.tools.vpe.ui.bot.test.editor.VPEEditorTestCase;
+/**
+ * Test open on functionality
+ * @author Vladimir Pakan
+ *
+ */
+public class OpenOnTest extends VPEEditorTestCase{
+ private static Logger log = Logger.getLogger(JBTSWTBotTestCase.class);
+ public void testOpenOn() throws Throwable{
+ try{
+ bot.menu(IDELabel.Menu.FILE).menu(IDELabel.Menu.CLOSE_ALL).click();
+ log.info("All Editors closed");
+ } catch (WidgetNotFoundException wnfe){
+ log.info("No Editors to close");
+ } catch (TimeoutException te){
+ log.info("No Editors to close");
+ }
+
+
+ openPage();
+ checkOpenOn();
+
+ }
+ /**
+ * Check Open On functionality for jsp page
+ */
+ private void checkOpenOn() {
+ // Check open on for
uri="http://java.sun.com/jsf/html"
+ String expectedOpenedFileName = "html_basic.tld";
+ SWTBotEditor openedEditor = OpenOnHelper.checkOpenOnFileIsOpened(
+ SWTTestExt.bot, TEST_PAGE,
"uri=\"http://java.sun.com/jsf/html\"", 5,
+ 0, 0, expectedOpenedFileName);
+ String selectedTreeItemLabel = openedEditor.bot().tree().selection()
+ .get(0, 0);
+ assertTrue("Selected tree item has to have label " +
expectedOpenedFileName
+ + " but it has " + selectedTreeItemLabel,
+ selectedTreeItemLabel.equalsIgnoreCase(expectedOpenedFileName));
+ openedEditor.close();
+ // Check open on for
uri="http://java.sun.com/jsf/core"
+ expectedOpenedFileName = "jsf_core.tld";
+ openedEditor = OpenOnHelper.checkOpenOnFileIsOpened(SWTTestExt.bot,
+ TEST_PAGE, "uri=\"http://java.sun.com/jsf/core\"", 5, 0, 0,
+ expectedOpenedFileName);
+ selectedTreeItemLabel = openedEditor.bot().tree().selection().get(0, 0);
+ assertTrue("Selected tree item has to have label " +
expectedOpenedFileName
+ + " but it has " + selectedTreeItemLabel,
+ selectedTreeItemLabel.equalsIgnoreCase(expectedOpenedFileName));
+ openedEditor.close();
+ // Check open on for h:outputText
+ String tagToCheck = "outputText";
+ expectedOpenedFileName = "html_basic.tld";
+ openedEditor = OpenOnHelper.checkOpenOnFileIsOpened(SWTTestExt.bot,
+ TEST_PAGE, "h:" + tagToCheck, 5, 0, 0,
+ expectedOpenedFileName);
+ selectedTreeItemLabel = openedEditor.bot().tree().selection().get(0, 0);
+ assertTrue("Selected tree item has to have label " + tagToCheck
+ + " but it has " + selectedTreeItemLabel,
+ selectedTreeItemLabel.equalsIgnoreCase(tagToCheck));
+ openedEditor.close();
+ // Check open on for f:view
+ tagToCheck = "view";
+ expectedOpenedFileName = "jsf_core.tld";
+ openedEditor = OpenOnHelper.checkOpenOnFileIsOpened(SWTTestExt.bot,
+ TEST_PAGE, "f:" + tagToCheck, 5, 0, 0,
+ expectedOpenedFileName);
+ selectedTreeItemLabel = openedEditor.bot().tree().selection().get(0, 0);
+ assertTrue("Selected tree item has to have label " + tagToCheck
+ + " but it has " + selectedTreeItemLabel,
+ selectedTreeItemLabel.equalsIgnoreCase(tagToCheck));
+ openedEditor.close();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/smoke/OpenOnTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain