Author: jgargula
Date: 2012-02-09 05:03:21 -0500 (Thu, 09 Feb 2012)
New Revision: 38537
Modified:
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsViewsTest.java
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/GuvnorRepositoriesTest.java
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/RuleFlowTest.java
Log:
Added workingMemoryTest to DroolsViewsTest and added support for deleting legacy guvnor
repository files
Modified:
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java
===================================================================
---
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java 2012-02-09
09:54:13 UTC (rev 38536)
+++
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/DroolsAllBotTests.java 2012-02-09
10:03:21 UTC (rev 38537)
@@ -28,6 +28,7 @@
import org.jboss.tools.ui.bot.ext.RequirementAwareSuite;
import org.jboss.tools.ui.bot.ext.SWTTestExt;
import org.jboss.tools.ui.bot.ext.SWTUtilExt;
+import org.jboss.tools.ui.bot.ext.config.TestConfigurator;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.jboss.tools.ui.bot.ext.types.PerspectiveType;
import org.junit.AfterClass;
@@ -160,8 +161,31 @@
}
eclipse.openPerspective(PerspectiveType.JAVA);
eclipse.maximizeActiveShell();
+
+ // Removes legacy files after previous run
+ final String serverHome = TestConfigurator.currentConfig.getServer().runtimeHome;
+ if (serverHome != null) {
+ deleteGuvnorRepositoryIfExists(serverHome + "/bin/");
+ }
}
+ private static void deleteGuvnorRepositoryIfExists(final String
pathToDirectoryWithRepository) {
+ delete(new File(pathToDirectoryWithRepository + "repository.xml"));
+ delete(new File(pathToDirectoryWithRepository + "repository"));
+ }
+
+ private static boolean delete(final File file) {
+ if (!file.exists()) {
+ return false;
+ }
+ if (file.isDirectory()) {
+ for (final String s : file.list()) {
+ delete(new File(file, s));
+ }
+ }
+ return file.delete();
+ }
+
public static boolean useExternalDroolsRuntime() {
return USE_EXTERNAL_DROOLS_RUNTIME;
}
Modified:
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsViewsTest.java
===================================================================
---
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsViewsTest.java 2012-02-09
09:54:13 UTC (rev 38536)
+++
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/DroolsViewsTest.java 2012-02-09
10:03:21 UTC (rev 38537)
@@ -5,11 +5,14 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+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.SWTOpenExt;
import org.jboss.tools.ui.bot.ext.SWTTestExt;
@@ -19,6 +22,7 @@
import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -28,7 +32,7 @@
*/
public class DroolsViewsTest extends SWTTestExt {
- private static final String PROJECT_NAME = "droolsTest";
+ private static final String PROJECT_NAME = "droolsViewsTest";
private static final String RULES_FILE = "Sample.drl";
private static final String RULES_FILE_PATH = "src/main/rules";
private static final String JAVA_FILE = "DroolsTest.java";
@@ -45,18 +49,20 @@
@Before
public void setUp() {
if (isFirstTimeRun) {
- eclipse.closeAllEditors();
+ eclipse.closeAllEditors();
manageProject();
setUpOnce();
}
SWTBotTreeItem javaTreeItem = packageExplorer.selectTreeItem(JAVA_FILE, new
String[] {PROJECT_NAME, JAVA_FILE_PATH, SAMPLE_TREE_NODE});
eclipse.debugTreeItemAsDroolsApplication(javaTreeItem);
- while (bot.waitForShell(IDELabel.Shell.PROGRESS_INFORMATION, 0) != null) {
- bot.sleep(Timing.time2S());
- }
+
if (isFirstTimeRun) {
eclipse.closeConfirmPerspectiveSwitchShellIfOpened(false, true);
+ } else {
+ while (bot.waitForShell(IDELabel.Shell.PROGRESS_INFORMATION, 0) != null) {
+ bot.sleep(Timing.time2S());
+ }
}
bot.sleep(Timing.time2S());
@@ -77,7 +83,7 @@
* and creates brand new project.
*/
private void manageProject() {
- packageExplorer.deleteAllProjects();
+ //packageExplorer.deleteAllProjects();
ManageDroolsProject.createDroolsProject(PROJECT_NAME);
Widget openingProjectWidget = null;
try {
@@ -102,6 +108,8 @@
public void tearDown() {
eclipse.closeView(IDELabel.View.AGENDA);
eclipse.closeView(IDELabel.View.GLOBAL_DATA);
+ eclipse.closeView(IDELabel.View.AUDIT);
+ eclipse.closeView(IDELabel.View.WORKING_MEMORY);
eclipse.finishDebug();
}
@@ -138,6 +146,7 @@
* Tests refreshing of Agenda view.
*/
@Test
+ @Ignore
public void refreshAgendaTest() {
openView(IDELabel.View.AGENDA);
eclipse.stepOver();
@@ -178,6 +187,99 @@
}
/**
+ * Test of Working Memory view
+ */
+ @Test
+ public void workingMemoryTest() {
+ openView(IDELabel.View.WORKING_MEMORY);
+
+ SWTBotTree workingMemoryTree = bot.tree();
+ assertEquals("Working memory tree was expected to have exactly 1 root item,
but it had "
+ + workingMemoryTree.getAllItems().length + " root items.", 1,
workingMemoryTree.getAllItems().length);
+
+ String rootItemText = workingMemoryTree.getAllItems()[0].getText();
+ assertNotNull(rootItemText);
+ assertTrue("Root item of working memory tree had unexpected text: " +
rootItemText,
+ rootItemText.contains("DroolsTest$Message"));
+
+ List<String> treeItemsStrings =
workingMemoryTree.expandNode(rootItemText).getNodes();
+ final int EXPECTED_ITEMS = 6;
+ assertEquals("There should be " + EXPECTED_ITEMS + " items but was
" + treeItemsStrings.size(),
+ EXPECTED_ITEMS, treeItemsStrings.size());
+
+ String messageString = "message= \"Goodbye cruel world\"";
+ String statusString = "status= 1";
+ String[] itemsStrings = new String[] {"BYE= 2", "FINISH=
3","GOODBYE= 1", "HELLO= 0", messageString, statusString};
+ Set<String> expectedWorkingMemorySet = new
HashSet<String>(EXPECTED_ITEMS);
+ for (int i = 0; i < itemsStrings.length; i++) {
+ expectedWorkingMemorySet.add(itemsStrings[i]);
+ }
+ assertEquals(expectedWorkingMemorySet, getWorkingMemoryItems(rootItemText));
+
+ eclipse.resumeDebug();
+ expectedWorkingMemorySet.remove(messageString);
+ expectedWorkingMemorySet.remove(statusString);
+ messageString = "message= \"JustBye rule\"";
+ statusString = "status= 3";
+ expectedWorkingMemorySet.add(messageString);
+ expectedWorkingMemorySet.add(statusString);
+ assertEquals(expectedWorkingMemorySet, getWorkingMemoryItems(rootItemText));
+
+ eclipse.resumeDebug();
+ expectedWorkingMemorySet.clear();
+ showView(IDELabel.View.CONSOLE);
+ showView(IDELabel.View.WORKING_MEMORY);
+ assertEquals("Working memory view should be empty. Maybe it was not
refreshed.",
+ expectedWorkingMemorySet, getWorkingMemoryItems(rootItemText));
+ }
+
+ /**
+ * Gets working memory items from Working Memory view.
+ *
+ * @param rootNode Root node name
+ * @return Set of strings representing working memory items.
+ */
+ private Set<String> getWorkingMemoryItems(final String rootNode) {
+ waitForStoppingDebugging();
+ showView(IDELabel.View.WORKING_MEMORY);
+ Set<String> stringSet = new HashSet<String>();
+
+ List<String> nodesStrings = null;
+ try {
+ nodesStrings = bot.tree().expandNode(rootNode).getNodes();
+ } catch (WidgetNotFoundException wnfe) {
+ return stringSet;
+ }
+
+ for (String s : nodesStrings) {
+ final int index = s.indexOf('(');
+ if (index > 0) {
+ s = s.substring(0, index);
+ }
+ stringSet.add(s.trim());
+ }
+
+ return stringSet;
+ }
+
+ /**
+ * Waits while debugging is stopped at breakpoint or finished.
+ */
+ private void waitForStoppingDebugging() {
+ for (int i = 0; i < 20; i++) {
+ SWTBotMenu resumeMenu =
bot.menu(IDELabel.Menu.RUN).menu(IDELabel.Menu.RESUME);
+ if (resumeMenu.isEnabled()) {
+ return;
+ }
+ SWTBotMenu terminateMenu =
bot.menu(IDELabel.Menu.RUN).menu(IDELabel.Menu.TERMINATE);
+ if (!resumeMenu.isEnabled() && !terminateMenu.isEnabled()) {
+ return;
+ }
+ bot.sleep(Timing.time1S());
+ }
+ }
+
+ /**
* Adds some pieces of code to DroolsTest.java
*/
private void adjustDroolsTestFile() {
@@ -252,10 +354,14 @@
private void showView(final String viewTitle) {
checkViewTitleNull(viewTitle);
boolean isViewOpened = false;
- for (SWTBotView view : bot.views()) {
+ for (final SWTBotView view : bot.views()) {
if (viewTitle.equals(view.getTitle())) {
- view.show();
- view.setFocus();
+ view.getWidget().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ view.show();
+ view.setFocus();
+ }
+ });
isViewOpened = true;
break;
}
Modified:
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/GuvnorRepositoriesTest.java
===================================================================
---
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/GuvnorRepositoriesTest.java 2012-02-09
09:54:13 UTC (rev 38536)
+++
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/GuvnorRepositoriesTest.java 2012-02-09
10:03:21 UTC (rev 38537)
@@ -31,6 +31,10 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.hamcrest.Matcher;
import org.jboss.tools.drools.ui.bot.test.DroolsAllBotTests;
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.SWTUtilExt;
+import org.jboss.tools.ui.bot.ext.Timing;
import org.jboss.tools.ui.bot.ext.config.Annotations.Require;
import org.jboss.tools.ui.bot.ext.config.Annotations.Server;
import org.jboss.tools.ui.bot.ext.config.Annotations.ServerState;
@@ -48,10 +52,6 @@
import org.jboss.tools.ui.bot.ext.types.JobName;
import org.jboss.tools.ui.bot.ext.types.PerspectiveType;
import org.jboss.tools.ui.bot.ext.view.GuvnorRepositories;
-import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
-import org.jboss.tools.ui.bot.ext.SWTTestExt;
-import org.jboss.tools.ui.bot.ext.SWTUtilExt;
-import org.jboss.tools.ui.bot.ext.Timing;
import org.junit.Test;
/**
* Tests Guvnor Repositories
@@ -131,6 +131,7 @@
assertTrue("Guvnor repository was not deleted properly",
guvnorRepositoriesBot.tree().rowCount() == 0);
}
+
/**
* Opens Guvnor Console
*/
Modified:
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/RuleFlowTest.java
===================================================================
---
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/RuleFlowTest.java 2012-02-09
09:54:13 UTC (rev 38536)
+++
trunk/build/aggregate/bottests-site/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/RuleFlowTest.java 2012-02-09
10:03:21 UTC (rev 38537)
@@ -31,13 +31,16 @@
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.jboss.tools.drools.ui.bot.test.DroolsAllBotTests;
import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
+import org.jboss.tools.ui.bot.ext.SWTOpenExt;
import org.jboss.tools.ui.bot.ext.SWTTestExt;
import org.jboss.tools.ui.bot.ext.SWTUtilExt;
import org.jboss.tools.ui.bot.ext.Timing;
+import org.jboss.tools.ui.bot.ext.gen.ActionItem;
import org.jboss.tools.ui.bot.ext.helper.KeyboardHelper;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.jboss.tools.ui.bot.ext.types.ViewType;
@@ -68,15 +71,32 @@
private boolean isEditorMaximized = false;
- /**
- * Tests Rule Flow
- */
- @Test
- public void testRuleFlow() {
- runRuleFlowCheck(DroolsAllBotTests.RULE_FLOW_JAVA_TEST_FILE_NAME);
- ruleFlowEditorCheck(DroolsAllBotTests.RULE_FLOW_FILE_NAME);
- }
+ /**
+ * Tests Rule Flow
+ */
+ @Test
+ public void testRuleFlow() {
+ runRuleFlowCheck(DroolsAllBotTests.RULE_FLOW_JAVA_TEST_FILE_NAME);
+ ruleFlowEditorCheck(DroolsAllBotTests.RULE_FLOW_FILE_NAME);
+ }
+ /**
+ * Sets all drools flow nodes.
+ */
+ @SuppressWarnings("unused")
+ private void setAllDroolsFlowNodes() {
+ new
SWTOpenExt(bot).preferenceOpen(ActionItem.Preference.DroolsDroolsFlownodes.LABEL);
+ bot.waitForShell(IDELabel.Shell.PREFERENCES);
+ for (SWTBotCheckBox checkBox : bot.checkBoxes()) {
+ if (checkBox.isEnabled()) {
+ checkBox.select();
+ }
+ }
+ bot.button(IDELabel.Button.OK).click();
+ bot.waitForShell(IDELabel.Shell.WARNING);
+ bot.button(IDELabel.Button.OK).click();
+ }
+
/**
* Runs newly created Drools project and check result
* @param droolsProjectName