Author: vpakan(a)redhat.com
Date: 2010-10-25 07:17:27 -0400 (Mon, 25 Oct 2010)
New Revision: 26027
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/InsertActionsTest.java
Modified:
trunk/jst/tests/org.jboss.tools.jst.ui.bot.test/src/org/jboss/tools/ui/bot/test/JBTSWTBotTestCase.java
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/VPEAutoTestCase.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/VPEEditorTestCase.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java
Log:
Added InsertActionsTest.
Modified:
trunk/jst/tests/org.jboss.tools.jst.ui.bot.test/src/org/jboss/tools/ui/bot/test/JBTSWTBotTestCase.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.ui.bot.test/src/org/jboss/tools/ui/bot/test/JBTSWTBotTestCase.java 2010-10-25
11:14:55 UTC (rev 26026)
+++
trunk/jst/tests/org.jboss.tools.jst.ui.bot.test/src/org/jboss/tools/ui/bot/test/JBTSWTBotTestCase.java 2010-10-25
11:17:27 UTC (rev 26027)
@@ -13,7 +13,10 @@
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
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.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.view.ProblemsView;
public abstract class JBTSWTBotTestCase extends SWTTestExt implements
ILogListener {
@@ -361,5 +364,16 @@
}
return process;
}
-
+ /**
+ * Asserts if Problems View has no errors
+ * @param botExt
+ */
+ protected static void assertProbelmsViewNoErrors (SWTBotExt botExt){
+
+ SWTBotTreeItem[] errors = ProblemsView.getFilteredErrorsTreeItems(botExt, null, null,
null, null);
+
+ assertTrue("There are errors in Problems view: " +
+ (errors != null && errors.length > 0 ? errors[0].getText() :
""),
+ errors == null);
+ }
}
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 2010-10-25
11:14:55 UTC (rev 26026)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java 2010-10-25
11:17:27 UTC (rev 26027)
@@ -5,6 +5,7 @@
import junit.framework.TestSuite;
import org.eclipse.swtbot.swt.finder.SWTBotTestCase;
import org.jboss.tools.vpe.ui.bot.test.editor.BlockCommentTest;
+import org.jboss.tools.vpe.ui.bot.test.editor.InsertActionsTest;
import org.jboss.tools.vpe.ui.bot.test.editor.ToggleCommentTest;
import org.jboss.tools.vpe.ui.bot.test.editor.VerificationOfNameSpacesTest;
import org.jboss.tools.vpe.ui.bot.test.editor.JspFileEditingTest;
@@ -66,6 +67,7 @@
suite.addTestSuite(PaletteEditorTest.class);
suite.addTestSuite(ToolbarTextFormattingTest.class);
suite.addTestSuite(VisualEditorContextMenuTest.class);
+ suite.addTestSuite(InsertActionsTest.class);
return new TestSetup(suite);
}
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAutoTestCase.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAutoTestCase.java 2010-10-25
11:14:55 UTC (rev 26026)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAutoTestCase.java 2010-10-25
11:17:27 UTC (rev 26027)
@@ -13,6 +13,7 @@
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.jst.jsp.jspeditor.JSPMultiPageEditor;
import org.jboss.tools.test.TestProperties;
import org.jboss.tools.vpe.ui.bot.test.Activator;
@@ -414,24 +415,35 @@
protected abstract boolean isUnuseDialogOpened();
- protected void openPage(){
+ protected void openPage(String pageName){
SWTBot innerBot = bot.viewByTitle(WidgetVariables.PACKAGE_EXPLORER).bot();
SWTBotTree tree = innerBot.tree();
tree.expandNode(JBT_TEST_PROJECT_NAME)
-
.expandNode("WebContent").expandNode("pages").getNode(TEST_PAGE).doubleClick();
//$NON-NLS-1$ //$NON-NLS-2$
+
.expandNode("WebContent").expandNode("pages").getNode(pageName).doubleClick();
//$NON-NLS-1$ //$NON-NLS-2$
+ bot.sleep(Timing.time3S());
}
+
+ protected void openPage(){
+ openPage(TEST_PAGE);
+ }
/**
* Creates new empty JSP page within test project
* @param pageName
*/
protected void createJspPage (String pageName){
- packageExplorer.selectTreeItem("pages", new String[]
{VPEAutoTestCase.JBT_TEST_PROJECT_NAME,"WebContent"});
- open.newObject(ActionItem.NewObject.WebJSP.LABEL);
- bot.shell(IDELabel.Shell.NEW_JSP_FILE).activate();
- bot.textWithLabel(ActionItem.NewObject.WebJSP.TEXT_FILE_NAME).setText(pageName);
- bot.button(IDELabel.Button.NEXT).click();
- bot.table().select(IDELabel.NewJSPFileDialog.JSP_TEMPLATE);
- bot.button(IDELabel.Button.FINISH).click();
- bot.sleep(Timing.time2S());
+ SWTBotTreeItem tiPages = packageExplorer.selectTreeItem("pages", new
String[] {VPEAutoTestCase.JBT_TEST_PROJECT_NAME,"WebContent"});
+ tiPages.expand();
+ try {
+ tiPages.getNode(pageName);
+ openPage(pageName);
+ } catch (WidgetNotFoundException e) {
+ open.newObject(ActionItem.NewObject.WebJSP.LABEL);
+ bot.shell(IDELabel.Shell.NEW_JSP_FILE).activate();
+ bot.textWithLabel(ActionItem.NewObject.WebJSP.TEXT_FILE_NAME).setText(pageName);
+ bot.button(IDELabel.Button.NEXT).click();
+ bot.table().select(IDELabel.NewJSPFileDialog.JSP_TEMPLATE);
+ bot.button(IDELabel.Button.FINISH).click();
+ bot.sleep(Timing.time2S());
+ }
}
}
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/InsertActionsTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/InsertActionsTest.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/InsertActionsTest.java 2010-10-25
11:17:27 UTC (rev 26027)
@@ -0,0 +1,202 @@
+/*******************************************************************************
+
+ * Copyright (c) 2007-2010 Exadel, Inc. and 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.ui.bot.test.editor;
+
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.Timing;
+import org.jboss.tools.vpe.ui.bot.test.tools.SWTBotWebBrowser;
+import org.mozilla.interfaces.nsIDOMNode;
+/**
+ * Tests JSP file Insert Actions
+ * @author vlado pakan
+ *
+ */
+public class InsertActionsTest extends VPEEditorTestCase {
+
+ private SWTBotExt botExt = null;
+
+ private static final String PAGE_TEXT = "<%@ taglib
uri=\"http://java.sun.com/jsf/html\" prefix=\"h\" %>\n" +
+ "<html>\n" +
+ " <body>\n" +
+ " plain text inserted\n" +
+ " <h:outputText value=\"Studio\" />\n" +
+ " <h:inputText/>\n" +
+ " </body>\n" +
+ "</html>";
+
+ private static final String TEST_PAGE_NAME = "InsertActionsTest.jsp";
+
+ private SWTBotEclipseEditor jspTextEditor;
+ private SWTBotWebBrowser webBrowser;
+
+ public InsertActionsTest() {
+ super();
+ botExt = new SWTBotExt();
+ }
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ eclipse.maximizeActiveShell();
+ createJspPage(InsertActionsTest.TEST_PAGE_NAME);
+ jspTextEditor =
botExt.editorByTitle(InsertActionsTest.TEST_PAGE_NAME).toTextEditor();
+ webBrowser = new SWTBotWebBrowser(InsertActionsTest.TEST_PAGE_NAME,botExt);
+
+ }
+ /**
+ * Insert Tag After Selected Tag
+ */
+ public void testInsertTagAfter(){
+
+ nsIDOMNode node = initJspPageBeforeInserting(InsertActionsTest.PAGE_TEXT,
"INPUT");
+
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.INSERT_AFTER_MENU_LABEL,
+ SWTBotWebBrowser.JBOSS_MENU_LABEL, SWTBotWebBrowser.RICH_FACES_MENU_LABEL,
+ SWTBotWebBrowser.RICH_CALENDAR_TAG_MENU_LABEL);
+
+ jspTextEditor.save();
+ botExt.sleep(Timing.time3S());
+ String editorText = jspTextEditor.getText();
+ // Check if tag <rich:calendar> was properly added
+ assertTrue("File " + TEST_PAGE
+ + " has to contain string
'<h:inputText/><rich:calendar>' but it doesn't.\nIt contains:
" + editorText,
+ editorText.contains("<h:inputText/><rich:calendar>"));
+
+ assertTrue("Visual Representation of file " + TEST_PAGE
+ + " has to contain rich:calendar but it doesn't",
+
webBrowser.containsNodeWithNameAndAttributes(webBrowser.getMozillaEditor().getDomDocument(),
"SPAN",
+ new String[]{"title"},new String[] {"rich:calendar"}));
+
+ assertProbelmsViewNoErrors(botExt);
+
+ }
+ /**
+ * Insert Tag Before Selected Tag
+ */
+ public void testInsertTagBefore(){
+
+ nsIDOMNode node =
initJspPageBeforeInserting(InsertActionsTest.PAGE_TEXT,"INPUT");
+
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.INSERT_BEFORE_MENU_LABEL,
+ SWTBotWebBrowser.JBOSS_MENU_LABEL, SWTBotWebBrowser.RICH_FACES_MENU_LABEL,
+ SWTBotWebBrowser.RICH_CALENDAR_TAG_MENU_LABEL);
+
+ jspTextEditor.save();
+ botExt.sleep(Timing.time3S());
+ String trimedEditorText =
VPEEditorTestCase.stripHTMLSourceText(jspTextEditor.getText());
+ // Check if tag <rich:calendar> was properly added
+ assertTrue("File " + TEST_PAGE
+ + " has to contain string
'<rich:calendar></rich:calendar><h:inputText/>' but it
doesn't.\nIt contains: " + trimedEditorText,
+
trimedEditorText.contains("<rich:calendar></rich:calendar><h:inputText/>"));
+
+ assertTrue("Visual Representation of file " + TEST_PAGE
+ + " has to contain rich:calendar but it doesn't",
+
webBrowser.containsNodeWithNameAndAttributes(webBrowser.getMozillaEditor().getDomDocument(),
"SPAN",
+ new String[]{"title"},new String[] {"rich:calendar"}));
+
+ assertProbelmsViewNoErrors(botExt);
+
+ }
+
+ /**
+ * Insert Tag Into Selected Tag
+ */
+ public void testInsertTagInto(){
+
+ nsIDOMNode node = initJspPageBeforeInserting("<%@ taglib
uri=\"http://java.sun.com/jsf/html\" prefix=\"h\" %>\n" +
+ "<html>\n" +
+ " <body>\n" +
+ " plain text inserted\n" +
+ " <form>\n" +
+ " </form>\n" +
+ " </body>\n" +
+ "</html>",
+ "FORM");
+
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.INSERT_INTO_MENU_LABEL,
+ SWTBotWebBrowser.JBOSS_MENU_LABEL, SWTBotWebBrowser.RICH_FACES_MENU_LABEL,
+ SWTBotWebBrowser.RICH_CALENDAR_TAG_MENU_LABEL);
+
+ jspTextEditor.save();
+ botExt.sleep(Timing.time3S());
+ String trimedEditorText =
VPEEditorTestCase.stripHTMLSourceText(jspTextEditor.getText());
+ // Check if tag <rich:calendar> was properly added
+ assertTrue("File " + TEST_PAGE
+ + " has to contain string
'<form><rich:calendar></rich:calendar></form>' but it
doesn't.\nIt contains: " + trimedEditorText,
+
trimedEditorText.contains("<form><rich:calendar></rich:calendar></form>"));
+
+ assertTrue("Visual Representation of file " + TEST_PAGE
+ + " has to contain rich:calendar but it doesn't",
+
webBrowser.containsNodeWithNameAndAttributes(webBrowser.getMozillaEditor().getDomDocument(),
"FORM"));
+
+ assertProbelmsViewNoErrors(botExt);
+
+ }
+
+ /**
+ * Insert Tag Around Selected Tag
+ */
+ public void testInsertTagAround(){
+
+ nsIDOMNode node = initJspPageBeforeInserting(InsertActionsTest.PAGE_TEXT,
"INPUT");
+
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.INSERT_AROUND_MENU_LABEL,
+ SWTBotWebBrowser.JSF_MENU_LABEL, SWTBotWebBrowser.HTML_MENU_LABEL,
+ SWTBotWebBrowser.H_FORM_TAG_MENU_LABEL);
+
+ jspTextEditor.save();
+ botExt.sleep(Timing.time3S());
+ String trimedEditorText =
VPEEditorTestCase.stripHTMLSourceText(jspTextEditor.getText());
+ // Check if tag <h:form> was properly added
+ assertTrue("File " + TEST_PAGE
+ + " has to contain string
'<h:form><h:inputText/></h:form>' but it doesn't.\nIt
contains: " + trimedEditorText,
+
trimedEditorText.contains("<h:form><h:inputText/></h:form>"));
+
+ assertTrue("Visual Representation of file " + TEST_PAGE
+ + " has to contain h:form but it doesn't",
+
webBrowser.containsNodeWithNameAndAttributes(webBrowser.getMozillaEditor().getDomDocument(),
"FORM"));
+
+ assertProbelmsViewNoErrors(botExt);
+
+ }
+
+ /**
+ * Inits JSP Page before Tag will be inserted
+ */
+ private nsIDOMNode initJspPageBeforeInserting(String pageText , String nodeText) {
+
+ jspTextEditor.setText(pageText);
+ jspTextEditor.save();
+ botExt.sleep(Timing.time3S());
+ nsIDOMNode node = webBrowser.getDomNodeByTagName(nodeText, 0);
+ webBrowser.selectDomNode(node, 0);
+ botExt.sleep(Timing.time1S());
+
+ return node;
+
+ }
+
+ @Override
+ protected void closeUnuseDialogs() {
+
+ }
+
+ @Override
+ protected boolean isUnuseDialogOpened() {
+ return false;
+ }
+
+}
Property changes on:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/InsertActionsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/VPEEditorTestCase.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/VPEEditorTestCase.java 2010-10-25
11:14:55 UTC (rev 26026)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/VPEEditorTestCase.java 2010-10-25
11:17:27 UTC (rev 26027)
@@ -79,5 +79,13 @@
}
super.tearDown();
}
+
+ /**
+ * Returns HTML Source striped from spaces, tabs and EOL
+ * @return String
+ */
+ protected static String stripHTMLSourceText(String editorText){
+ return editorText.replaceAll("\n", "").replaceAll("\t",
"").replaceAll(" ", "");
+ }
}
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java 2010-10-25
11:14:55 UTC (rev 26026)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java 2010-10-25
11:17:27 UTC (rev 26027)
@@ -87,8 +87,12 @@
public static final String PASTE_MENU_LABEL = "Paste";
public static final String JSF_MENU_LABEL = "JSF";
+ public static final String JBOSS_MENU_LABEL = "JBoss";
+ public static final String RICH_FACES_MENU_LABEL = "RichFaces";
public static final String HTML_MENU_LABEL = "HTML";
public static final String H_OUTPUT_TEXT_TAG_MENU_LABEL =
"<h:outputText>";
+ public static final String H_FORM_TAG_MENU_LABEL = "<h:form>";
+ public static final String RICH_CALENDAR_TAG_MENU_LABEL =
"<rich:calendar>";
private Display display;
private IVisualEditor visualEditor;
@@ -368,13 +372,82 @@
}
/**
+ * Returns true if node or it's child has node with specified name and attributes
with specified values
+ * @param node
+ * @param searchName
+ * @param attributeNames
+ * @param attributeValues
+ * @return
+ */
+ public boolean containsNodeWithNameAndAttributes(nsIDOMNode node, String searchName ,
String[] attributeNames , String[] attributeValues) {
+
+ boolean result = false;
+
+ String nodeName = node.getNodeName();
+ if (nodeName != null && nodeName.equals(searchName)) {
+ // Test Attributes
+ if (attributeNames != null){
+ boolean attributesAreEqual = true;
+ nsIDOMNamedNodeMap attributesMap = node.getAttributes();
+ for (int index = 0 ; index < attributeNames.length &&
attributesAreEqual; index++){
+ nsIDOMNode attributeNode = attributesMap.getNamedItem(attributeNames[index]);
+ if (attributeNode != null){
+ if (!attributeNode.getNodeValue().equalsIgnoreCase(attributeValues[index])){
+ attributesAreEqual = false;
+ }
+ }
+ else{
+ attributesAreEqual = false;
+ }
+ }
+ if (attributesAreEqual){
+ result = true;
+ }
+ }
+ else{
+ result = true;
+ }
+ }
+
+ if (!result) {
+ nsIDOMNodeList children = node.getChildNodes();
+
+ for (int i = 0; i < children.getLength() && !result; i++) {
+
+ nsIDOMNode child = children.item(i);
+
+ // leave out empty text nodes in test dom model
+ if ((child.getNodeType() == Node.TEXT_NODE)
+ && ((child.getNodeValue() == null) || (child.getNodeValue().trim()
+ .length() == 0)))
+ continue;
+
+ result = containsNodeWithNameAndAttributes(child,
searchName,attributeNames,attributeValues);
+ }
+ }
+
+ return result;
+
+ }
+ /**
+ * Returns true if node or it's child has node with specified name
+ * @param node
+ * @param searchName
+ * @return
+ */
+ public boolean containsNodeWithNameAndAttributes(nsIDOMNode node, String searchName) {
+
+ return containsNodeWithNameAndAttributes(node, searchName,null,null);
+
+ }
+
+ /**
* Returns true if node or it's child has value searchText
* @param node
* @param searchText
* @return
*/
public boolean containsNodeWithValue(nsIDOMNode node, String searchText) {
-
boolean result = false;
String nodeValue = node.getNodeValue();
@@ -400,7 +473,6 @@
}
return result;
-
}
/**
* Returns Palette Viewer associated to JBoss Tools Palette