Revision: 3336
http://vexi.svn.sourceforge.net/vexi/?rev=3336&view=rev
Author: mkpg2
Date: 2009-01-04 04:02:18 +0000 (Sun, 04 Jan 2009)
Log Message:
-----------
New test to verify posting with vexi.stream.pipe()
Modified Paths:
--------------
trunk/core/org.ibex.js/src_junit/test/js/exec/http/TestHTTP.java
trunk/core/org.ibex.net/src_junit/org/ibex/net/TestHTTP.java
trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java
Added Paths:
-----------
trunk/core/org.ibex.js/src_junit/test/js/exec/http/post2.js
Modified: trunk/core/org.ibex.js/src_junit/test/js/exec/http/TestHTTP.java
===================================================================
--- trunk/core/org.ibex.js/src_junit/test/js/exec/http/TestHTTP.java
2009-01-04 01:54:17 UTC (rev 3335)
+++ trunk/core/org.ibex.js/src_junit/test/js/exec/http/TestHTTP.java
2009-01-04 04:02:18 UTC (rev 3336)
@@ -11,15 +11,17 @@
public TestHTTP() {
super(TestHTTP.class);
}
-
- public void run(TestResult result) {
+
+ static private void before(){
// start servlet
try {
org.ibex.net.TestHTTP.startServlet();
} catch (Exception e) {
throw new Error(e);
}
- super.run(result);
+ }
+
+ static private void after(){
// end servlet
try {
org.ibex.net.TestHTTP.stopServlet();
@@ -27,9 +29,23 @@
throw new Error(e);
}
}
+
+ public void run(TestResult result) {
+ before();
+ super.run(result);
+ after();
+ }
public static Test suite() {
return JSTestSuite.suite(new TestHTTP());
}
+
+ static public void main(String[] args) throws Throwable {
+ before();
+ JSTestSuite jts = new TestHTTP();
+ TestCase t = jts.createTestCase(jts.getResourceDirs(), "post2.js");
+ t.run();
+ after();
+ }
}
\ No newline at end of file
Added: trunk/core/org.ibex.js/src_junit/test/js/exec/http/post2.js
===================================================================
--- trunk/core/org.ibex.js/src_junit/test/js/exec/http/post2.js
(rev 0)
+++ trunk/core/org.ibex.js/src_junit/test/js/exec/http/post2.js 2009-01-04
04:02:18 UTC (rev 3336)
@@ -0,0 +1,16 @@
+ sys.import("shared");
+ var local = sys.stream.buffer(3);
+ sys.log.warn(1);
+ sys.stream.utf8writer(local).write("abc");
+ sys.log.warn(2);
+ assertEquals("abc",sys.stream.utf8reader(local).all);
+ sys.log.warn(3);
+ var remote = sys.stream.url("http://localhost:9999/capitalize");
+
+ sys.stream.pipe(local,remote);
+ sys.log.warn(4);
+ var r = sys.stream.utf8reader(remote).all;
+ sys.log.warn(5);
+ sys.log.warn(r.length);
+ assertEquals("ABC",r);
+
Modified: trunk/core/org.ibex.net/src_junit/org/ibex/net/TestHTTP.java
===================================================================
--- trunk/core/org.ibex.net/src_junit/org/ibex/net/TestHTTP.java
2009-01-04 01:54:17 UTC (rev 3335)
+++ trunk/core/org.ibex.net/src_junit/org/ibex/net/TestHTTP.java
2009-01-04 04:02:18 UTC (rev 3336)
@@ -39,14 +39,15 @@
public static void stopServlet() throws Exception{
server.stop();
}
-
+ static private byte[] workspace = new byte[16 * 1024];
static public class CapitalizeServlet extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- IOUtil.pipe(request.getInputStream(),
- baos);
+ IOUtil.pipe(
+ request.getInputStream(),
+ baos, workspace);
String r = baos.toString().toUpperCase();
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
Modified: trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java
===================================================================
--- trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java 2009-01-04
01:54:17 UTC (rev 3335)
+++ trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java 2009-01-04
04:02:18 UTC (rev 3336)
@@ -43,4 +43,16 @@
out.close();
}
}
+
+ public static void pipe(InputStream in, OutputStream out, byte[]
workspace) throws IOException {
+ try{
+ while (true) {
+ int bytesRead = in.read(workspace);
+ if (bytesRead == -1) break;
+ out.write(workspace, 0, bytesRead);
+ }
+ }finally{
+ out.close();
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn