You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by md...@apache.org on 2004/01/12 23:20:05 UTC
cvs commit: jakarta-commons-sandbox/codec-multipart/src/test/org/apache/commons/codec/multipart result.txt MultipartTest.java
mdiggory 2004/01/12 14:20:05
Modified: codec-multipart/src/test/org/apache/commons/codec/multipart
MultipartTest.java
Added: codec-multipart/src/test/org/apache/commons/codec/multipart
result.txt
Log:
and actual test that works.
Revision Changes Path
1.2 +31 -13 jakarta-commons-sandbox/codec-multipart/src/test/org/apache/commons/codec/multipart/MultipartTest.java
Index: MultipartTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/codec-multipart/src/test/org/apache/commons/codec/multipart/MultipartTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MultipartTest.java 12 Jan 2004 21:42:35 -0000 1.1
+++ MultipartTest.java 12 Jan 2004 22:20:05 -0000 1.2
@@ -66,7 +66,9 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -98,26 +100,42 @@
public void testBasicEncodeDecode() throws Exception {
+ File file = File.createTempFile("test","txt");
+ FileWriter writer = new FileWriter(file);
+ writer.write("This is a test");
+ writer.close();
- /*
-
+ MultipartCodec codec = MultipartCodecFactory.newMultipartCodec();
+
Part[] parts = new Part[]{
new StringPart("test1name", "test1value"),
new StringPart("test2name", "test2value"),
- new FilePart("test3name", new File("test")),
- new FilePart("test4name","test4filename",new File("test"))
+ new FilePart("test3name", file),
+ new FilePart("test4name","test4filename",file)
};
ByteArrayOutputStream out = new ByteArrayOutputStream();
+ codec.writeTo(out, parts);
- MultipartCodecFactory codec = new MultipartCodecFactory();
- String plain = "Hello there!";
- codec.encodeTo(parts,out);
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ InputStream in = this.getClass().getResourceAsStream("result.txt");
+
+ try {
+ byte[] tmp = new byte[4096];
+ int len;
+ while ((len = in.read(tmp)) >= 0) {
+ result.write(tmp, 0, len);
+ }
+ } finally {
+ // we're done with the stream, close it
+ in.close();
+ }
System.out.print(new String(out.toByteArray()));
- assertEquals("Basic URL encoding test",
- "Hello+there%21", encoded);
- */
+
+ assertEquals(new String(result.toByteArray()),new String(out.toByteArray()));
+
+ file.delete();
}
}
1.1 jakarta-commons-sandbox/codec-multipart/src/test/org/apache/commons/codec/multipart/result.txt
Index: result.txt
===================================================================
------------------314159265358979323846
Content-Disposition: form-data; name="test1name"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
test1value
------------------314159265358979323846
Content-Disposition: form-data; name="test2name"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
test2value
------------------314159265358979323846
Content-Disposition: form-data; name="test3name"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary
This is a test
------------------314159265358979323846
Content-Disposition: form-data; name="test4name"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary
This is a test
------------------314159265358979323846--
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org