Author: jjankovi
Date: 2011-08-15 11:01:59 -0400 (Mon, 15 Aug 2011)
New Revision: 33926
Modified:
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/fix/CDIQuickFixTest.java
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/actions/CDIUtil.java
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/wizard/CdiATWizardTest.java
Log:
Added new cdi bot test and util methods
Modified:
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 2011-08-15
14:59:11 UTC (rev 33925)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/CDIAllBotTests.java 2011-08-15
15:01:59 UTC (rev 33926)
@@ -36,6 +36,7 @@
* Suite duration: aprox. 3min
*
* @author Lukas Jungmann
+ * @author Jaroslav Jankovic
*/
@RunWith(RequirementAwareSuite.class)
@SuiteClasses({
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/fix/CDIQuickFixTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/fix/CDIQuickFixTest.java 2011-08-15
14:59:11 UTC (rev 33925)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/fix/CDIQuickFixTest.java 2011-08-15
15:01:59 UTC (rev 33926)
@@ -1,12 +1,9 @@
package org.jboss.tools.cdi.bot.test.fix;
-import java.io.InputStream;
-import java.util.Scanner;
import java.util.logging.Logger;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
-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.jboss.tools.cdi.bot.test.CDIAllBotTests;
@@ -22,6 +19,8 @@
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.types.ViewType;
+import org.jboss.tools.ui.bot.ext.view.ProblemsView;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite.SuiteClasses;
@@ -37,47 +36,62 @@
@SuiteClasses({ CDIAllBotTests.class })
public class CDIQuickFixTest extends SWTTestExt {
- private static final Logger LOGGER = Logger.getLogger(CDIQuickFixTest.class
- .getName());
+ private static final Logger LOGGER = Logger.getLogger(CDIQuickFixTest.class.getName());
private static final String PROJECT_NAME = "CDIProject";
private static final String PACKAGE_NAME = "org.cdi.test";
private static final String BEAN_NAME = "B1";
+ @Before
+ public void setUp() {
+ eclipse.showView(ViewType.PROJECT_EXPLORER);
+ }
+
@Test
- public void testSerializableQF() {
+ public void testSerializableQF() {
new NewFileWizardAction().run()
.selectTemplate("Web", "Dynamic Web Project").next();
new DynamicWebProjectWizard().setProjectName(PROJECT_NAME).finish();
- util.waitForNonIgnoredJobs();
- SWTBot v = eclipse.showView(ViewType.PROJECT_EXPLORER);
- SWTBotTree tree = v.tree();
+ util.waitForNonIgnoredJobs();
+ SWTBotTree tree = bot.tree();
tree.setFocus();
+
assertTrue("Project " + PROJECT_NAME + " was not created
properly.",
SWTEclipseExt.treeContainsItemWithLabel(tree, PROJECT_NAME));
SWTBotTreeItem item = tree.getTreeItem(PROJECT_NAME);
item.expand();
- new CDIUtil().nodeContextMenu(tree, item, "Configure",
- "Add CDI (Context and Dependency Injection) support...")
- .click();
- bot.activeShell().bot().button("OK").click();
- util.waitForNonIgnoredJobs();
+
+ CDIUtil.addCDISupport(tree, item, bot, util);
+
new NewCDIFileWizard(CDIWizardType.BEAN).run().setPackage(PACKAGE_NAME)
.setName(BEAN_NAME).finish();
util.waitForNonIgnoredJobs();
SWTBotEditor ed = bot.editorByTitle(BEAN_NAME + ".java");
- SWTBotEclipseEditor st = ed.toTextEditor();
- st.selectRange(0, 0, st.getText().length());
- InputStream javasrc = CDIQuickFixTest.class
- .getResourceAsStream("/resources/cdi/" + BEAN_NAME +
".java.cdi");
- String code = readStream(javasrc);
- st.setText(code);
- ed.save();
+ assertNotNull("Bean: " + BEAN_NAME + " was not created properly.",
ed);
+
+ CDIUtil.copyResourceToClass(ed, CDIQuickFixTest.class
+ .getResourceAsStream("/resources/cdi/" + BEAN_NAME +
".java.cdi"), false);
assertContains("(a)SessionScoped",ed.toTextEditor().getText());
- }
-
- private String readStream(InputStream is) {
- return new Scanner(is).useDelimiter("\\A").next();
- }
+
+ SWTEclipseExt.showView(bot, ViewType.PROBLEMS);
+ bot.sleep(3 * TIME_1S);
+
+
+ SWTBotTreeItem[] warningTrees = ProblemsView.getFilteredWarningsTreeItems(bot,
"Managed bean B1 which",
+ "/" + PROJECT_NAME , BEAN_NAME + ".java", "CDI
Problem");
+
+ assertNotNull("Warnings node should contain the expected problem.",
warningTrees);
+ assertTrue("Warnings node should contain only one record instead of " +
warningTrees.length + " records.",
+ warningTrees.length == 1);
+
+ CDIUtil.resolveQuickFix(bot.tree(), warningTrees[0], bot, util);
+
+ SWTBotEclipseEditor eclEditor = ed.toTextEditor();
+ assertTrue("Quick fix does not resolve issue properly.",
+ eclEditor.getText().contains("import java.io.Serializable;"));
+ warningTrees = ProblemsView.getFilteredWarningsTreeItems(bot, "Managed bean B1
which",
+ "/" + PROJECT_NAME , BEAN_NAME + ".java", "CDI
Problem");
+ assertTrue("Warnings should not contain resolved problem.",
warningTrees.length == 0);
+ }
}
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/actions/CDIUtil.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/actions/CDIUtil.java 2011-08-15
14:59:11 UTC (rev 33925)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/actions/CDIUtil.java 2011-08-15
15:01:59 UTC (rev 33926)
@@ -1,15 +1,50 @@
package org.jboss.tools.cdi.bot.test.uiutils.actions;
+import java.io.InputStream;
+import java.util.Scanner;
+
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
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.SWTUtilExt;
import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
public class CDIUtil {
+
- public SWTBotMenu nodeContextMenu(final SWTBotTree tree,
+ public static void addCDISupport(final SWTBotTree tree, SWTBotTreeItem item, SWTBotExt
bot, SWTUtilExt util) {
+ nodeContextMenu(tree, item, "Configure",
+ "Add CDI (Context and Dependency Injection) support...")
+ .click();
+ bot.activeShell().bot().button("OK").click();
+ bot.sleep(2000);
+ util.waitForNonIgnoredJobs();
+ }
+
+ public static void resolveQuickFix(final SWTBotTree tree, SWTBotTreeItem item, SWTBotExt
bot, SWTUtilExt util) {
+ nodeContextMenu(bot.tree(), item, "Quick Fix")
+ .click();
+ bot.activeShell().bot().button("Finish").click();
+ bot.sleep(2000);
+ util.waitForNonIgnoredJobs();
+ }
+
+ public static void copyResourceToClass(SWTBotEditor classEdit,
+ InputStream resource, boolean closeEdit) {
+ SWTBotEclipseEditor st = classEdit.toTextEditor();
+ st.selectRange(0, 0, st.getText().length());
+ String code = readStream(resource);
+ st.setText(code);
+ classEdit.save();
+ if (closeEdit) classEdit.close();
+ }
+
+ public static SWTBotMenu nodeContextMenu(final SWTBotTree tree,
SWTBotTreeItem item, final String... menu) {
assert menu.length > 0;
ContextMenuHelper.prepareTreeItemForContextMenu(tree, item);
@@ -25,5 +60,11 @@
}
});
}
+
+ private static String readStream(InputStream is) {
+ // we don't care about performance in tests too much, so this should be
+ // OK
+ return new Scanner(is).useDelimiter("\\A").next();
+ }
}
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/wizard/CdiATWizardTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/wizard/CdiATWizardTest.java 2011-08-15
14:59:11 UTC (rev 33925)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/wizard/CdiATWizardTest.java 2011-08-15
15:01:59 UTC (rev 33926)
@@ -15,9 +15,6 @@
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.SWTBot;
-import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
-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.cdi.bot.test.uiutils.actions.CDIUtil;
@@ -32,7 +29,6 @@
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.helper.ContextMenuHelper;
import org.jboss.tools.ui.bot.ext.types.ViewType;
import org.junit.After;
import org.junit.Test;
@@ -65,13 +61,7 @@
SWTEclipseExt.treeContainsItemWithLabel(tree, PROJECT_NAME));
SWTBotTreeItem t = tree.getTreeItem(PROJECT_NAME);
t.expand();
-
- // Configure Add CDI Support...
-
- new CDIUtil().nodeContextMenu(tree, t, "Configure",
- "Add CDI (Context and Dependency Injection) support...").click();
- bot.activeShell().bot().button("OK").click();
- util.waitForNonIgnoredJobs();
+ CDIUtil.addCDISupport(tree, t, bot, util);
}
@Test