-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 All,
[ At the request of Nathan Bubna, I am posting this to dev@velocity.apache.org instead of bothering him individually ;) ] Today, I have integrated the ImageSupport tests that I wrote into the unit tests that are (as we speak) being added into svn. Please find attached below my test case. It is a single file that belongs in src/test/org/apache/velocity/tools/test/whitebox. It relies on two additional libraries: 1. jmock (available at http://jmock.org/) 2. TestURLConnection (my own library, not attached as the list identifies my post as SPAM if I do that) Both of these JAR files need to go into test/lib in order to run the tests. A couple of notes: 1. My TestURLConnection library is looking for a good home. Any suggestions? I'm only providing the binary library which is probably a deal-breaker for velocity-tools -- I know -- but I was wondering if you know anyone in either jakarta-commons or an incubator project who might be interested in this. I'd be happy to provide you with the entire thing including source, docs, etc. 2. My test case does not run properly unless "fork" is set to true in the whitebox junit invocation. I'm not entirely sure why this is. Also, I have an inner class that <junit> wants to run like a test, and so that fails unless you change the fileset to be executed from ".../whitebox/**/*" to ".../whitebox/**/*Tests.class". I'd be happy to learn how to suppress testing on an inner class so that this doesn't cause a problem. 3. The "test.generic" ant target runs all whitebox testing and not just the generic tests (well, now that my test is included, it does). My test is definitely not a blackbox test, so I set it up under the white box tests. Perhaps you guys aren't ready for more tests and the method just needs to evolve as more tests are added. Just a thought. Let me know what you think. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFt+eL9CaO5/Lv0PARAtcjAKCyLd1hpJ+h35HD/NcYvzxtYxsptgCeL4nN gEu8P0VTyQ8tyYEw0aU2t9Q= =Ofs5 -----END PGP SIGNATURE-----
package org.apache.velocity.tools.test.whitebox; import java.util.Map; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import org.junit.Test; import org.junit.BeforeClass; import junit.framework.Assert; import junit.framework.TestCase; import org.jmock.Mock; import org.jmock.MockObjectTestCase; import org.apache.velocity.tools.view.ImportSupport; import org.apache.velocity.tools.test.loopback.Handler; import net.christopherschultz.testurl.HttpURLConnection; import net.christopherschultz.testurl.URLConnectionRegistry; public class ImportSupportTests extends MockObjectTestCase { // Need a concrete class; must be public else junit complains public static class ImportSupportImpl extends ImportSupport { public String acquireString(String url) throws IOException, Exception { return super.acquireString(url); } public Reader acquireReader(String url) throws IOException, Exception { return super.acquireReader(url); } } private ImportSupportImpl is = new ImportSupportImpl(); public @BeforeClass void setUp() { URLConnectionRegistry.clear(); URLConnectionRegistry.registerURLStreamHandler(); } public @Test void testAcquireString() throws Exception { String response = "<html><h1>Test\u1234Content</h1></html>"; java.io.ByteArrayInputStream data = new java.io.ByteArrayInputStream(response.getBytes("UTF-8")); Mock m_conn = new Mock(HttpURLConnection.class); m_conn.expects(once()).method("getInputStream").will(returnValue(data)); m_conn.expects(once()).method("getResponseCode").will(returnValue(200)); m_conn.expects(once()).method("getContentType").will(returnValue("text/html; charset=UTF-8")); m_conn.expects(once()).method("disconnect"); URLConnectionRegistry.register("test/url", (HttpURLConnection)m_conn.proxy()); // Make the request String content = is.acquireString("testurl:test/url"); Assert.assertEquals(response, content); m_conn.verify(); } public @Test void testAcquireReader() throws Exception { String response = "<html><h1>Test\u1234Content</h1></html>"; java.io.ByteArrayInputStream data = new java.io.ByteArrayInputStream(response.getBytes("UTF-8")); Mock m_conn = new Mock(HttpURLConnection.class); m_conn.expects(once()).method("getInputStream").will(returnValue(data)); m_conn.expects(once()).method("getResponseCode").will(returnValue(200)); m_conn.expects(once()).method("getContentType").will(returnValue("text/html; charset=UTF-8")); m_conn.expects(once()).method("disconnect"); URLConnectionRegistry.register("test/url", (HttpURLConnection)m_conn.proxy()); // Make the request Reader r = is.acquireReader("testurl:test/url"); // Make sure that the response used the correct charset char[] chars = new char[1024]; int count = r.read(chars); String content = new String(chars, 0, count); r.close(); // should trigger a disconnect. Assert.assertEquals("Character encoding appears to be lost.", response, content); m_conn.verify(); } public ImportSupportTests(String name) { super(name); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]