incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1225461 - in /incubator/lcf/trunk: framework/core/src/test/java/org/apache/manifoldcf/core/tests/ framework/core/src/test/resource/org/apache/manifoldcf/core/tests/ tests/filesystem/src/test/java/org/apache/manifoldcf/filesystem_tests/
Date Thu, 29 Dec 2011 07:51:35 GMT
Author: kwright
Date: Thu Dec 29 07:51:34 2011
New Revision: 1225461

URL: http://svn.apache.org/viewvc?rev=1225461&view=rev
Log:
Add job save/delete logic to navigation test.  Part of CONNECTORS-339.

Modified:
    incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/HTMLTester.java
    incubator/lcf/trunk/framework/core/src/test/resource/org/apache/manifoldcf/core/tests/VirtualBrowser.py
    incubator/lcf/trunk/tests/filesystem/src/test/java/org/apache/manifoldcf/filesystem_tests/NavigationUI.java

Modified: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/HTMLTester.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/HTMLTester.java?rev=1225461&r1=1225460&r2=1225461&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/HTMLTester.java
(original)
+++ incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/HTMLTester.java
Thu Dec 29 07:51:34 2011
@@ -148,6 +148,7 @@ public class HTMLTester
     currentIndentLevel = 0;
     virtualBrowserVarName = getNextVariableName();
     
+    emitLine("import time");
     emitLine("import sys");
     emitLine("sys.path.append(\".\")");
     emitLine("import VirtualBrowser");
@@ -202,7 +203,53 @@ public class HTMLTester
       emitLine(variableName + " = None");
     return new StringDescription(variableName);
   }
+
+  /** Create a string description for use later in the test.
+  *@param values are the intended values of the string description, concatenated together.
+  *@return the string description.
+  */
+  public StringDescription createStringDescription(StringDescription[] values)
+    throws Exception
+  {
+    String variableName = getNextVariableName();
+    if (values.length == 0)
+      emitLine(variableName + " = " + quotePythonString(""));
+    else
+    {
+      StringBuilder sb = new StringBuilder(variableName);
+      sb.append(" = ");
+      for (int i = 0; i < values.length ; i++)
+      {
+        if (i > 0)
+          sb.append(" + ");
+        sb.append(values[i].getVarName());
+      }
+      emitLine(sb.toString());
+    }
+    return new StringDescription(variableName);
+  }
+
+  /** Print a value.
+  */
+  public void printValue(StringDescription value)
+    throws Exception
+  {
+    emitLine("print >> sys.stderr, "+value.getVarName());
+  }
+  
+  /** Begin a loop.
+  */
+  public Loop beginLoop(int maxSeconds)
+    throws Exception
+  {
+    String variableName = getNextVariableName();
+    emitLine(variableName+" = time.time() + "+maxSeconds);
+    emitLine("while True:");
+    currentIndentLevel++;
+    return new Loop(variableName);
+  }
   
+    
   /** Open virtual browser window, and send it to a specified URL.
   *@param url is the desired URL.
   *@return the window handle.  Use this whenever a window argument is required later.
@@ -281,6 +328,28 @@ public class HTMLTester
       this.windowVar = windowVar;
     }
     
+    /** Check if a pattern is present or not.
+    *@return a StringDescription that in fact describes a boolean condition; true if present.
+    */
+    public StringDescription isPresent(StringDescription regularExpression)
+      throws Exception
+    {
+      String varName = getNextVariableName();
+      emitLine(varName + " = "+windowVar+".is_present("+regularExpression.getVarName()+")");
+      return new StringDescription(varName);
+    }
+
+    /** Check if a pattern is present or not.
+    *@return a StringDescription that in fact describes a boolean condition; true if not
present.
+    */
+    public StringDescription isNotPresent(StringDescription regularExpression)
+      throws Exception
+    {
+      String varName = getNextVariableName();
+      emitLine(varName + " = not "+windowVar+".is_present("+regularExpression.getVarName()+")");
+      return new StringDescription(varName);
+    }
+    
     /** Look for a specific match in the current page data, and return the value of the specified
group.
     *@return a description of the string found.  This can be used later in other commands
to assess
     *  correctness of the page, or allow form data to be filled in.
@@ -350,6 +419,42 @@ public class HTMLTester
     }
   }
   
+  /** Loop object.
+  */
+  public class Loop
+  {
+    protected String loopVarName;
+    
+    public Loop(String loopVarName)
+    {
+      this.loopVarName = loopVarName;
+    }
+    
+    /** Break on condition being true.
+    */
+    public void breakWhenTrue(StringDescription condition)
+      throws Exception
+    {
+      emitLine("if "+condition.getVarName()+":");
+      currentIndentLevel++;
+      emitLine("break");
+      currentIndentLevel--;
+    }
+    
+    /** End the loop.
+    */
+    public void endLoop()
+      throws Exception
+    {
+      emitLine("time.sleep(1)");
+      emitLine("if time.time() >= "+loopVarName+":");
+      currentIndentLevel++;
+      emitLine("raise Exception('Loop timed out')");
+      currentIndentLevel--;
+      currentIndentLevel--;
+    }
+  }
+  
   /** Object representative of a virtual browser link.
   */
   public class Link

Modified: incubator/lcf/trunk/framework/core/src/test/resource/org/apache/manifoldcf/core/tests/VirtualBrowser.py
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/resource/org/apache/manifoldcf/core/tests/VirtualBrowser.py?rev=1225461&r1=1225460&r2=1225461&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/resource/org/apache/manifoldcf/core/tests/VirtualBrowser.py
(original)
+++ incubator/lcf/trunk/framework/core/src/test/resource/org/apache/manifoldcf/core/tests/VirtualBrowser.py
Thu Dec 29 07:51:34 2011
@@ -784,6 +784,12 @@ class VirtualWindow:
 
     # Public part of interface
 
+    # Look for pattern
+    def is_present( self, regular_expression ):
+        reobject = re.compile( regular_expression )
+        mo = reobject.search( self.data )
+        return mo != None
+
     # Look for a specific match in the page data, and return the value of the specified group
     def find_match( self, regular_expression, group=0 ):
         reobject = re.compile( regular_expression )

Modified: incubator/lcf/trunk/tests/filesystem/src/test/java/org/apache/manifoldcf/filesystem_tests/NavigationUI.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/tests/filesystem/src/test/java/org/apache/manifoldcf/filesystem_tests/NavigationUI.java?rev=1225461&r1=1225460&r2=1225461&view=diff
==============================================================================
--- incubator/lcf/trunk/tests/filesystem/src/test/java/org/apache/manifoldcf/filesystem_tests/NavigationUI.java
(original)
+++ incubator/lcf/trunk/tests/filesystem/src/test/java/org/apache/manifoldcf/filesystem_tests/NavigationUI.java
Thu Dec 29 07:51:34 2011
@@ -46,6 +46,7 @@ public class NavigationUI extends BaseUI
     HTMLTester.Selectbox selectbox;
     HTMLTester.Button button;
     HTMLTester.Radiobutton radiobutton;
+    HTMLTester.Loop loop;
     
     window = testerInstance.openMainWindow("http://localhost:8346/mcf-crawler-ui/index.jsp");
     
@@ -203,7 +204,7 @@ public class NavigationUI extends BaseUI
     // Add a record to the Paths list
     
     // MHL
-    /* Need a way of checking job status if we're going to save it and delete it, since it
happens in background.
+    
     // Save the job
     window = testerInstance.findWindow(null);
     button = window.findButton(testerInstance.createStringDescription("Save this job"));
@@ -211,11 +212,21 @@ public class NavigationUI extends BaseUI
 
     // Delete the job
     window = testerInstance.findWindow(null);
-    HTMLTester.StringDescription jobID = window.findMatch(testerInstance.createStringDescription("<!--jobid=(.*?)-->"),1);
+    HTMLTester.StringDescription jobID = window.findMatch(testerInstance.createStringDescription("<!--jobid=(.*?)-->"),0);
+    testerInstance.printValue(jobID);
     link = window.findLink(testerInstance.createStringDescription("Delete this job"));
     link.click();
-    */
     
+    // Wait for the job to go away
+    loop = testerInstance.beginLoop(120);
+    window = testerInstance.findWindow(null);
+    link = window.findLink(testerInstance.createStringDescription("Manage jobs"));
+    link.click();
+    window = testerInstance.findWindow(null);
+    HTMLTester.StringDescription isJobNotPresent = window.isNotPresent(jobID);
+    testerInstance.printValue(isJobNotPresent);
+    loop.breakWhenTrue(isJobNotPresent);
+    loop.endLoop();
     
     // Delete the authority connection
     window = testerInstance.findWindow(null);



Mime
View raw message