You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jb...@apache.org on 2003/09/02 05:47:40 UTC
cvs commit: incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/net/protocol/file FileProtocolTest.java
jboynes 2003/09/01 20:47:40
Modified: modules/common/src/test/org/apache/geronimo/common/net/protocol/file
FileProtocolTest.java
Log:
Commented out testGetOutputStream as it fails on Windows platforms
Problem is illustrated by testFoo
Revision Changes Path
1.2 +72 -68 incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/net/protocol/file/FileProtocolTest.java
Index: FileProtocolTest.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/net/protocol/file/FileProtocolTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileProtocolTest.java 1 Sep 2003 15:18:25 -0000 1.1
+++ FileProtocolTest.java 2 Sep 2003 03:47:40 -0000 1.2
@@ -56,18 +56,16 @@
package org.apache.geronimo.common.net.protocol.file;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.MalformedURLException;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.FileOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.BufferedOutputStream;
+import java.net.URL;
+import java.net.URLConnection;
import junit.framework.TestCase;
-
import org.apache.geronimo.common.net.protocol.Protocols;
import org.apache.geronimo.common.net.protocol.URLStreamHandlerFactory;
@@ -77,8 +75,7 @@
* @version $Revision$ $Date$
*/
public class FileProtocolTest
- extends TestCase
-{
+ extends TestCase {
static {
//
// Have to install factory to make sure that our file handler is used
@@ -88,152 +85,159 @@
URLStreamHandlerFactory factory = new URLStreamHandlerFactory();
URL.setURLStreamHandlerFactory(factory);
}
-
+
protected File file;
protected URL fileURL;
-
- protected void setUp() throws Exception
- {
+
+ protected void setUp() throws Exception {
file = File.createTempFile("FileProtocolTest", ".tmp");
fileURL = file.toURI().toURL();
}
-
- protected void tearDown() throws Exception
- {
+
+ protected void tearDown() throws Exception {
file.delete();
}
-
- public void testCreateURL() throws Exception
- {
- URL url = new URL("file:/some/file");
+
+ public void testCreateURL() throws Exception {
+ new URL("file:/some/file");
}
-
- public void testURLConnectionType() throws Exception
- {
+
+ public void testURLConnectionType() throws Exception {
URL url = new URL("file:/some/file");
URLConnection c = url.openConnection();
assertEquals(FileURLConnection.class, c.getClass());
}
-
- public void testFileToURL() throws Exception
- {
+
+ public void testFileToURL() throws Exception {
URL url = file.toURL();
URLConnection c = url.openConnection();
assertEquals(FileURLConnection.class, c.getClass());
}
-
- public void testGetLastModified() throws Exception
- {
+
+ public void testGetLastModified() throws Exception {
URLConnection c = fileURL.openConnection();
assertEquals(file.lastModified(), c.getLastModified());
file.setLastModified(System.currentTimeMillis());
assertEquals(file.lastModified(), c.getLastModified());
}
-
- public void testGetDate() throws Exception
- {
+
+ public void testGetDate() throws Exception {
URLConnection c = fileURL.openConnection();
assertEquals(file.lastModified(), c.getDate());
file.setLastModified(System.currentTimeMillis());
assertEquals(file.lastModified(), c.getDate());
}
-
- protected void writeSomeBytes(final File file, final int count) throws IOException
- {
+
+ protected void writeSomeBytes(final File file, final int count) throws IOException {
OutputStream output = new FileOutputStream(file);
try {
writeSomeBytes(output, count);
- }
- finally {
+ } finally {
output.close();
}
}
-
- protected void writeSomeBytes(final OutputStream output, final int count) throws IOException
- {
+
+ protected void writeSomeBytes(final OutputStream output, final int count) throws IOException {
output.write(new byte[count]);
output.flush();
}
-
- public void testGetContentLength() throws Exception
- {
+
+ public void testGetContentLength() throws Exception {
int length = 0;
URLConnection c = fileURL.openConnection();
assertEquals(file.length(), c.getContentLength());
-
+
length += 8;
writeSomeBytes(file, length);
assertEquals(length, file.length());
assertEquals(file.length(), c.getContentLength());
-
+
length += 1;
writeSomeBytes(file, length);
assertEquals(length, file.length());
assertEquals(file.length(), c.getContentLength());
-
+
length += 10;
writeSomeBytes(file, length);
assertEquals(length, file.length());
assertEquals(file.length(), c.getContentLength());
-
+
length *= 2;
writeSomeBytes(file, length);
assertEquals(length, file.length());
assertEquals(file.length(), c.getContentLength());
}
-
- public void testGetContentType() throws Exception
- {
+
+ public void testGetContentType() throws Exception {
File file = File.createTempFile("FileProtocolTest", ".xml");
try {
URLConnection c = file.toURI().toURL().openConnection();
assertEquals("application/xml", c.getContentType());
- }
- finally {
+ } finally {
file.delete();
}
}
-
- public void testGetInputStream() throws Exception
- {
+
+ public void testGetInputStream() throws Exception {
URLConnection c = fileURL.openConnection();
InputStream input = c.getInputStream();
-
+
int length = 8;
writeSomeBytes(file, length);
assertEquals(length, input.available());
-
+
length *= 8;
writeSomeBytes(file, length);
assertEquals(length, input.available());
-
+
try {
input.close();
input.read();
fail("Expected IOException");
+ } catch (IOException e) {
+ // OK
+ }
+ }
+
+ public void testFoo() throws Exception {
+ File foo = File.createTempFile("TestFileLength", ".tmp");
+ FileOutputStream fos = new FileOutputStream(foo);
+ OutputStream out = new BufferedOutputStream(fos);
+ try {
+ out.write(new byte[10]);
+ out.flush();
+// out.close();
+ fos.getFD().sync(); // this is required on Windows for foo.length to be updated
+ assertEquals(10, foo.length());
+ } finally {
+ foo.delete();
}
- catch (IOException e) {}
}
-
- public void testGetOutputStream() throws Exception
- {
+
+ /*
+ * This test fails on Windows because File.length() is not updated until the
+ * OutputStream is closed or the underlying FileDescriptor sync()'ed
+ */
+ public void XtestGetOutputStream() throws Exception {
URLConnection c = fileURL.openConnection();
OutputStream output = c.getOutputStream();
-
+
int length = 8;
writeSomeBytes(output, length);
+ output.close();
assertEquals(length, file.length());
assertEquals(length, c.getContentLength());
-
+
writeSomeBytes(output, length);
assertEquals(length * 2, file.length());
assertEquals(length * 2, c.getContentLength());
-
+
try {
output.close();
writeSomeBytes(output, 1);
fail("Expected IOException");
+ } catch (IOException e) {
+ // OK
}
- catch (IOException e) {}
}
}