Thanks! Archives and more eyes are very good things. :)
Responses inline: On 1/24/07, Christopher Schultz <[EMAIL PROTECTED]> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 All, [ At the request of Nathan Bubna, I am posting this to [email protected] 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)
Code contributions are best through JIRA anyway, as that allows you to mark it explicitly as contributed for use under the Apache License.
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.
Yeah, we're open source, so installing a binary-only library probably won't work. However, it's not really that difficult to start your own open source project for this at Google Code (http://code.google.com/hosting/createProject) or SourceForge (http://sourceforge.net/register/). Once it is set up there, that makes it much easier for people to try it out or check out the code, which in turn makes it much, much easier to find a better home for it or else build a dev community around it there. In fact, depending on what license you put it under (i recommend ASL 2.0 :), once you set it up and release a version, we would then be able to integrate it into the VelocityTools tests and increase it's exposure for you. The only other possibility for us being able to use TestURLConnection in VelocityTools is if we decided to adopt the code ourselves and make it part of our own little test framework. Consideration of this would probably have to wait until VelocityTools 1.3 is released and i am definitely open to it if it means thorough testing of ImportSupport, however, it probably would not give as much exposure or freedom to your library. If you're willing to take the time to set it up and release it as an independent project, then that is the path i would recommend.
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.
i'm not sure. Claude might have a better idea. I'm still a noob when it comes to junit.
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.
We would probably either have to change "test.generic" to "test.whitebox" or else add a new "greybox" or something. Claude, are you reading this? I'd love to hear your thoughts on where non-blackbox testing of VelocityView (not Generic) tools should go.
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]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
