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

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Mar 21 11:00:12 EDT 2012


Author: vpakan at redhat.com
Date: 2012-03-21 11:00:11 -0400 (Wed, 21 Mar 2012)
New Revision: 39710

Added:
   trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/ExternalEditingTest.java
Modified:
   trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/FileHelper.java
   trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java
Log:
Added tests ExternalEditingTest.

Modified: trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/FileHelper.java
===================================================================
--- trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/FileHelper.java	2012-03-21 14:53:37 UTC (rev 39709)
+++ trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/FileHelper.java	2012-03-21 15:00:11 UTC (rev 39710)
@@ -12,10 +12,12 @@
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
+import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -204,4 +206,16 @@
 		if (!dir.mkdirs())
 			throw new RuntimeException("Can not create dir " + dir);
 	}
+	/**
+	 * Modify file fileLocation to have content fileContent
+	 * @param fileLocation
+	 * @param fileContent
+	 * @throws IOException
+	 */
+	public static void modifyTextFile(String fileLocation, String fileContent) throws IOException{
+	  File file = new File(fileLocation);
+    BufferedWriter bwOutput = new BufferedWriter(new FileWriter(file));
+    bwOutput.write(fileContent);
+    bwOutput.close();
+	}
 }

Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java	2012-03-21 14:53:37 UTC (rev 39709)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java	2012-03-21 15:00:11 UTC (rev 39710)
@@ -14,6 +14,7 @@
 import org.jboss.tools.ui.bot.ext.RequirementAwareSuite;
 import org.jboss.tools.vpe.ui.bot.test.editor.BlockCommentTest;
 import org.jboss.tools.vpe.ui.bot.test.editor.EditingActionsTest;
+import org.jboss.tools.vpe.ui.bot.test.editor.ExternalEditingTest;
 import org.jboss.tools.vpe.ui.bot.test.editor.InsertActionsTest;
 import org.jboss.tools.vpe.ui.bot.test.editor.MinMaxPanesTest;
 import org.jboss.tools.vpe.ui.bot.test.editor.StylesOnThePageTest;
@@ -210,7 +211,8 @@
   SummaryTagTest.class,
   SelectTagTest.class,
   RichFacesComponentTest.class,
-  UnicodeCharacterDisplayingTest.class
+  UnicodeCharacterDisplayingTest.class,
+  ExternalEditingTest.class
 })
 public class VPEAllBotTests extends SWTBotTestCase{
 

Added: trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/ExternalEditingTest.java
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/ExternalEditingTest.java	                        (rev 0)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/ExternalEditingTest.java	2012-03-21 15:00:11 UTC (rev 39710)
@@ -0,0 +1,169 @@
+/*******************************************************************************
+
+ * Copyright (c) 2007-2010 Exadel, Inc. and 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:
+ *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.ui.bot.test.editor;
+
+import java.awt.event.KeyEvent;
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.Timing;
+import org.jboss.tools.ui.bot.ext.helper.FileHelper;
+import org.jboss.tools.ui.bot.ext.helper.KeyboardHelper;
+import org.jboss.tools.vpe.ui.bot.test.VPEAutoTestCase;
+/**
+ * Tests editing of web page via external editor  
+ * @author vlado pakan
+ *
+ */
+public class ExternalEditingTest extends VPEEditorTestCase {
+  
+  private SWTBotExt botExt = null;
+  
+  private SWTBotEclipseEditor jspEditor;
+  
+	public ExternalEditingTest() {
+		super();
+		botExt = new SWTBotExt();
+	}
+	@Override
+	public void setUp() throws Exception {
+	  super.setUp();
+    eclipse.maximizeActiveShell();
+    bot.closeAllEditors();
+	}
+	/**
+	 * Checks External Editing of web page when accepting External changes
+	 */
+	public void testAcceptExternalChanges(){
+	  final String acceptExtChangesPageName = "ExternalEditingTestAccept.jsp";
+    createJspPage(acceptExtChangesPageName);
+    jspEditor = botExt.editorByTitle(acceptExtChangesPageName).toTextEditor();
+    final String originalPageContent = "<%@ taglib uri=\"http://java.sun.com/jsf/html\" prefix=\"h\" %>\n" +
+        "<html>\n" +
+        "  <body>\n" +
+        "  </body>\n" +
+        "</html>";
+    jspEditor.setText(originalPageContent);
+    jspEditor.save();
+    // modify web page externally   
+    final String changedPageContent = "<%@ taglib uri=\"http://java.sun.com/jsf/html\" prefix=\"h\" %>\n" +
+        "<html>\n" +
+        "  <body>\n" +
+        "    !@#$%CHANGED_TEXT%$#@!\n" +
+        "  </body>\n" +
+        "</html>";
+    try {
+      FileHelper.modifyTextFile(getPageLocation(acceptExtChangesPageName),
+          changedPageContent);
+    } catch (IOException ioe) {
+      throw new RuntimeException(ioe);
+    }
+    new TypeKeyCodesThread(new int[] {KeyEvent.VK_ENTER})
+        .start();
+    jspEditor.setFocus();
+    String sourceText = jspEditor.getText();
+    assertTrue("VPE Source pane has to contain text\n" + changedPageContent +
+        "'\nbut it contains\n" +
+        sourceText,
+      sourceText.equals(changedPageContent));
+	}
+	@Override
+	protected void closeUnuseDialogs() {
+
+	}
+
+	@Override
+	protected boolean isUnuseDialogOpened() {
+		return false;
+	}
+  @Override
+  public void tearDown() throws Exception {
+    jspEditor.close();
+    super.tearDown();
+  } 
+  /**
+   * Returns absolute page pageName location
+   * @param pageName
+   * @return
+   */
+  private String getPageLocation (String pageName){
+    StringBuffer sbPageLocation = new StringBuffer("");
+    sbPageLocation.append(FileHelper.getProjectLocation(VPEAutoTestCase.JBT_TEST_PROJECT_NAME, botExt));
+    sbPageLocation.append(File.separator);
+    sbPageLocation.append("WebContent");
+    sbPageLocation.append(File.separator);
+    sbPageLocation.append("pages");
+    sbPageLocation.append(File.separator);
+    sbPageLocation.append(pageName);
+    return sbPageLocation.toString();
+  }
+  /**
+   * Checks External Editing of web page when deny External changes
+   */
+  public void testDenyExternalChanges(){
+    final String denyExtChangesPageName = "ExternalEditingTestDeny.jsp";
+    createJspPage(denyExtChangesPageName);
+    jspEditor = botExt.editorByTitle(denyExtChangesPageName).toTextEditor();
+    final String originalPageContent = "<%@ taglib uri=\"http://java.sun.com/jsf/html\" prefix=\"h\" %>\n" +
+        "<html>\n" +
+        "  <body>\n" +
+        "  </body>\n" +
+        "</html>";
+    jspEditor.setText(originalPageContent);
+    jspEditor.save();
+    // modify web page externally   
+    final String changedPageContent = "<%@ taglib uri=\"http://java.sun.com/jsf/html\" prefix=\"h\" %>\n" +
+        "<html>\n" +
+        "  <body>\n" +
+        "    !@#$%CHANGED_TEXT%$#@!\n" +
+        "  </body>\n" +
+        "</html>";
+    try {
+      FileHelper.modifyTextFile(getPageLocation(denyExtChangesPageName),
+          changedPageContent);
+    } catch (IOException ioe) {
+      throw new RuntimeException(ioe);
+    }
+    new TypeKeyCodesThread(new int[] {KeyEvent.VK_TAB,KeyEvent.VK_ENTER})
+        .start();
+    jspEditor.setFocus();
+    String sourceText = jspEditor.getText();
+    assertTrue("VPE Source pane has to contain text\n" + originalPageContent +
+        "'\nbut it contains\n" +
+        sourceText,
+      sourceText.equals(originalPageContent));
+  }
+  /**
+   * Thread closing dialog displayed when page is modified externally 
+   */
+  class TypeKeyCodesThread extends Thread {
+    private int[] keyCodes;
+    public TypeKeyCodesThread (int[] keyCodes){
+      super();
+      this.keyCodes = keyCodes;
+    }
+    public void run() {
+      try {
+        System.out.println("**-- start thread");
+        sleep(Timing.time5S());
+        for (int keyCode : keyCodes){
+          System.out.println("**--Type: " + keyCode);
+          KeyboardHelper.typeKeyCodeUsingAWT(keyCode);
+          sleep(Timing.time2S());
+        }
+      } catch (InterruptedException e) {
+      }
+    }
+  }
+}


Property changes on: trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/ExternalEditingTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list