Revision: 628
          http://svn.sourceforge.net/jwebunit/?rev=628&view=rev
Author:   henryju
Date:     2006-11-27 07:42:10 -0800 (Mon, 27 Nov 2006)

Log Message:
-----------
Fix assertDownloadedFileEquals (now use a URL instead of File) to work with 
file inside a JAR (jar://bla.jar!foo.txt)
Fix dependency versions from previous releases (was 1.4-rc1, should be 
1.4-SNAPSHOT).

Modified Paths:
--------------
    branches/1.x/jwebunit-commons-tests/pom.xml
    
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NonHtmlContentTest.java
    branches/1.x/jwebunit-core/pom.xml
    
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
    branches/1.x/jwebunit-htmlunit-plugin/pom.xml
    branches/1.x/jwebunit-webtestcase-generator/src/main/javacc/Java1.5.jj

Modified: branches/1.x/jwebunit-commons-tests/pom.xml
===================================================================
--- branches/1.x/jwebunit-commons-tests/pom.xml 2006-11-27 11:13:19 UTC (rev 
627)
+++ branches/1.x/jwebunit-commons-tests/pom.xml 2006-11-27 15:42:10 UTC (rev 
628)
@@ -22,7 +22,7 @@
     <dependency>
       <groupId>net.sourceforge.jwebunit</groupId>
       <artifactId>jwebunit-core</artifactId>
-      <version>1.4-rc1</version>
+      <version>${pom.version}</version>
     </dependency>
     <dependency>
       <groupId>commons-fileupload</groupId>

Modified: 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NonHtmlContentTest.java
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NonHtmlContentTest.java
    2006-11-27 11:13:19 UTC (rev 627)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NonHtmlContentTest.java
    2006-11-27 15:42:10 UTC (rev 628)
@@ -4,7 +4,11 @@
  
******************************************************************************/
 package net.sourceforge.jwebunit.tests;
 
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 
 import junit.framework.Test;
@@ -39,12 +43,9 @@
         assertTextPresent("Hello\r\nWorld");
     }
 
-    public void testImageContent() {
+    public void testImageContent() throws IOException {
         beginAt("/image.png");
         saveAs(new File("C:\\test.png"));
-        URL url = this.getClass().getResource(
-                "/testcases/NonHtmlContentTest/image.png");
-        File img = new File(url.getPath());
-        assertDownloadedFileEquals(img);
+        
assertDownloadedFileEquals(this.getClass().getResource("/testcases/NonHtmlContentTest/image.png"));
     }
 }
\ No newline at end of file

Modified: branches/1.x/jwebunit-core/pom.xml
===================================================================
--- branches/1.x/jwebunit-core/pom.xml  2006-11-27 11:13:19 UTC (rev 627)
+++ branches/1.x/jwebunit-core/pom.xml  2006-11-27 15:42:10 UTC (rev 628)
@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
        <parent>
                <artifactId>jwebunit</artifactId>
                <groupId>net.sourceforge.jwebunit</groupId>
@@ -41,7 +43,7 @@
                                                        <tasks>
 
                                                                <!--
-                                                               Do nothing as 
we only want to create a new source folder.
+                                                                       Do 
nothing as we only want to create a new source folder.
                                                                -->
 
                                                        </tasks>
@@ -67,18 +69,28 @@
                                        </execution>
                                </executions>
                                <configuration>
-                                       
<mainClass>net.sourceforge.jwebunit.javacc.WebTestCaseGenerator</mainClass>
+                                       <mainClass>
+                                               
net.sourceforge.jwebunit.javacc.WebTestCaseGenerator
+                                       </mainClass>
                                        <arguments>
                                                
<argument>${basedir}/src/main/java</argument>
-                                               
<argument>${project.build.directory}/generated-sources/main/java</argument>
+                                               <argument>
+                                                       
${project.build.directory}/generated-sources/main/java
+                                               </argument>
                                        </arguments>
-                                       
<includePluginDependencies>true</includePluginDependencies>
-                                       
<includeProjectDependencies>false</includeProjectDependencies>
+                                       <includePluginDependencies>
+                                               true
+                                       </includePluginDependencies>
+                                       <includeProjectDependencies>
+                                               false
+                                       </includeProjectDependencies>
                                </configuration>
                                <dependencies>
-                                       <dependency>
+                                       <dependency>
                                                
<groupId>net.sourceforge.jwebunit</groupId>
-                                               
<artifactId>jwebunit-webtestcase-generator</artifactId>
+                                               <artifactId>
+                                                       
jwebunit-webtestcase-generator
+                                               </artifactId>
                                                <version>1.4-SNAPSHOT</version>
                                        </dependency>
                                </dependencies>

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
      2006-11-27 11:13:19 UTC (rev 627)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
      2006-11-27 15:42:10 UTC (rev 628)
@@ -8,7 +8,9 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectInputStream;
 import java.io.PrintStream;
+import java.net.URL;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -1575,8 +1577,8 @@
      * @param frameNameOrId Name or ID of the frame. ID is checked first.
      */
     public void assertFramePresent(String frameNameOrId) {
-        Assert.assertTrue("Unable to locate frame with name or ID [" + 
frameNameOrId + "].",
-                getDialog().hasFrame(frameNameOrId));
+        Assert.assertTrue("Unable to locate frame with name or ID ["
+                + frameNameOrId + "].", getDialog().hasFrame(frameNameOrId));
     }
 
     /**
@@ -2049,13 +2051,18 @@
         getDialog().saveAs(f);
     }
 
-    public void assertDownloadedFileEquals(File expected) {
+    /**
+     * Download the current page (or file) and compare it with the given file.
+     * 
+     * @param expected Expected file URL.
+     */
+    public void assertDownloadedFileEquals(URL expected) {
         try {
             File tmp = File.createTempFile("jwebunit", null);
             tmp.deleteOnExit();
             saveAs(tmp);
             Assert.assertTrue("Files are not binary equals.", areFilesEqual(
-                    expected, tmp));
+                    expected, tmp.toURL()));
         } catch (IOException e) {
             e.printStackTrace();
             Assert.fail(e.toString());
@@ -2171,18 +2178,18 @@
      * Exemple: <br/>
      * 
      * <pre>
-     *                                        &lt;FORM 
action=&quot;http://my_host/doit&quot; method=&quot;post&quot;&gt;
-     *                                          &lt;P&gt;
-     *                                            &lt;SELECT multiple 
size=&quot;4&quot; name=&quot;component-select&quot;&gt;
-     *                                              &lt;OPTION selected 
value=&quot;Component_1_a&quot;&gt;Component_1&lt;/OPTION&gt;
-     *                                              &lt;OPTION selected 
value=&quot;Component_1_b&quot;&gt;Component_2&lt;/OPTION&gt;
-     *                                              
&lt;OPTION&gt;Component_3&lt;/OPTION&gt;
-     *                                              
&lt;OPTION&gt;Component_4&lt;/OPTION&gt;
-     *                                              
&lt;OPTION&gt;Component_5&lt;/OPTION&gt;
-     *                                            &lt;/SELECT&gt;
-     *                                            &lt;INPUT 
type=&quot;submit&quot; value=&quot;Send&quot;&gt;&lt;INPUT 
type=&quot;reset&quot;&gt;
-     *                                          &lt;/P&gt;
-     *                                        &lt;/FORM&gt;
+     *                                           &lt;FORM 
action=&quot;http://my_host/doit&quot; method=&quot;post&quot;&gt;
+     *                                             &lt;P&gt;
+     *                                               &lt;SELECT multiple 
size=&quot;4&quot; name=&quot;component-select&quot;&gt;
+     *                                                 &lt;OPTION selected 
value=&quot;Component_1_a&quot;&gt;Component_1&lt;/OPTION&gt;
+     *                                                 &lt;OPTION selected 
value=&quot;Component_1_b&quot;&gt;Component_2&lt;/OPTION&gt;
+     *                                                 
&lt;OPTION&gt;Component_3&lt;/OPTION&gt;
+     *                                                 
&lt;OPTION&gt;Component_4&lt;/OPTION&gt;
+     *                                                 
&lt;OPTION&gt;Component_5&lt;/OPTION&gt;
+     *                                               &lt;/SELECT&gt;
+     *                                               &lt;INPUT 
type=&quot;submit&quot; value=&quot;Send&quot;&gt;&lt;INPUT 
type=&quot;reset&quot;&gt;
+     *                                             &lt;/P&gt;
+     *                                           &lt;/FORM&gt;
      * </pre>
      * 
      * Should return [Component_1, Component_2, Component_3, Component_4, 
Component_5]
@@ -2354,23 +2361,25 @@
         }
     }
 
-    protected boolean areFilesEqual(File f1, File f2) throws IOException {
-        // compare file sizes
-        if (f1.length() != f2.length())
-            return false;
-
+    protected boolean areFilesEqual(URL f1, URL f2) throws IOException {
         // read and compare bytes pair-wise
-        InputStream i1 = new FileInputStream(f1);
-        InputStream i2 = new FileInputStream(f2);
+        InputStream i1 = f1.openStream();
+        InputStream i2 = f2.openStream();
+        if (f1 == null) {
+            throw new IOException(f1.toString() + " can't be opened.");
+        }
+        if (f2 == null) {
+            throw new IOException(f2.toString() + " can't be opened.");
+        }
         int b1, b2;
         do {
             b1 = i1.read();
             b2 = i2.read();
-        } while (b1 == b2 && b1 != -1);
+        } while (b1 == b2 && b1 != -1 && b2 != -1);
         i1.close();
         i2.close();
-        // true only if end of file is reached
-        return b1 == -1;
+        // true only if end of file is reached for both
+        return (b1 == -1) && (b2 == -1);
     }
 
 }

Modified: branches/1.x/jwebunit-htmlunit-plugin/pom.xml
===================================================================
--- branches/1.x/jwebunit-htmlunit-plugin/pom.xml       2006-11-27 11:13:19 UTC 
(rev 627)
+++ branches/1.x/jwebunit-htmlunit-plugin/pom.xml       2006-11-27 15:42:10 UTC 
(rev 628)
@@ -40,12 +40,12 @@
         <dependency>
             <groupId>net.sourceforge.jwebunit</groupId>
             <artifactId>jwebunit-core</artifactId>
-            <version>1.4-rc1</version>
+            <version>${pom.version}</version>
         </dependency>
         <dependency>
             <groupId>net.sourceforge.jwebunit</groupId>
             <artifactId>jwebunit-commons-tests</artifactId>
-            <version>1.4-rc1</version>
+            <version>${pom.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>

Modified: branches/1.x/jwebunit-webtestcase-generator/src/main/javacc/Java1.5.jj
===================================================================
--- branches/1.x/jwebunit-webtestcase-generator/src/main/javacc/Java1.5.jj      
2006-11-27 11:13:19 UTC (rev 627)
+++ branches/1.x/jwebunit-webtestcase-generator/src/main/javacc/Java1.5.jj      
2006-11-27 15:42:10 UTC (rev 628)
@@ -488,7 +488,8 @@
   [ PackageDeclaration(sb) ]
 
   {sb.append("import java.io.File;\n");
-  sb.append("import java.io.PrintStream;\n\n");
+  sb.append("import java.io.PrintStream;\n");
+  sb.append("import java.net.URL;\n\n");
   sb.append("import net.sourceforge.jwebunit.api.IJWebUnitDialog;\n");
   sb.append("import net.sourceforge.jwebunit.html.Table;\n");
   sb.append("import net.sourceforge.jwebunit.util.TestContext;\n\n");


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to