Author: ljelinko
Date: 2011-11-21 11:51:12 -0500 (Mon, 21 Nov 2011)
New Revision: 36500
Added:
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/XMLFileNodeContentMatcher.java
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/XMLNode.java
Log:
created new matcher
Added:
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/XMLFileNodeContentMatcher.java
===================================================================
---
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/XMLFileNodeContentMatcher.java
(rev 0)
+++
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/XMLFileNodeContentMatcher.java 2011-11-21
16:51:12 UTC (rev 36500)
@@ -0,0 +1,74 @@
+package org.jboss.tools.portlet.ui.bot.test.matcher.workspace.file.xml;
+
+import java.util.Arrays;
+
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.hamcrest.Description;
+import org.jboss.tools.portlet.ui.bot.test.matcher.AbstractSWTMatcher;
+import org.jboss.tools.ui.bot.ext.SWTBotFactory;
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
+
+/**
+ * Checks if the file contains specified nodes.
+ *
+ * @author Lucia Jelinkova
+ *
+ */
+public class XMLFileNodeContentMatcher extends AbstractSWTMatcher<XMLNode[]> {
+
+ private String project;
+
+ private String file;
+
+ public XMLFileNodeContentMatcher(String project, String file) {
+ super();
+ this.project = project;
+ this.file = file;
+ }
+
+ @Override
+ public boolean matchesSafely(XMLNode[] nodes) {
+ String[] filePath = file.split("/");
+ SWTBotFactory.getPackageexplorer().openFile(project, filePath);
+ SWTBotEditorExt editor =
SWTBotFactory.getBot().swtBotEditorExtByTitle(filePath[filePath.length - 1]);
+ SWTBotTree tree = editor.bot().tree();
+
+ for (XMLNode node : nodes){
+ if (!containsNode(editor.bot(), tree, node)){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean containsNode(SWTBot bot, SWTBotTree tree, XMLNode node) {
+ for (String s : getNodePath(node)){
+ System.out.println("Path element: " + s);
+ }
+ System.out.println("Name: " + getNodeName(node));
+ SWTBotTreeItem item = SWTEclipseExt.getTreeItemOnPathStartsWith(bot, tree, 0,
getNodeName(node), getNodePath(node));
+ return item.cell(1).contains(node.getContent());
+ }
+
+ private String[] getNodePath(XMLNode node) {
+ String[] path = node.getPath().split("/");
+ if (path.length <= 1){
+ return new String[0];
+ }
+ return Arrays.copyOfRange(path, 0, path.length - 1);
+ }
+
+ private String getNodeName(XMLNode node) {
+ String[] path = node.getPath().split("/");
+ return path[path.length - 1];
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("file " + project + "/" + file + "
contains the node(s)");
+ }
+}
+
Added:
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/XMLNode.java
===================================================================
---
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/XMLNode.java
(rev 0)
+++
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/matcher/workspace/file/xml/XMLNode.java 2011-11-21
16:51:12 UTC (rev 36500)
@@ -0,0 +1,36 @@
+package org.jboss.tools.portlet.ui.bot.test.matcher.workspace.file.xml;
+
+
+public class XMLNode {
+
+ private String path;
+
+ private String content;
+
+ public XMLNode(String path, String content) {
+ super();
+ this.path = path;
+ this.content = content;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ @Override
+ public String toString() {
+ return "XML path = " + getPath() + ", content = " + getContent();
+ }
+}
Show replies by date