tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [13/16] git commit: Change DocumentLinkerImplTest to use inline strings, not external files, to verify documents
Date Fri, 06 Jul 2012 00:38:01 GMT
Change DocumentLinkerImplTest to use inline strings, not external files, to verify documents


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/7fd8d997
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/7fd8d997
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/7fd8d997

Branch: refs/heads/5.4-js-rewrite
Commit: 7fd8d99793edd364b7b973916180d070b74de4e1
Parents: 1468399
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Thu Jul 5 10:46:28 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Thu Jul 5 10:46:28 2012 -0700

----------------------------------------------------------------------
 .../services/DocumentLinkerImplTest.groovy         |  126 ++++++++++++---
 .../tapestry5/internal/services/add_script.txt     |    4 -
 .../internal/services/add_script_links.txt         |    6 -
 .../internal/services/add_style_links.txt          |    2 -
 .../services/existing_head_used_if_present.txt     |    2 -
 .../services/ie_conditional_stylesheet.txt         |    5 -
 .../internal/services/immediate_initialization.txt |    5 -
 .../internal/services/include_generator_meta.txt   |    2 -
 .../services/module_based_initialization.txt       |   11 --
 .../internal/services/no_body_element.txt          |    3 -
 .../omit_generator_meta_on_no_html_root.txt        |    2 -
 .../internal/services/other_initialization.txt     |    7 -
 .../services/pretty_print_initialization.txt       |   21 ---
 .../internal/services/script_written_raw.txt       |    3 -
 .../services/stylesheet_insertion_point.txt        |    1 -
 15 files changed, 106 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
index 492e263..ce6b3fe 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
@@ -16,11 +16,12 @@ import org.testng.annotations.Test
 
 class DocumentLinkerImplTest extends InternalBaseTestCase {
 
-    def check(Document document, String file) throws Exception {
+    def check(Document document, String expectedContent) throws Exception {
 
-        def content = readFile(file)
+        // TestNG's assertEquals() is actually more useful here than Groovy's assert. Normally,
+        // it's the other way around.
 
-        assertEquals document.toString(), content
+        assertEquals document.toString(), expectedContent.trim()
     }
 
     @Test
@@ -64,7 +65,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         // Check that document is unchanged.
 
-        assert document.toString() == "<not-html>not an HTML document</not-html>"
+        check document, "<not-html>not an HTML document</not-html>"
 
         verify()
     }
@@ -99,7 +100,13 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check(document, "add_script_links.txt")
+        check document, '''
+<?xml version="1.0"?>
+<html><head/><body><p>Ready to be updated with scripts.</p><script
src="/js/require.js"/><script type="text/javascript">require.config();
+</script><script src="foo.js" type="text/javascript"/><script src="bar/baz.js"
type="text/javascript"/><script type="text/javascript">Tapestry.onDOMLoaded(function()
{
+pageInitialization();
+});
+</script></body></html>'''
 
         verify()
     }
@@ -117,7 +124,10 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check(document, "include_generator_meta.txt")
+        check document, '''
+<?xml version="1.0"?>
+<html><head><meta content="Apache Tapestry Framework (version 1.2.3)" name="generator"/></head><body><p>Ready
to be marked with generator meta.</p></body></html>
+'''
     }
 
     /**
@@ -133,7 +143,10 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check(document, "omit_generator_meta_on_no_html_root.txt")
+        check document, '''
+<?xml version="1.0"?>
+<no_html>Generator meta only added if root is html tag.</no_html>
+'''
     }
 
 
@@ -150,7 +163,10 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check(document, "add_style_links.txt")
+        check document, '''
+<?xml version="1.0"?>
+<html><head><link type="text/css" rel="stylesheet" href="foo.css"/><link
media="print" type="text/css" rel="stylesheet" href="bar/baz.css"/></head><body><p>Ready
to be updated with styles.</p></body></html>
+'''
     }
 
     @Test
@@ -166,7 +182,10 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check(document, "existing_head_used_if_present.txt")
+        check document, '''
+<?xml version="1.0"?>
+<html><head><!-- existing head --><link type="text/css" rel="stylesheet"
href="foo.css"/></head><body>body content</body></html>
+'''
     }
 
     @Test
@@ -184,7 +203,12 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check(document, "add_script.txt")
+        check document, '''
+<html><head></head><body><p>Ready to be updated with scripts.</p><script
src="/js/require.js"></script><script type="text/javascript">require.config();
+</script><script type="text/javascript">doSomething();
+doSomethingElse();
+</script></body></html>
+'''
 
         verify()
     }
@@ -204,7 +228,11 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check(document, "no_body_element.txt")
+        check document, '''
+<?xml version="1.0"?>
+<html><head/><notbody><p>Ready to be updated with scripts.</p></notbody><body><script/><script
type="text/javascript">require.config();
+</script><script src="foo.js" type="text/javascript"/></body></html>
+'''
     }
 
     @Test
@@ -221,7 +249,11 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check(document, "script_written_raw.txt")
+        check document, '''
+<html><head></head><body><p>Ready to be updated with scripts.</p><script
src="/js/require.js"></script><script type="text/javascript">require.config();
+</script><script type="text/javascript">for (var i = 0; i < 5; i++)  { doIt(i);
}
+</script></body></html>
+'''
 
         verify()
     }
@@ -263,7 +295,13 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        check document, "immediate_initialization.txt"
+        check document, '''
+<html><head><meta/><script></script></head><body><script
src="/js/require.js"></script><script type="text/javascript">require.config();
+</script><script type="text/javascript">require(["core/pageinit"], function (pageinit)
{
+  pageinit([["immediate/module:myfunc",{"fred":"barney"}]]);
+});
+</script></body></html>
+'''
 
         verify()
     }
@@ -286,7 +324,29 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        assertEquals(document.toString(), readFile("pretty_print_initialization.txt"))
+        check document, '''
+<html><head><meta/></head><body><script src="/js/require.js"></script><script
type="text/javascript">require.config();
+</script><script type="text/javascript">Tapestry.onDOMLoaded(function() {
+require(["core/pageinit"], function (pageinit) {
+  pageinit([[
+  "my/module"
+],
+  [
+  "my/other/module:normal",
+  111,
+  222
+]]);
+});
+require(["core/pageinit"], function (pageinit) {
+  pageinit([[
+  "my/other/module:late",
+  333,
+  444
+]]);
+});
+});
+</script></body></html>
+'''
     }
 
     @Test
@@ -306,8 +366,15 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        assertEquals(document.toString(), readFile("other_initialization.txt"))
-
+        check document, '''
+<html><head><meta/><script></script></head><body><script
src="/js/require.js"></script><script type="text/javascript">require.config();
+</script><script type="text/javascript">Tapestry.onDOMLoaded(function() {
+require(["core/pageinit"], function (pageinit) {
+  pageinit([["my/module","barney"]]);
+});
+});
+</script></body></html>
+'''
         verify()
     }
 
@@ -324,7 +391,13 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        assertEquals(document.toString(), readFile("ie_conditional_stylesheet.txt"))
+        check document, '''
+<html><head><link type="text/css" rel="stylesheet" href="everybody.css"/>
+<!--[if IE]>
+<link type="text/css" rel="stylesheet" href="just_ie.css"/>
+<![endif]-->
+</head></html>
+'''
     }
 
     @Test
@@ -340,7 +413,9 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        assertEquals(document.toString(), readFile("stylesheet_insertion_point.txt"))
+        check document, '''
+<html><head><link type="text/css" rel="stylesheet" href="whatever.css"/><link
type="text/css" rel="stylesheet t-ajax-insertion-point" href="insertion-point.css"/></head></html>
+'''
     }
 
     @Test
@@ -361,8 +436,19 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         linker.updateDocument(document)
 
-        assertEquals(document.toString(), readFile("module_based_initialization.txt"))
-
+        check document, '''
+<html><head><meta/></head><body><script src="/js/require.js"></script><script
type="text/javascript">require.config();
+</script><script type="text/javascript">Tapestry.onDOMLoaded(function() {
+require(["core/pageinit"], function (pageinit) {
+  pageinit([["my/module"],
+  ["my/other/module:normal",111,222]]);
+});
+require(["core/pageinit"], function (pageinit) {
+  pageinit([["my/other/module:late",333,444]]);
+});
+});
+</script></body></html>
+'''
     }
 
     private ModuleManager mockModuleManager() {

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script.txt
deleted file mode 100644
index 7c100ce..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-<html><head></head><body><p>Ready to be updated with scripts.</p><script
src="/js/require.js"></script><script type="text/javascript">require.config();
-</script><script type="text/javascript">doSomething();
-doSomethingElse();
-</script></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links.txt
deleted file mode 100644
index 7ae2813..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0"?>
-<html><head/><body><p>Ready to be updated with scripts.</p><script
src="/js/require.js"/><script type="text/javascript">require.config();
-</script><script src="foo.js" type="text/javascript"/><script src="bar/baz.js"
type="text/javascript"/><script type="text/javascript">Tapestry.onDOMLoaded(function()
{
-pageInitialization();
-});
-</script></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_style_links.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_style_links.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_style_links.txt
deleted file mode 100644
index 87ffb13..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_style_links.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version="1.0"?>
-<html><head><link type="text/css" rel="stylesheet" href="foo.css"/><link
media="print" type="text/css" rel="stylesheet" href="bar/baz.css"/></head><body><p>Ready
to be updated with styles.</p></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/existing_head_used_if_present.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/existing_head_used_if_present.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/existing_head_used_if_present.txt
deleted file mode 100644
index d9d27d3..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/existing_head_used_if_present.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version="1.0"?>
-<html><head><!-- existing head --><link type="text/css" rel="stylesheet"
href="foo.css"/></head><body>body content</body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt
deleted file mode 100644
index 762cf7a..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-<html><head><link type="text/css" rel="stylesheet" href="everybody.css"/>
-<!--[if IE]>
-<link type="text/css" rel="stylesheet" href="just_ie.css"/>
-<![endif]-->
-</head></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/immediate_initialization.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/immediate_initialization.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/immediate_initialization.txt
deleted file mode 100644
index 273f3ec..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/immediate_initialization.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-<html><head><meta/><script></script></head><body><script
src="/js/require.js"></script><script type="text/javascript">require.config();
-</script><script type="text/javascript">require(["core/pageinit"], function (pageinit)
{
-  pageinit([["immediate/module:myfunc",{"fred":"barney"}]]);
-});
-</script></body></html>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt
deleted file mode 100644
index 63b5bb0..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version="1.0"?>
-<html><head><meta content="Apache Tapestry Framework (version 1.2.3)" name="generator"/></head><body><p>Ready
to be marked with generator meta.</p></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/module_based_initialization.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/module_based_initialization.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/module_based_initialization.txt
deleted file mode 100644
index 524add0..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/module_based_initialization.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-<html><head><meta/></head><body><script src="/js/require.js"></script><script
type="text/javascript">require.config();
-</script><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-require(["core/pageinit"], function (pageinit) {
-  pageinit([["my/module"],
-  ["my/other/module:normal",111,222]]);
-});
-require(["core/pageinit"], function (pageinit) {
-  pageinit([["my/other/module:late",333,444]]);
-});
-});
-</script></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/no_body_element.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/no_body_element.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/no_body_element.txt
deleted file mode 100644
index 1490176..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/no_body_element.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-<?xml version="1.0"?>
-<html><head/><notbody><p>Ready to be updated with scripts.</p></notbody><body><script/><script
type="text/javascript">require.config();
-</script><script src="foo.js" type="text/javascript"/></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/omit_generator_meta_on_no_html_root.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/omit_generator_meta_on_no_html_root.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/omit_generator_meta_on_no_html_root.txt
deleted file mode 100644
index ad91c64..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/omit_generator_meta_on_no_html_root.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version="1.0"?>
-<no_html>Generator meta only added if root is html tag.</no_html>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/other_initialization.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/other_initialization.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/other_initialization.txt
deleted file mode 100644
index f6ad7d0..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/other_initialization.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-<html><head><meta/><script></script></head><body><script
src="/js/require.js"></script><script type="text/javascript">require.config();
-</script><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-require(["core/pageinit"], function (pageinit) {
-  pageinit([["my/module","barney"]]);
-});
-});
-</script></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/pretty_print_initialization.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/pretty_print_initialization.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/pretty_print_initialization.txt
deleted file mode 100644
index b339834..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/pretty_print_initialization.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-<html><head><meta/></head><body><script src="/js/require.js"></script><script
type="text/javascript">require.config();
-</script><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-require(["core/pageinit"], function (pageinit) {
-  pageinit([[
-  "my/module"
-],
-  [
-  "my/other/module:normal",
-  111,
-  222
-]]);
-});
-require(["core/pageinit"], function (pageinit) {
-  pageinit([[
-  "my/other/module:late",
-  333,
-  444
-]]);
-});
-});
-</script></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/script_written_raw.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/script_written_raw.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/script_written_raw.txt
deleted file mode 100644
index 1b9980b..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/script_written_raw.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-<html><head></head><body><p>Ready to be updated with scripts.</p><script
src="/js/require.js"></script><script type="text/javascript">require.config();
-</script><script type="text/javascript">for (var i = 0; i < 5; i++)  { doIt(i);
}
-</script></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7fd8d997/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/stylesheet_insertion_point.txt
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/stylesheet_insertion_point.txt
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/stylesheet_insertion_point.txt
deleted file mode 100644
index 87f0c40..0000000
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/stylesheet_insertion_point.txt
+++ /dev/null
@@ -1 +0,0 @@
-<html><head><link type="text/css" rel="stylesheet" href="whatever.css"/><link
type="text/css" rel="stylesheet t-ajax-insertion-point" href="insertion-point.css"/></head></html>
\ No newline at end of file


Mime
View raw message