Author: fhanik Date: Thu Jul 5 13:55:07 2007 New Revision: 553631 URL: http://svn.apache.org/viewvc?view=rev&rev=553631 Log: Added test and fixed the streaming reader to work with multiple messages
Added: tomcat/sandbox/bayeux/test/ tomcat/sandbox/bayeux/test/org/ tomcat/sandbox/bayeux/test/org/apache/ tomcat/sandbox/bayeux/test/org/apache/comet/ tomcat/sandbox/bayeux/test/org/apache/comet/test/ tomcat/sandbox/bayeux/test/org/apache/comet/test/TestJSONReader.java Modified: tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java Modified: tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java?view=diff&rev=553631&r1=553630&r2=553631 ============================================================================== --- tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java (original) +++ tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java Thu Jul 5 13:55:07 2007 @@ -52,8 +52,12 @@ public void recycle() { - reader = null; + recycle(null); + } + public void recycle(Reader r) { + reader = r; buffer.delete(0,buffer.length()); + pos = -1; } public void setReader(Reader r){ Added: tomcat/sandbox/bayeux/test/org/apache/comet/test/TestJSONReader.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/test/org/apache/comet/test/TestJSONReader.java?view=auto&rev=553631 ============================================================================== --- tomcat/sandbox/bayeux/test/org/apache/comet/test/TestJSONReader.java (added) +++ tomcat/sandbox/bayeux/test/org/apache/comet/test/TestJSONReader.java Thu Jul 5 13:55:07 2007 @@ -0,0 +1,87 @@ +package org.apache.comet.test; + +import junit.framework.*; +import org.stringtree.json.JSONReader; +import org.stringtree.json.JSONValidatingReader; +import org.stringtree.json.JSONValidator; +import org.stringtree.json.JSONErrorListener; +import java.io.StringReader; +import org.apache.comet.json.ReaderCharIterator; + +public class TestJSONReader extends TestCase { + String s = "[\n"+ +" {\n"+ +" \"channel\": \"/meta/handshake\",\n"+ +" \"version\": 0.1,\n"+ +" \"minimumVersion\": 0.1,\n"+ +" \"supportedConnectionTypes\": [\"iframe\", \"flash\", \"http-polling\"],\n"+ +" \"authScheme\": \"SHA1\",\n"+ +" \"authUser\": \"alex\",\n"+ +" \"authToken\": \"HASHJIBBERISH\"\n"+ +" }\n"+ +" ]\n"; + + + + + public TestJSONReader(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testJSON() throws Exception { + JSONReader reader = new JSONReader(); + Object o = reader.read(s); + System.out.println(o); + assertNotNull("JSON Test failed, returned null.",o); + JSONValidatingReader vr = new JSONValidatingReader(new ErrorListener()); + o = vr.read(s); + System.out.println(o); + assertNotNull("JSON Test failed, returned null.",o); + } + + public void testJSONStreaming() throws Exception { + JSONReader reader = new JSONReader(); + StringReader sr = new StringReader(s); + ReaderCharIterator rci = new ReaderCharIterator(sr); + Object o = reader.read(rci,JSONReader.FIRST); + System.out.println(o); + assertNotNull("JSON Test failed, returned null.",o); + } + + public void testJSONStreamingTwoMsgs() throws Exception { + JSONReader reader = new JSONReader(); + StringReader sr = new StringReader(s+s.replaceAll("SHA1","MD5")); + ReaderCharIterator rci = new ReaderCharIterator(sr); + Object o = reader.read(rci,JSONReader.FIRST); + System.out.println(o); + assertNotNull("JSON Test failed, returned null.",o); + rci.recycle(); + rci.setReader(sr); + o = reader.read(rci,JSONReader.NEXT); + System.out.println(o); + assertNotNull("JSON Test failed, returned null.",o); + } + + + public static class ErrorListener implements JSONErrorListener { + public void start(String string) { + System.out.println("Start:"+string); + } + public void error(String string, int _int) { + System.out.println("Error:"+string+" Pos:"+_int); + } + public void end(){ + System.out.println("End:"); + } + + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]