Author: jlukas(a)redhat.com
Date: 2010-11-01 12:51:41 -0400 (Mon, 01 Nov 2010)
New Revision: 26168
Added:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/CDIAllBotTests.launch
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/CDIAllBotTests.java
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/BeansEditorTest.java
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/Bar.jav_
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/Foo.jav_
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/beans.xml
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/editor/
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/editor/BeansEditor.java
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/META-INF/MANIFEST.MF
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/actions/Action.java
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/CDIWizard.java
Log:
adding basic test for beans.xml editor
Added: trunk/cdi/tests/org.jboss.tools.cdi.bot.test/CDIAllBotTests.launch
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.bot.test/CDIAllBotTests.launch
(rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.bot.test/CDIAllBotTests.launch 2010-11-01 16:51:41
UTC (rev 26168)
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="no"?>
+<launchConfiguration
type="org.eclipse.swtbot.eclipse.ui.launcher.JunitLaunchConfig">
+<booleanAttribute key="append.args" value="true"/>
+<booleanAttribute key="askclear" value="false"/>
+<booleanAttribute key="automaticAdd" value="true"/>
+<booleanAttribute key="automaticValidate" value="false"/>
+<stringAttribute key="bootstrap" value=""/>
+<stringAttribute key="checked" value="[NONE]"/>
+<booleanAttribute key="clearConfig" value="true"/>
+<booleanAttribute key="clearws" value="true"/>
+<booleanAttribute key="clearwslog" value="false"/>
+<stringAttribute key="configLocation"
value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
+<booleanAttribute key="default" value="true"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<stringAttribute key="location"
value="${workspace_loc}/../junit-workspace"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry
value="/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/CDIAllBotTests.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<mapAttribute key="org.eclipse.debug.core.environmentVariables">
+<mapEntry key="DISPLAY" value=":1"/>
+</mapAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER"
value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR"
value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME"
value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND"
value="org.eclipse.jdt.junit.loader.junit4"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER"
value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE"
value="org.jboss.tools.cdi.bot.test.CDIAllBotTests"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS"
value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}
-consoleLog"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR"
value="org.jboss.tools.cdi.bot.test"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER"
value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS"
value="-Dosgi.requiredJavaVersion=1.5 -XX:MaxPermSize=256m -Xms256m -Xmx512m
-Dswtbot.test.properties.file=${env_var:HOME}/swtbot.properties
-Dusage_reporting_enabled=false"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<stringAttribute key="product"
value="org.eclipse.platform.ide"/>
+<booleanAttribute key="show_selected_only" value="false"/>
+<stringAttribute key="templateConfig"
value="${target_home}/configuration/config.ini"/>
+<booleanAttribute key="tracing" value="false"/>
+<booleanAttribute key="useCustomFeatures" value="false"/>
+<booleanAttribute key="useDefaultConfig" value="true"/>
+<booleanAttribute key="useDefaultConfigArea" value="false"/>
+<booleanAttribute key="useProduct" value="true"/>
+</launchConfiguration>
Modified: trunk/cdi/tests/org.jboss.tools.cdi.bot.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.bot.test/META-INF/MANIFEST.MF 2010-11-01 16:40:15
UTC (rev 26167)
+++ trunk/cdi/tests/org.jboss.tools.cdi.bot.test/META-INF/MANIFEST.MF 2010-11-01 16:51:41
UTC (rev 26168)
@@ -14,6 +14,7 @@
org.junit4;bundle-version="4.8.1",
org.apache.log4j;bundle-version="1.2.15",
org.eclipse.ui;bundle-version="3.6.0",
- org.jboss.tools.ui.bot.ext;bundle-version="3.2.0"
+ org.jboss.tools.ui.bot.ext;bundle-version="3.2.0",
+ org.eclipse.core.resources;bundle-version="3.6.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Added:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/CDIAllBotTests.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/CDIAllBotTests.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/CDIAllBotTests.java 2010-11-01
16:51:41 UTC (rev 26168)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.bot.test;
+
+import java.util.logging.Logger;
+
+import org.jboss.tools.cdi.bot.test.editor.BeansEditorTest;
+import org.jboss.tools.cdi.bot.test.wizard.CdiATWizardTest;
+import org.jboss.tools.ui.bot.ext.RequirementAwareSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * System properties:
+ * -Dswtbot.test.properties.file=$PATH
+ * -Dusage_reporting_enabled=$BOOLEAN
+ *
+ * Suite duration: aprox. 3min
+ *
+ * @author Lukas Jungmann
+ */
+(a)RunWith(RequirementAwareSuite.class)
+@SuiteClasses({
+ CdiATWizardTest.class,
+ BeansEditorTest.class})
+public class CDIAllBotTests {
+}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/BeansEditorTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/BeansEditorTest.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/BeansEditorTest.java 2010-11-01
16:51:41 UTC (rev 26168)
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.bot.test.editor;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.jboss.tools.cdi.bot.test.uiutils.editor.BeansEditor;
+import org.jboss.tools.cdi.bot.test.uiutils.editor.BeansEditor.Item;
+import org.jboss.tools.ui.bot.ext.RequirementAwareSuite;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.config.Annotations.SWTBotTestRequires;
+import org.jboss.tools.ui.bot.ext.config.Annotations.Server;
+import org.jboss.tools.ui.bot.ext.config.Annotations.ServerState;
+import org.jboss.tools.ui.bot.ext.view.ProjectExplorer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Lukas Jungmann
+ */
+@SWTBotTestRequires(clearProjects = false, perspective = "Java EE", server =
@Server(state = ServerState.NotRunning, version = "6.0", operator =
">="))
+(a)RunWith(RequirementAwareSuite.class)
+@SuiteClasses({ BeansEditorTest.class })
+public class BeansEditorTest extends SWTTestExt {
+
+ private static final String descPath = "WebContent/WEB-INF/beans.xml";
+ private static final String project = "CDIProject";
+ private static final Logger LOGGER = Logger.getLogger(BeansEditorTest.class.getName());
+
+ @BeforeClass
+ public static void prepare() {
+ copyResource("resources/beans.xml", descPath);
+ copyResource("resources/Foo.jav_", "src/cdi/Foo.java");
+ copyResource("resources/Bar.jav_", "src/cdi/Bar.java");
+ }
+
+ @Before
+ public void setup() {
+ new ProjectExplorer().openFile(project, descPath.split("/"));
+ }
+
+ @Test
+ public void testInterceptors() {
+ addItem(Item.INTERCEPTOR, "cdi.I1");
+ removeItem(Item.INTERCEPTOR, "cdi.I1");
+ addItem(Item.INTERCEPTOR, "cdi.I2");
+ }
+
+ @Test
+ public void testDecorators() {
+ addItem(Item.DECORATOR, "cdi.MapDecorator");
+ addItem(Item.DECORATOR, "cdi.ComparableDecorator");
+ removeItem(Item.DECORATOR, "cdi.ComparableDecorator");
+ }
+
+ @Test
+ public void testClasses() {
+ addItem(Item.CLASS, "cdi.Foo");
+ addItem(Item.CLASS, "cdi.Bar");
+ removeItem(Item.CLASS, "cdi.Foo");
+ }
+
+ @Test
+ public void testStereotypes() {
+ addItem(Item.STEREOTYPE, "cdi.S2");
+ addItem(Item.STEREOTYPE, "cdi.S3");
+ removeItem(Item.STEREOTYPE, "cdi.S3");
+ addItem(Item.STEREOTYPE, "cdi.S1");
+ removeItem(Item.STEREOTYPE, "cdi.S2");
+ }
+
+ @Test
+ public void testResult() {
+ SWTBotEditor editor = new SWTWorkbenchBot().activeEditor();
+ BeansEditor be = new BeansEditor(editor.getReference(), new SWTWorkbenchBot());
+ be.activatePage("Source");
+ String text = be.toTextEditor().getText();
+ List<Node> nl = getItems(text, Item.INTERCEPTOR);
+ assertEquals(1, nl.size());
+ assertTrue(containsItem(nl, "cdi.I2"));
+
+ nl = getItems(text, Item.DECORATOR);
+ assertEquals(1, nl.size());
+ assertTrue(containsItem(nl, "cdi.MapDecorator"));
+
+ nl = getItems(text, Item.CLASS);
+ assertEquals(1, nl.size());
+ assertTrue(containsItem(nl, "cdi.Bar"));
+
+ nl = getItems(text, Item.STEREOTYPE);
+ assertEquals(1, nl.size());
+ assertTrue(containsItem(nl, "cdi.S1"));
+ }
+
+ private void addItem(Item item, String name) {
+ SWTBotEditor editor = new SWTWorkbenchBot().activeEditor();
+ BeansEditor be = new BeansEditor(editor.getReference(), new SWTWorkbenchBot());
+ be.activatePage("Tree");
+ try {
+ be.add(item, name);
+ Assert.assertTrue(be.isDirty());
+ be.activatePage("Source");
+ String text = be.toTextEditor().getText();
+ List<Node> nl = getItems(text, item);
+ assertTrue(containsItem(nl, name));
+ } finally {
+ if (be.isDirty()) {
+ be.save();
+ }
+ }
+ }
+
+ private void removeItem(Item item, String name) {
+ SWTBotEditor editor = new SWTWorkbenchBot().activeEditor();
+ BeansEditor be = new BeansEditor(editor.getReference(), new SWTWorkbenchBot());
+ be.activatePage("Tree");
+ try {
+ be.remove(item, name);
+ Assert.assertTrue(be.isDirty());
+ be.activatePage("Source");
+ String text = be.toTextEditor().getText();
+ List<Node> nl = getItems(text, item);
+ assertFalse(containsItem(nl, name));
+ } finally {
+ if (be.isDirty()) {
+ be.save();
+ }
+ }
+ }
+
+ private Document getDocument(String text) {
+ Document d = null;
+ try {
+ d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new
ByteArrayInputStream(text.getBytes()));
+ } catch (SAXException e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ } catch (IOException e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ } catch (ParserConfigurationException e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ }
+ return d;
+ }
+
+ private List<Node> getItems(String doc, Item i) {
+ Document d = getDocument(doc);
+ NodeList nl = null;
+ switch (i) {
+ case DECORATOR:
+ nl = d.getElementsByTagName("decorators");
+ break;
+ case INTERCEPTOR:
+ nl = d.getElementsByTagName("interceptors");
+ break;
+ case STEREOTYPE:
+ return getNodes(d.getElementsByTagName("stereotype"), i);
+ case CLASS:
+ nl = d.getElementsByTagName("alternatives");
+ break;
+ }
+ return nl.getLength() > 0 ? getNodes(nl.item(0).getChildNodes(), i) : new
ArrayList<Node>();
+ }
+
+ private List<Node> getNodes(NodeList nl, Item item) {
+ List<Node> list = new ArrayList<Node>();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node n = nl.item(i);
+ if (item == Item.STEREOTYPE) {
+ if ("stereotype".equals(n.getNodeName())) {
+ list.add(n);
+ }
+ } else {
+ if ("class".equals(n.getNodeName())) {
+ list.add(n);
+ }
+ }
+ }
+ return list;
+ }
+
+ private boolean containsItem(List<Node> nl, String name) {
+ if (nl == null) {
+ return false;
+ }
+ for (int i = 0; i < nl.size(); i++) {
+ if (name.equals(nl.get(i).getTextContent())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static void copyResource(String src, String target) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProjects()[0];
+ IFile f = project.getFile(target);
+ if (f.exists()) {
+ LOGGER.info("Replacing " + target + " file");
+ try {
+ f.delete(true, new NullProgressMonitor());
+ } catch (CoreException ce) {
+ LOGGER.log(Level.WARNING, ce.getMessage(), ce);
+ }
+ }
+ InputStream is = null;
+ try {
+ is = BeansEditorTest.class.getResourceAsStream(src);
+ f.create(is, true, new NullProgressMonitor());
+ } catch (CoreException ce) {
+ LOGGER.log(Level.WARNING, ce.getMessage(), ce);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException ioe) {
+ //ignore
+ }
+ }
+ }
+ }
+}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/Bar.jav_
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/Bar.jav_
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/Bar.jav_ 2010-11-01
16:51:41 UTC (rev 26168)
@@ -0,0 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package cdi;
+
+public class Bar {}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/Foo.jav_
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/Foo.jav_
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/Foo.jav_ 2010-11-01
16:51:41 UTC (rev 26168)
@@ -0,0 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package cdi;
+
+public class Foo {}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/beans.xml
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/beans.xml
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/editor/resources/beans.xml 2010-11-01
16:51:41 UTC (rev 26168)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!--
+******************************************************************************
+Copyright (c) 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
+
+Contributors:
+Red Hat, Inc. - initial API and implementation
+******************************************************************************
+-->
+<beans
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://jboss.org/schema/cdi/beans_1_0.xsd"/>
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/actions/Action.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/actions/Action.java 2010-11-01
16:40:15 UTC (rev 26167)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/actions/Action.java 2010-11-01
16:51:41 UTC (rev 26168)
@@ -15,40 +15,48 @@
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
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.helper.ContextMenuHelper;
public abstract class Action<T> {
private final SWTBotExt bot = new SWTBotExt();
- private final String[] path;
+ private final String[] actionPath;
+ private final String[] nodePath;
+ private final SWTBotTree tree;
public Action(String... path) {
- assert path.length > 0;
- this.path = path;
+ this(null, null, path);
}
+
+ public Action(SWTBotTree tree, String[] nodePath, String... actionPath) {
+ assert actionPath.length > 0;
+ this.tree = tree;
+ this.nodePath = nodePath;
+ this.actionPath = actionPath;
+ }
public abstract T run();
protected SWTBot performMenu() {
- SWTBotMenu m = bot.menu(path[0]);
- for (int i = 1; i < path.length; i++) {
- m = m.menu(path[i]);
+ SWTBotMenu m = bot.menu(actionPath[0]);
+ for (int i = 1; i < actionPath.length; i++) {
+ m = m.menu(actionPath[i]);
}
m.click();
return new SWTBot();
}
- protected SWTBot pepformPopup(final SWTBotTree tree, SWTBotTreeItem item) {
- ContextMenuHelper.prepareTreeItemForContextMenu(tree, item);
+ protected SWTBot pepformPopup() {
+ assert tree != null : "Tree cannot be null!";
+ ContextMenuHelper.prepareTreeItemForContextMenu(tree, tree.expandNode(nodePath));
UIThreadRunnable.syncExec(new Result<SWTBotMenu>() {
public SWTBotMenu run() {
SWTBotMenu m = new SWTBotMenu(ContextMenuHelper.getContextMenu(
- tree, path[0], false));
- for (int i = 1; i < path.length; i++) {
- m = m.menu(path[i]);
+ tree, actionPath[0], false));
+ for (int i = 1; i < actionPath.length; i++) {
+ m = m.menu(actionPath[i]);
}
return m;
}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/editor/BeansEditor.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/editor/BeansEditor.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/editor/BeansEditor.java 2010-11-01
16:51:41 UTC (rev 26168)
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.bot.test.uiutils.editor;
+
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.ui.IEditorReference;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.widgets.SWTBotMultiPageEditor;
+
+/**
+ * @author Lukas Jungmann
+ */
+public class BeansEditor extends SWTBotMultiPageEditor {
+
+ public enum Item {
+ INTERCEPTOR("Interceptors"), DECORATOR("Decorators"),
+ CLASS("Alternatives"), STEREOTYPE("Alternatives");
+
+ private final String node;
+
+ private Item(String node) {
+ this.node = node;
+ }
+
+ private String getNode() {
+ return node;
+ }
+ }
+
+ private SWTBotExt bot = new SWTBotExt();
+ private static final String ROOT_NODE = "beans.xml";
+
+ public BeansEditor(IEditorReference editorReference, SWTWorkbenchBot bot) {
+ super(editorReference, bot);
+ }
+
+ public BeansEditor add(Item item, String name) {
+ return modify(item, name, "Add...", new AddDialogHandler(item, name));
+ }
+
+ public BeansEditor remove(Item item, String name) {
+ return modify(item, name, "Remove...", new DeleteDialogHandler());
+ }
+
+ private BeansEditor modify(Item item, String name, String actionLabel, DialogHandler h)
{
+ SWTBotTree tree = bot.tree();
+ tree.expandNode(ROOT_NODE, item.getNode()).select().click();
+ selectItem(item, name);
+ getItemButton(item, actionLabel).click();
+ h.handle(bot.activeShell());
+ bot.sleep(500);
+ this.setFocus();
+ return this;
+ }
+
+ private void selectItem(Item item, String name) {
+ SWTBotTable t = item == Item.STEREOTYPE ? bot.table(1) : bot.table(0);
+ if (t.containsItem(name)) {
+ t.select(name);
+ }
+ }
+
+ private SWTBotButton getItemButton(Item i, String label) {
+ return i == Item.STEREOTYPE ? bot.button(label, 1) : bot.button(label, 0);
+ }
+
+ private interface DialogHandler {
+ void handle(SWTBotShell dialog);
+ }
+
+ private class AddDialogHandler implements DialogHandler {
+
+ private final Item type;
+ private final String name;
+
+ public AddDialogHandler(Item type, String name) {
+ this.type = type;
+ this.name = name;
+ }
+
+ public void handle(SWTBotShell dialog) {
+ SWTBot sh = dialog.bot();
+ SWTBotText t = type == Item.STEREOTYPE
+ ? sh.textWithLabel("Stereotype:*")
+ : sh.textWithLabel("Class:*");
+ t.setText(name);
+ sh.button("Finish").click();
+ }
+ }
+
+ private class DeleteDialogHandler implements DialogHandler {
+
+ public void handle(SWTBotShell dialog) {
+ dialog.bot().button("OK").click();
+ }
+
+ }
+}
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/CDIWizard.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/CDIWizard.java 2010-11-01
16:40:15 UTC (rev 26167)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/CDIWizard.java 2010-11-01
16:51:41 UTC (rev 26168)
@@ -250,6 +250,7 @@
bot().button("Add...", 0).click();
SWTBotShell sh = bot().activeShell();
sh.bot().text().setText(intf);
+ sh.bot().sleep(1000);
sh.bot().table().getTableItem(0).select();
sh.bot().button("OK").click();
break;