You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by bo...@apache.org on 2018/11/03 18:01:29 UTC
tapestry-5 git commit: Fix unit test broken by Selenium upgrade
Repository: tapestry-5
Updated Branches:
refs/heads/master 7cacb7c6a -> b323f47ad
Fix unit test broken by Selenium upgrade
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/b323f47a
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/b323f47a
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/b323f47a
Branch: refs/heads/master
Commit: b323f47adab5b6317884026bc5b1c7f8e7f92929
Parents: 7cacb7c
Author: Bob Harner <bo...@gmail.com>
Authored: Sat Nov 3 14:00:02 2018 -0400
Committer: Bob Harner <bo...@gmail.com>
Committed: Sat Nov 3 14:00:02 2018 -0400
----------------------------------------------------------------------
.../GroovyTapestryCoreTestCase.groovy | 13 -----
.../integration/appfolder/AppFolderTests.groovy | 9 ++--
.../integration/TapestryCoreTestCase.java | 52 ++++++++++++++++++++
.../tapestry5/integration/app1/AssetTests.java | 32 +-----------
4 files changed, 59 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b323f47a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/GroovyTapestryCoreTestCase.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/GroovyTapestryCoreTestCase.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/GroovyTapestryCoreTestCase.groovy
index 144d20f..2525194 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/GroovyTapestryCoreTestCase.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/GroovyTapestryCoreTestCase.groovy
@@ -1,19 +1,6 @@
package org.apache.tapestry5.integration
-import org.apache.tapestry5.test.TapestryRunnerConstants
-
class GroovyTapestryCoreTestCase extends TapestryCoreTestCase
{
- protected final assertDownloadedAsset(String assetURL, String path)
- {
-
- URL url = new URL(getBaseURL() + assetURL.substring(1))
-
- byte[] downloaded = url.bytes
-
- byte[] actual = new File(TapestryRunnerConstants.MODULE_BASE_DIR, path).bytes
-
- assertEquals downloaded, actual, "Contents of $path do not match"
- }
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b323f47a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy
index 0ee69ba..c2baaab 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy
@@ -53,11 +53,14 @@ class AppFolderTests extends GroovyTapestryCoreTestCase
{
openLinks "t5app/"
- // Ony one image on page
+ // there's only one image on page
String assetURL = getAttribute("//img/@src")
- assert assetURL.startsWith("/t5app/assets/")
+ // Selenium now adds unwanted port & host
+ String urlPath = new URL(assetURL).getPath();
- assertDownloadedAsset assetURL, "src/test/appfolder/images/t5-logo.png"
+ assert urlPath.startsWith("/t5app/assets/")
+
+ assertDownloadedAsset urlPath, "src/test/appfolder/images/t5-logo.png"
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b323f47a/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
index 1c3baa7..204f9ad 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
@@ -14,7 +14,17 @@
package org.apache.tapestry5.integration;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.file.Files;
+
+import org.apache.tapestry5.internal.TapestryInternalUtils;
import org.apache.tapestry5.test.SeleniumTestCase;
+import org.apache.tapestry5.test.TapestryRunnerConstants;
public abstract class TapestryCoreTestCase extends SeleniumTestCase
{
@@ -65,4 +75,46 @@ public abstract class TapestryCoreTestCase extends SeleniumTestCase
assertText("css=[data-container-type=alerts] .alert span", text);
}
+ /**
+ * Assert that asset at the given URL contains the exact same contents as the
+ * file at the given path.
+ * @param assetURL a root-relative (starting with "/") URL to an asset, such as
+ * "/t5app/assets/ctx/b492f3dd/images/t5-logo.png"
+ * @param path the path (relative to the module base directory) where the asset file exists, such
+ * as "src/test/appfolder/images/filename.ext"
+ * @throws IOException
+ * @since 5.5
+ */
+ protected final void assertDownloadedAsset(String assetURL, String path) throws IOException
+ {
+ URL url = new URL(getBaseURL() + assetURL.substring(1));
+
+ byte[] downloaded = getBytes(url);
+
+ File file = new File(TapestryRunnerConstants.MODULE_BASE_DIR, path);
+ byte[] actual = Files.readAllBytes(file.toPath());
+
+ assertEquals(downloaded, actual, "Asset contents differ at " + url + " and " + path);
+ }
+
+ /**
+ * Read (download) the content of this URL and return it as a byte[].
+ *
+ * @param url URL to read content from
+ * @return the byte[] from that URL
+ * @throws IOException if an IOException occurs.
+ */
+ private static byte[] getBytes(URL url) throws IOException {
+ InputStream is = new BufferedInputStream(url.openStream());
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ TapestryInternalUtils.copy(is, os);
+
+ os.close();
+ is.close();
+
+ return os.toByteArray();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b323f47a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java
index 40f148c..444a83e 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java
@@ -51,7 +51,7 @@ public class AssetTests extends App1TestCase
String assetURL = getAttribute(String.format("//img[@id='%s']/@src", id));
- compareDownloadedAsset(assetURL, localPath);
+ assertDownloadedAsset(assetURL, localPath);
}
// TAP5-1515
@@ -79,34 +79,4 @@ public class AssetTests extends App1TestCase
// used by tapestry testing code to know when the page is finished loading is never invoked.
assertTrue(isVisible("assetWithWrongChecksum"));
}
-
-
- private void compareDownloadedAsset(String assetURL, String localPath) throws Exception
- {
- // Strip off the leading slash
-
- URL url = new URL(getBaseURL() + assetURL.substring(1));
-
- byte[] downloaded = readContent(url);
-
- File local = new File(TapestryRunnerConstants.MODULE_BASE_DIR, localPath);
-
- byte[] actual = readContent(local.toURL());
-
- assertEquals(downloaded, actual);
- }
-
- private byte[] readContent(URL url) throws Exception
- {
- InputStream is = new BufferedInputStream(url.openStream());
-
- ByteArrayOutputStream os = new ByteArrayOutputStream();
-
- TapestryInternalUtils.copy(is, os);
-
- os.close();
- is.close();
-
- return os.toByteArray();
- }
}