[jbosstools-commits] JBoss Tools SVN: r22124 - in trunk: jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon May 17 11:29:00 EDT 2010


Author: vpakan at redhat.com
Date: 2010-05-17 11:28:59 -0400 (Mon, 17 May 2010)
New Revision: 22124

Modified:
   trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/GuvnorRepositoriesTest.java
   trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/OpenDroolsPerspective.java
   trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
   trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
   trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java
Log:
Extends Guvnor Tests.

Modified: trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/GuvnorRepositoriesTest.java
===================================================================
--- trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/GuvnorRepositoriesTest.java	2010-05-17 15:18:28 UTC (rev 22123)
+++ trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/GuvnorRepositoriesTest.java	2010-05-17 15:28:59 UTC (rev 22124)
@@ -11,21 +11,31 @@
 
 package org.jboss.tools.drools.ui.bot.test.smoke;
 
+import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
+
 import java.awt.event.KeyEvent;
+import java.util.List;
 
 import org.apache.log4j.Logger;
+import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 import org.eclipse.swtbot.swt.finder.SWTBot;
 import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
+import org.eclipse.swtbot.swt.finder.results.StringResult;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
 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.config.requirement.PrepareViews;
 import org.jboss.tools.ui.bot.ext.config.requirement.RequirementNotFulfilledException;
 import org.jboss.tools.ui.bot.ext.config.requirement.StartServer;
 import org.jboss.tools.ui.bot.ext.config.requirement.StopServer;
+import org.jboss.tools.ui.bot.ext.gen.ActionItem.View.GuvnorGuvnorResourceHistory;
 import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
 import org.jboss.tools.ui.bot.ext.helper.DragAndDropHelper;
 import org.jboss.tools.ui.bot.ext.helper.KeyboardHelper;
@@ -50,6 +60,7 @@
   private static final Logger log = Logger.getLogger(GuvnorRepositoriesTest.class);
   private static final String GUVNOR_TEST_FILE = "Dummy rule.drl";
   private static final String GUVNOR_REPOSITORY_IMPORT_TEST_FILE = "Underage.brl";
+  private static final String GUVNOR_REPOSITORY_HISTORY_TEST_FILE = "MortgageModel.model.drl";
   private GuvnorRepositories guvnorRepositories = new GuvnorRepositories(); 
   /**
    * Tests Guvnor Repositories
@@ -61,10 +72,12 @@
     deleteGuvnorRepository();
     addGuvnorRepository();
     openGuvnorConsole();
+    drillIntoFunctionalityCheck();
     browseGuvnorRepository(GuvnorRepositoriesTest.GUVNOR_TEST_FILE);
-    importFileFromGuvnorRepository(GuvnorRepositoriesTest.GUVNOR_TEST_FILE,
+    guvnorFunctionalityCheck(GuvnorRepositoriesTest.GUVNOR_TEST_FILE,
       DroolsAllBotTests.SAMPLE_DROOLS_RULE_NAME,
       GuvnorRepositoriesTest.GUVNOR_REPOSITORY_IMPORT_TEST_FILE);
+    repositoryHistoryCheck(GuvnorRepositoriesTest.GUVNOR_REPOSITORY_HISTORY_TEST_FILE);
     stopGuvnor();
   }
 
@@ -163,12 +176,12 @@
     } 
   }
   /**
-   * Imports file with fileName to Drools project
+   * Imports file with fileName to Drools project and check update and commit Guvnor functionality
    * @param fileName
    * @param sampleFileName
    * @param importFileName
    */
-  private void importFileFromGuvnorRepository(String fileName, String sampleFileName, String importFileName){
+  private void guvnorFunctionalityCheck(String fileName, String sampleFileName, String importFileName){
     eclipse.openPerspective(PerspectiveType.JAVA);
     guvnorRepositories.show().bot();
     SWTBotTreeItem tiGuvnorFile = guvnorRepositories.selectTreeItem(Timing.time3S(),fileName,
@@ -328,4 +341,168 @@
     assertTrue("File " + importFileName + " was not disconnected from Guvnor Repository.",
         tiImportRuleFile.getText().trim().equals(importFileName));    
   }
+  private void drillIntoFunctionalityCheck(){
+    SWTBotView guvnorReposioryView = guvnorRepositories.show();
+    guvnorRepositories.selectTreeItem(Timing.time2S(), IDELabel.GuvnorRepositories.PACKAGES_TREE_ITEM, 
+      new String[]{IDELabel.GuvnorRepositories.GUVNOR_REPOSITORY_ROOT_TREE_ITEM});
+    SWTUtilExt.getViewToolbarButtonWithTooltip(guvnorReposioryView,
+      IDELabel.GuvnorRepositories.GO_INTO_GUVNOR_REPOSITORY_TOOLTIP)
+        .click();
+    SWTBot guvnorRepositoryBot = guvnorReposioryView.bot();
+    SWTBotTree guvnorRepositoryTree = guvnorRepositoryBot.tree();
+    guvnorRepositoryBot.sleep(Timing.time3S());
+    assertTrue("Guvnor repository Go Into functionality doesn't work properly.\n" +
+      "Expected First Tree Item in Guvnor Repository is " + IDELabel.GuvnorRepositories.DEFAULT_PACKAGE_TREE_ITEM +
+      "\nBut it was " + guvnorRepositoryTree.getAllItems()[0].getText(),
+      IDELabel.GuvnorRepositories.DEFAULT_PACKAGE_TREE_ITEM.equals(guvnorRepositoryTree.getAllItems()[0].getText()));
+    
+    guvnorRepositories.selectTreeItem(Timing.time2S(), IDELabel.GuvnorRepositories.MORTGAGE_TREE_ITEM, 
+      null);
+    SWTUtilExt.getViewToolbarButtonWithTooltip(guvnorReposioryView,
+        IDELabel.GuvnorRepositories.GO_INTO_GUVNOR_REPOSITORY_TOOLTIP)
+          .click();
+    guvnorRepositoryBot.sleep(Timing.time3S());
+    assertTrue("Guvnor repository Go Into functionality doesn't work properly.\n" +
+      "Expected First Tree Item in Guvnor Repository is " + IDELabel.GuvnorRepositories.APPLICANTDSL_DSL_TREE_ITEM +
+      "\nBut it was " + guvnorRepositoryTree.getAllItems()[0].getText(),
+      IDELabel.GuvnorRepositories.APPLICANTDSL_DSL_TREE_ITEM.equals(guvnorRepositoryTree.getAllItems()[0].getText()));
+
+    SWTUtilExt.getViewToolbarButtonWithTooltip(guvnorReposioryView,
+        IDELabel.GuvnorRepositories.BACK_GUVNOR_REPOSITORY_TOOLTIP)
+          .click();
+    guvnorRepositoryBot.sleep(Timing.time3S());
+    assertTrue("Guvnor repository Back functionality doesn't work properly.\n" +
+      "Expected First Tree Item in Guvnor Repository is " + IDELabel.GuvnorRepositories.DEFAULT_PACKAGE_TREE_ITEM +
+      "\nBut it was " + guvnorRepositoryTree.getAllItems()[0].getText(),
+      IDELabel.GuvnorRepositories.DEFAULT_PACKAGE_TREE_ITEM.equals(guvnorRepositoryTree.getAllItems()[0].getText()));
+
+    SWTUtilExt.getViewToolbarButtonWithTooltip(guvnorReposioryView,
+        IDELabel.GuvnorRepositories.HOME_GUVNOR_REPOSITORY_TOOLTIP)
+          .click();
+    guvnorRepositoryBot.sleep(Timing.time3S());
+    assertTrue("Guvnor repository Home functionality doesn't work properly.\n" +
+      "Expected First Tree Item in Guvnor Repository is " + IDELabel.GuvnorRepositories.GUVNOR_REPOSITORY_ROOT_TREE_ITEM +
+      "\nBut it was " + guvnorRepositoryTree.getAllItems()[0].getText(),
+      IDELabel.GuvnorRepositories.GUVNOR_REPOSITORY_ROOT_TREE_ITEM.equals(guvnorRepositoryTree.getAllItems()[0].getText()));    
+  }
+  /**
+   * Check Repository History Functionality
+   * @param testFileName
+   */
+  private void repositoryHistoryCheck (String testFileName){
+    // Import File From Repository
+    eclipse.createNew(EntityType.RESOURCES_FROM_GUVNOR);
+    bot.button(IDELabel.Button.NEXT).click();
+    SWTEclipseExt.getTreeItemOnPath(
+      bot,
+      bot.tree(),
+      Timing.time3S(),
+      testFileName,
+      new String[] {
+        IDELabel.GuvnorRepositories.GUVNOR_REPOSITORY_ROOT_TREE_ITEM,
+        IDELabel.GuvnorRepositories.PACKAGES_TREE_ITEM,
+        IDELabel.GuvnorRepositories.MORTGAGE_TREE_ITEM }).select();
+    bot.button(IDELabel.Button.NEXT).click();
+    SWTEclipseExt.getTreeItemOnPath(bot,
+      bot.tree(),
+      Timing.time1S(),
+      "rules",
+      new String[] {DroolsAllBotTests.DROOLS_PROJECT_NAME,"src","main"}).select();
+    bot.button(IDELabel.Button.FINISH).click();
+    util.waitForJobs(Timing.time5S(),JobName.BUILDING_WS);
+    bot.sleep(Timing.time1S());
+    SWTBot packageExplorerBot = packageExplorer.show().bot();
+    SWTBotTree packageExplorerTree = packageExplorerBot.tree();
+    // File is renamed because there is appended Guvnor info to Tree Item Label
+    // So we need to get real label of Tree Item and use it later
+    SWTBotTreeItem tiTestRuleFile = SWTEclipseExt.getTreeItemOnPathStartsWith(packageExplorerBot, 
+      packageExplorerTree, 
+      Timing.time1S(),
+      testFileName, 
+      new String[]{DroolsAllBotTests.DROOLS_PROJECT_NAME,
+        DroolsAllBotTests.SRC_MAIN_RULES_TREE_NODE});
+    SWTBotEditor editor = packageExplorer.openFile(DroolsAllBotTests.DROOLS_PROJECT_NAME, 
+      DroolsAllBotTests.SRC_MAIN_RULES_TREE_NODE,
+      tiTestRuleFile.getText());
+    // change test file
+    String addedChange = "SWTBOT Change!@#$asdfghjkl)(*&^";
+    editor.toTextEditor().insertText(0,0,addedChange);
+    editor.save();
+    bot.sleep(Timing.time1S());
+    // commit changes
+    ContextMenuHelper.prepareTreeItemForContextMenu(packageExplorerTree, tiTestRuleFile);
+    ContextMenuHelper.clickContextMenu(packageExplorerTree,
+      IDELabel.Menu.GUVNOR,IDELabel.Menu.GUVNOR_COMMIT);
+    bot.sleep(Timing.time5S());
+    // check history
+    ContextMenuHelper.prepareTreeItemForContextMenu(packageExplorerTree, tiTestRuleFile);
+    ContextMenuHelper.clickContextMenu(packageExplorerTree,
+      IDELabel.Menu.GUVNOR,IDELabel.Menu.GUVNOR_SHOW_HISTORY);
+    bot.sleep(Timing.time5S());
+    SWTBotView guvnorResourceHistoryView = open.viewOpen(GuvnorGuvnorResourceHistory.LABEL);
+    SWTBot guvnorResourceHistoryBot = guvnorResourceHistoryView.bot();
+    SWTBotTable guvnorResourceHistoryTable = guvnorResourceHistoryView.bot().table();
+    assertTrue("Guvnor Resource History table for file " + testFileName +
+        " has to contain at least one record but is empty.",
+      guvnorResourceHistoryTable.rowCount() > 0);
+    // Compare Revisions
+    String secondAddedChange = "222222" + addedChange;
+    editor.toTextEditor().insertText(0,0,secondAddedChange);
+    editor.saveAndClose();
+    bot.sleep(Timing.time1S());
+    ContextMenuHelper.prepareTreeItemForContextMenu(packageExplorerTree, tiTestRuleFile);
+    ContextMenuHelper.clickContextMenu(packageExplorerTree,
+      IDELabel.Menu.GUVNOR,IDELabel.Menu.GUVNOR_COMPARE_WITH_VERSION);
+    eclipse.waitForShell("");
+    guvnorResourceHistoryBot.activeShell().bot().button(IDELabel.Button.OK).click();
+    SWTBotEditor compareEditor = bot.editorByTitle("Compare");
+    Matcher<StyledText> widgetOfTypeMatcher = WidgetMatcherFactory.widgetOfType(StyledText.class);
+    final List<?> styledTexts = compareEditor.bot().widgets(widgetOfTypeMatcher,compareEditor.getWidget());
+    String newVersionEditorText = syncExec(new StringResult() {
+      public String run() {
+        return ((StyledText)styledTexts.get(0)).getText();
+      }
+    });
+    String revisionEditorText = syncExec(new StringResult() {
+      public String run() {
+        return ((StyledText)styledTexts.get(1)).getText();
+      }
+    });
+    compareEditor.close();
+    assertTrue("Actual version of file opened within compare editor has wrong content.\n" +
+      "Content should start with " + secondAddedChange +
+      "\n but is " + newVersionEditorText,newVersionEditorText.startsWith(secondAddedChange));
+    assertTrue("File stored in Guvnor Repository opened within compare editor has wrong content.\n" +
+      "Content should start with " + addedChange +
+      "\n but is " + revisionEditorText,revisionEditorText.startsWith(addedChange));
+    // Open Revision
+    guvnorResourceHistoryView.show();
+    guvnorResourceHistoryTable.setFocus();
+    bot.sleep(Timing.time1S());
+    guvnorResourceHistoryTable.select(0);
+    bot.sleep(Timing.time1S());
+    KeyboardHelper.pressKeyCodeUsingAWT(KeyEvent.VK_ENTER);
+    KeyboardHelper.releaseKeyCodeUsingAWT(KeyEvent.VK_ENTER);
+    bot.sleep(Timing.time1S());
+    SWTBotEditor revisonFileEditor = eclipse.editorStartsWith(testFileName);
+    String revisionFileText = revisonFileEditor.toTextEditor().getText();
+    revisonFileEditor.close();
+    assertTrue("File stored in Guvnor Repository has wrong content.\n" +
+        "Content should start with " + addedChange +
+        "\n but is " + revisionFileText,revisionFileText.startsWith(addedChange));
+    // Switch to version
+    editor = packageExplorer.openFile(DroolsAllBotTests.DROOLS_PROJECT_NAME, 
+        DroolsAllBotTests.SRC_MAIN_RULES_TREE_NODE,
+        tiTestRuleFile.getText());
+    ContextMenuHelper.prepareTreeItemForContextMenu(packageExplorerTree, tiTestRuleFile);
+    ContextMenuHelper.clickContextMenu(packageExplorerTree,
+      IDELabel.Menu.GUVNOR,IDELabel.Menu.GUVNOR_SWITCH_TO_VERSION);
+    eclipse.waitForShell("");
+    guvnorResourceHistoryBot.activeShell().bot().button(IDELabel.Button.OK).click();
+    bot.sleep(Timing.time3S());
+    String editorText = editor.toTextEditor().getText();    
+    assertTrue("Switched version of file has wrong content.\n" +
+      "Content should start with " + addedChange +
+      "\n but is " + editorText,editorText.startsWith(addedChange));
+  }
 }
\ No newline at end of file

Modified: trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/OpenDroolsPerspective.java
===================================================================
--- trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/OpenDroolsPerspective.java	2010-05-17 15:18:28 UTC (rev 22123)
+++ trunk/drools/tests/org.jboss.tools.drools.ui.bot.test/src/org/jboss/tools/drools/ui/bot/test/smoke/OpenDroolsPerspective.java	2010-05-17 15:28:59 UTC (rev 22124)
@@ -26,7 +26,7 @@
    * Test Opening Drools Rules
    */
   @Test
-  public void testManageDroolsProject() {
+  public void testOpenDroolsPerspective() {
     openDroolsPerspective();
   }
   /**

Modified: trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
===================================================================
--- trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java	2010-05-17 15:18:28 UTC (rev 22123)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java	2010-05-17 15:28:59 UTC (rev 22124)
@@ -1124,7 +1124,28 @@
 		public void run() {
 			shell.setMaximized(true);
 			
-		}		
-	});
+	    }		
+    });
   }
+  /**
+   * Returns SWTBotEditor with title starting with prefix 
+   * @param prefix
+   * @return
+   */
+  public SWTBotEditor editorStartsWith (String prefix){
+    SWTBotEditor editor = null;
+    List<?> editors = bot.editors();
+    Iterator<?> iterator = editors.iterator();
+    boolean found = false;
+    while (iterator.hasNext() && !found){
+      editor = ((SWTBotEditor)iterator.next()); 
+      found = editor.getTitle().startsWith(prefix);
+    }
+    if (found){
+      return editor;
+    }
+    else{
+      return null;
+    }
+  }
 }
\ No newline at end of file

Modified: trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
===================================================================
--- trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java	2010-05-17 15:18:28 UTC (rev 22123)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java	2010-05-17 15:28:59 UTC (rev 22124)
@@ -72,6 +72,9 @@
     public static final String GUVNOR_ADD = "Add...";
     public static final String GUVNOR_DELETE = "Delete...";
     public static final String GUVNOR_DISCONNECT = "Disconnect";
+    public static final String GUVNOR_SHOW_HISTORY = "Show History";
+    public static final String GUVNOR_COMPARE_WITH_VERSION = "Compare with Version...";
+    public static final String GUVNOR_SWITCH_TO_VERSION = "Switch to Version...";
     public static final String NAVIGATION = "Navigation";
     public static final String MAXIMIZE_ACTIVE_VIEW_OR_EDITOR = "Maximize Active View or Editor";
 	}
@@ -188,6 +191,7 @@
 		public static final String PROBLEMS = "Problems";
 		public static final String DEBUG = "Debug";
 		public static final String GUVNOR_REPOSITORIES = "Guvnor Repositories";
+		public static final String GUVNOR_RESOURCE_HISTORY = "Guvnor Resource History";
 		public static final String PROPERTIES = "Properties";
 	}
 	
@@ -460,6 +464,11 @@
      public static final String GUVNOR_REPOSITORY_ROOT_TREE_ITEM = "http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/webdav";
      public static final String PACKAGES_TREE_ITEM = "packages/";
      public static final String MORTGAGE_TREE_ITEM = "mortgages/";
+     public static final String GO_INTO_GUVNOR_REPOSITORY_TOOLTIP = "Go Into";
+     public static final String BACK_GUVNOR_REPOSITORY_TOOLTIP = "Back";
+     public static final String HOME_GUVNOR_REPOSITORY_TOOLTIP = "Home";
+     public static final String DEFAULT_PACKAGE_TREE_ITEM = "defaultPackage/";
+     public static final String APPLICANTDSL_DSL_TREE_ITEM = "ApplicantDsl.dsl";
    }
    
    public static final class GuvnorConsole {

Modified: trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java
===================================================================
--- trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java	2010-05-17 15:18:28 UTC (rev 22123)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java	2010-05-17 15:28:59 UTC (rev 22124)
@@ -19,7 +19,8 @@
  */
 public enum ViewType {
 	PACKAGE_EXPLORER, PROJECT_EXPLORER, WELCOME, DATA_SOURCE_EXPLORER,
-	SERVERS,WEB_PROJECTS,PROBLEMS,DEBUG,GUVNOR_REPOSITORIES,PROPERTIES;
+	SERVERS,WEB_PROJECTS,PROBLEMS,DEBUG,GUVNOR_REPOSITORIES,PROPERTIES,
+	GUVNOR_RESOURCE_HISTORY;
 	
 	
 	public String getGroupLabel() {
@@ -34,6 +35,7 @@
 			case DEBUG: viewLabel = IDELabel.ViewGroup.DEBUG; break;
 			case GUVNOR_REPOSITORIES: viewLabel = IDELabel.ViewGroup.GUVNOR; break;
 			case PROPERTIES: viewLabel = IDELabel.ViewGroup.GENERAL; break;
+			case GUVNOR_RESOURCE_HISTORY: viewLabel = IDELabel.ViewGroup.GUVNOR; break;
 			default: fail("Unknown View Type");
 		}
 		return viewLabel;	
@@ -51,6 +53,7 @@
 			case DEBUG: viewLabel = IDELabel.View.DEBUG; break;
 			case GUVNOR_REPOSITORIES: viewLabel = IDELabel.View.GUVNOR_REPOSITORIES; break;
 			case PROPERTIES: viewLabel = IDELabel.View.PROPERTIES; break;
+			case GUVNOR_RESOURCE_HISTORY: viewLabel = IDELabel.View.GUVNOR_RESOURCE_HISTORY; break;
 			default: fail("Unknown View Type");
 		}
 		return viewLabel;



More information about the jbosstools-commits mailing list