You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2008/01/16 21:56:06 UTC

svn commit: r612569 [1/2] - in /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests: internal/net/www/protocol/file/ internal/net/www/protocol/http/ internal/net/www/protocol/https/ java/io/

Author: tellison
Date: Wed Jan 16 12:56:03 2008
New Revision: 612569

URL: http://svn.apache.org/viewvc?rev=612569&view=rev
Log:
Another round of LUNI test tidy-ups, including formatting, tidy-up imports, and letting JUnit handle the exceptions.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayInputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayOutputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/CharArrayWriterTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/CharConversionExceptionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/DataInputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/DataOutputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/EOFExceptionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java?rev=612569&r1=612568&r2=612569&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java Wed Jan 16 12:56:03 2008
@@ -19,10 +19,9 @@
 import java.io.IOException;
 import java.net.URL;
 
-import org.apache.harmony.luni.internal.net.www.protocol.file.FileURLConnection;
-
 import junit.framework.TestCase;
 
+import org.apache.harmony.luni.internal.net.www.protocol.file.FileURLConnection;
 
 /**
  * Tests for <code>FileURLConnection</code> class constructors and methods.
@@ -36,11 +35,12 @@
         return new FileURLConnection(url).getContentType();
     }
 
-    public void testGetContentType() throws Exception {
+    public void testGetContentType() throws IOException  {
         // Regression for HARMONY-4699
         assertEquals(getContentType("test.rtf"), "application/rtf");
         assertEquals(getContentType("test.java"), "text/plain");
-        assertEquals(getContentType("test.doc"), "application/msword"); // RI would return "content/unknown"
+        // RI would return "content/unknown"
+        assertEquals(getContentType("test.doc"), "application/msword");
         assertEquals(getContentType("test.htx"), "text/html");
         assertEquals(getContentType("test.xml"), "application/xml");
         assertEquals(getContentType("."), "text/plain");

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java?rev=612569&r1=612568&r2=612569&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java Wed Jan 16 12:56:03 2008
@@ -97,8 +97,8 @@
             this(name, persUses, OK_CODE);
         }
 
-        public MockHTTPServer(String name, int persUses,
-                int responseCode) throws IOException {
+        public MockHTTPServer(String name, int persUses, int responseCode)
+                throws IOException {
             super(name);
             this.persUses = persUses;
             this.responseCode = responseCode;
@@ -120,10 +120,10 @@
                 try {
                     client = serverSocket.accept();
                     accepted = true;
-                    for (int i=0; i<persUses; i++) {
+                    for (int i = 0; i < persUses; i++) {
                         if (DEBUG) {
                             System.out.println("*** Using connection for "
-                                    + (i+1) + " time ***");
+                                    + (i + 1) + " time ***");
                         }
                         byte[] buff = new byte[1024];
                         is = client.getInputStream();
@@ -141,38 +141,42 @@
                             wasEOL = (bytik == '\n');
                             buff[num++] = (byte) bytik;
                         }
-                        //int num = is.read(buff);
+                        // int num = is.read(buff);
                         String message = new String(buff, 0, num);
                         if (DEBUG) {
-                            System.out.println("---- Server got request: ----\n"
-                                + message + "-----------------------------");
+                            System.out
+                                    .println("---- Server got request: ----\n"
+                                            + message
+                                            + "-----------------------------");
                         }
-                        
+
                         // Act as Server (not Proxy) side
                         if (message.startsWith("POST")) {
                             // client connection sent some data
                             // if the data was not read with header
                             if (DEBUG) {
-                                System.out.println(
-                                        "---- Server read client's data: ----");
+                                System.out
+                                        .println("---- Server read client's data: ----");
                             }
                             num = is.read(buff);
                             message = new String(buff, 0, num);
                             if (DEBUG) {
                                 System.out.println("'" + message + "'");
-                                System.out.println(
-                                        "------------------------------------");
+                                System.out
+                                        .println("------------------------------------");
                             }
                             // check the received data
                             assertEquals(clientPost, message);
                         }
 
-                        client.getOutputStream().write((
-                            "HTTP/1.1 " + responseCode + " OK\n"
-                            + "Content-type: text/html\n"
-                            + "Content-length: " 
-                            + response.length() + "\n\n"
-                            + response).getBytes());
+                        client
+                                .getOutputStream()
+                                .write(
+                                        ("HTTP/1.1 " + responseCode + " OK\n"
+                                                + "Content-type: text/html\n"
+                                                + "Content-length: "
+                                                + response.length() + "\n\n" + response)
+                                                .getBytes());
 
                         if (responseCode != OK_CODE) {
                             // wait while test case check closed connection
@@ -181,7 +185,8 @@
                                 while (!isInterrupted()) {
                                     Thread.sleep(1000);
                                 }
-                            } catch (Exception ignore) { }
+                            } catch (Exception ignore) {
+                            }
                         }
                     }
                 } catch (SocketTimeoutException ignore) {
@@ -204,7 +209,7 @@
     static class MockProxyServer extends MockServer {
 
         boolean acceptedAuthorizedRequest;
-        
+
         public MockProxyServer(String name) throws Exception {
             super(name);
         }
@@ -216,10 +221,12 @@
                 socket.setSoTimeout(5000);
                 byte[] buff = new byte[1024];
                 int num = socket.getInputStream().read(buff);
-                socket.getOutputStream().write((
-                    "HTTP/1.0 407 Proxy authentication required\n"
-                        + "Proxy-authenticate: Basic realm=\"remotehost\"\n\n")
-                        .getBytes());
+                socket
+                        .getOutputStream()
+                        .write(
+                                ("HTTP/1.0 407 Proxy authentication required\n"
+                                        + "Proxy-authenticate: Basic realm=\"remotehost\"\n\n")
+                                        .getBytes());
                 num = socket.getInputStream().read(buff);
                 if (num == -1) {
                     // this connection was closed, create new one:
@@ -228,11 +235,11 @@
                     num = socket.getInputStream().read(buff);
                 }
                 String request = new String(buff, 0, num);
-                acceptedAuthorizedRequest = 
-                    request.toLowerCase().indexOf("proxy-authorization:") > 0;
+                acceptedAuthorizedRequest = request.toLowerCase().indexOf(
+                        "proxy-authorization:") > 0;
                 if (acceptedAuthorizedRequest) {
-                    socket.getOutputStream().write((
-                            "HTTP/1.1 200 OK\n\n").getBytes());
+                    socket.getOutputStream().write(
+                            ("HTTP/1.1 200 OK\n\n").getBytes());
                 }
             } catch (IOException e) {
             }
@@ -242,7 +249,7 @@
     public void setUp() {
         if (DEBUG) {
             System.out.println("\n==============================");
-            System.out.println("===== Execution: "+getName());
+            System.out.println("===== Execution: " + getName());
             System.out.println("==============================");
         }
     }
@@ -257,11 +264,10 @@
         private int server_port;
 
         /**
-         * Creates proxy selector instance.
-         * Selector will return the proxy, only if the connection
-         * is made to localhost:server_port. Otherwise it will
-         * return NO_PROXY.
-         * Address of the returned proxy will be localhost:proxy_port.
+         * Creates proxy selector instance. Selector will return the proxy, only
+         * if the connection is made to localhost:server_port. Otherwise it will
+         * return NO_PROXY. Address of the returned proxy will be
+         * localhost:proxy_port.
          */
         public TestProxySelector(int server_port, int proxy_port) {
             this.server_port = server_port;
@@ -273,8 +279,8 @@
             Proxy proxy = Proxy.NO_PROXY;
             if (("localhost".equals(uri.getHost()))
                     && (server_port == uri.getPort())) {
-                proxy = new Proxy(Proxy.Type.HTTP,
-                            new InetSocketAddress("localhost", proxy_port));
+                proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
+                        "localhost", proxy_port));
             }
             ArrayList<Proxy> result = new ArrayList<Proxy>();
             result.add(proxy);
@@ -292,28 +298,27 @@
      */
     public void testGetOutputStream() throws Exception {
         // Regression for HARMONY-482
-        MockServer httpServer =
-            new MockServer("ServerSocket for HttpURLConnectionTest");
+        MockServer httpServer = new MockServer(
+                "ServerSocket for HttpURLConnectionTest");
         httpServer.start();
-        synchronized(bound) {
+        synchronized (bound) {
             if (!httpServer.started) {
                 bound.wait(5000);
             }
         }
-        HttpURLConnection c = (HttpURLConnection)
-            new URL("http://127.0.0.1:" + httpServer.port()).openConnection();
+        HttpURLConnection c = (HttpURLConnection) new URL("http://127.0.0.1:"
+                + httpServer.port()).openConnection();
         c.setDoOutput(true);
-        //use new String("POST") instead of simple "POST" to obtain other
-        //object instances then those that are in HttpURLConnection classes
+        // use new String("POST") instead of simple "POST" to obtain other
+        // object instances then those that are in HttpURLConnection classes
         c.setRequestMethod(new String("POST"));
         c.getOutputStream();
         httpServer.join();
     }
 
-
     /**
-     * Test checks if the proxy specified in openConnection
-     * method will be used for connection to the server
+     * Test checks if the proxy specified in openConnection method will be used
+     * for connection to the server
      */
     public void testUsingProxy() throws Exception {
         // Regression for HARMONY-570
@@ -324,18 +329,19 @@
 
         HttpURLConnection connection = (HttpURLConnection) url
                 .openConnection(new Proxy(Proxy.Type.HTTP,
-                        new InetSocketAddress("localhost",
-                            proxy.port())));
+                        new InetSocketAddress("localhost", proxy.port())));
         connection.setConnectTimeout(2000);
         connection.setReadTimeout(2000);
 
         server.start();
-        synchronized(bound) {
-            if (!server.started) bound.wait(5000);
+        synchronized (bound) {
+            if (!server.started)
+                bound.wait(5000);
         }
         proxy.start();
-        synchronized(bound) {
-            if (!proxy.started) bound.wait(5000);
+        synchronized (bound) {
+            if (!proxy.started)
+                bound.wait(5000);
         }
 
         connection.connect();
@@ -346,14 +352,15 @@
 
         assertTrue("Connection does not use proxy", connection.usingProxy());
         assertTrue("Proxy server was not used", proxy.accepted);
-        
-        HttpURLConnection huc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
+
+        HttpURLConnection huc = (HttpURLConnection) url
+                .openConnection(Proxy.NO_PROXY);
         assertFalse(huc.usingProxy());
     }
 
     /**
-     * Test checks if the proxy provided by proxy selector
-     * will be used for connection to the server
+     * Test checks if the proxy provided by proxy selector will be used for
+     * connection to the server
      */
     public void testUsingProxySelector() throws Exception {
         // Regression for HARMONY-570
@@ -365,22 +372,24 @@
         // keep default proxy selector
         ProxySelector defPS = ProxySelector.getDefault();
         // replace selector
-        ProxySelector.setDefault(
-                new TestProxySelector(server.port(), proxy.port()));
+        ProxySelector.setDefault(new TestProxySelector(server.port(), proxy
+                .port()));
 
         try {
-            HttpURLConnection connection =
-                (HttpURLConnection) url.openConnection();
+            HttpURLConnection connection = (HttpURLConnection) url
+                    .openConnection();
             connection.setConnectTimeout(2000);
             connection.setReadTimeout(2000);
 
             server.start();
-            synchronized(bound) {
-                if (!server.started) bound.wait(5000);
+            synchronized (bound) {
+                if (!server.started)
+                    bound.wait(5000);
             }
             proxy.start();
-            synchronized(bound) {
-                if (!proxy.started) bound.wait(5000);
+            synchronized (bound) {
+                if (!proxy.started)
+                    bound.wait(5000);
             }
             connection.connect();
 
@@ -388,8 +397,7 @@
             server.join();
             proxy.join();
 
-            assertTrue("Connection does not use proxy",
-                                            connection.usingProxy());
+            assertTrue("Connection does not use proxy", connection.usingProxy());
             assertTrue("Proxy server was not used", proxy.accepted);
         } finally {
             // restore default proxy selector
@@ -402,8 +410,8 @@
         Authenticator.setDefault(new Authenticator() {
             @Override
             protected PasswordAuthentication getPasswordAuthentication() {
-                return new PasswordAuthentication(
-                    "user", "password".toCharArray());
+                return new PasswordAuthentication("user", "password"
+                        .toCharArray());
             }
         });
 
@@ -411,9 +419,8 @@
             MockProxyServer proxy = new MockProxyServer("ProxyServer");
 
             URL url = new URL("http://remotehost:55555/requested.data");
-            HttpURLConnection connection =
-                (HttpURLConnection) url.openConnection(
-                        new Proxy(Proxy.Type.HTTP,
+            HttpURLConnection connection = (HttpURLConnection) url
+                    .openConnection(new Proxy(Proxy.Type.HTTP,
                             new InetSocketAddress("localhost", proxy.port())));
             connection.setConnectTimeout(5000);
             connection.setReadTimeout(5000);
@@ -421,8 +428,8 @@
             proxy.start();
 
             connection.connect();
-            assertEquals("unexpected response code", 
-                    200, connection.getResponseCode());
+            assertEquals("unexpected response code", 200, connection
+                    .getResponseCode());
             proxy.join();
             assertTrue("Connection did not send proxy authorization request",
                     proxy.acceptedAuthorizedRequest);
@@ -433,23 +440,23 @@
     }
 
     /**
-     * Test that a connection is not closed if the client reads all the data 
-     * but not closes input stream. read until -1.
+     * Test that a connection is not closed if the client reads all the data but
+     * not closes input stream. read until -1.
      */
     public void testConnectionPersistence() throws Exception {
-        MockHTTPServer httpServer =
-            new MockHTTPServer("HTTP Server for persistence checking", 2);
+        MockHTTPServer httpServer = new MockHTTPServer(
+                "HTTP Server for persistence checking", 2);
         httpServer.start();
-        synchronized(bound) {
+        synchronized (bound) {
             if (!httpServer.started) {
                 bound.wait(5000);
             }
         }
 
-        HttpURLConnection c = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         if (DEBUG) {
-            System.out.println("Actual connection class: "+c.getClass());
+            System.out.println("Actual connection class: " + c.getClass());
         }
 
         c.setDoInput(true);
@@ -459,7 +466,7 @@
         byte[] buffer = new byte[128];
         int totalBytes = 0;
         int bytesRead = 0;
-        while((bytesRead = is.read(buffer)) > 0){
+        while ((bytesRead = is.read(buffer)) > 0) {
             if (DEBUG) {
                 System.out.println("Client got response: '"
                         + new String(buffer, 0, bytesRead) + "'");
@@ -467,8 +474,8 @@
             totalBytes += bytesRead;
         }
 
-        HttpURLConnection c2 = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c2 = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
         c2.setReadTimeout(5000);
@@ -476,7 +483,7 @@
         buffer = new byte[128];
         totalBytes = 0;
         bytesRead = 0;
-        while((bytesRead = is.read(buffer)) > 0){
+        while ((bytesRead = is.read(buffer)) > 0) {
             if (DEBUG) {
                 System.out.println("Client got response: '"
                         + new String(buffer, 0, bytesRead) + "'");
@@ -486,23 +493,23 @@
     }
 
     /**
-     * Test that a connection is not closed if the client reads all the data 
-     * but not closes input stream. read() not receives -1.
+     * Test that a connection is not closed if the client reads all the data but
+     * not closes input stream. read() not receives -1.
      */
     public void testConnectionPersistence2() throws Exception {
-        MockHTTPServer httpServer =
-            new MockHTTPServer("HTTP Server for persistence checking", 2);
+        MockHTTPServer httpServer = new MockHTTPServer(
+                "HTTP Server for persistence checking", 2);
         httpServer.start();
-        synchronized(bound) {
+        synchronized (bound) {
             if (!httpServer.started) {
                 bound.wait(5000);
             }
         }
 
-        HttpURLConnection c = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         if (DEBUG) {
-            System.out.println("Actual connection class: "+c.getClass());
+            System.out.println("Actual connection class: " + c.getClass());
         }
 
         c.setDoInput(true);
@@ -511,45 +518,47 @@
         InputStream is = c.getInputStream();
         int bytes2Read = httpServer.response.length();
         byte[] buffer = new byte[httpServer.response.length()];
-        while((bytes2Read -= is.read(buffer)) > 0) { }
+        while ((bytes2Read -= is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
 
-        HttpURLConnection c2 = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c2 = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
         c2.setReadTimeout(5000);
         is = c2.getInputStream();
         buffer = new byte[httpServer.response.length()];
         bytes2Read = httpServer.response.length();
-        while((bytes2Read -= is.read(buffer)) > 0) { }
+        while ((bytes2Read -= is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
     }
 
     /**
-     * Test that a connection is not closed if it firstly does POST, 
-     * and then does GET requests.
+     * Test that a connection is not closed if it firstly does POST, and then
+     * does GET requests.
      */
     public void testConnectionPersistence3() throws Exception {
-        MockHTTPServer httpServer =
-            new MockHTTPServer("HTTP Server for persistence checking", 2);
+        MockHTTPServer httpServer = new MockHTTPServer(
+                "HTTP Server for persistence checking", 2);
         httpServer.start();
-        synchronized(bound) {
+        synchronized (bound) {
             if (!httpServer.started) {
                 bound.wait(5000);
             }
         }
 
-        HttpURLConnection c = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         if (DEBUG) {
-            System.out.println("Actual connection class: "+c.getClass());
+            System.out.println("Actual connection class: " + c.getClass());
         }
 
         c.setDoInput(true);
@@ -558,65 +567,68 @@
         c.setReadTimeout(5000);
         c.getOutputStream().write(httpServer.clientPost.getBytes());
 
-        InputStream is = c.getInputStream(); 
+        InputStream is = c.getInputStream();
         int bytes2Read = httpServer.response.length();
         byte[] buffer = new byte[httpServer.response.length()];
-        while((bytes2Read -= is.read(buffer)) > 0) { }
+        while ((bytes2Read -= is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
 
-        HttpURLConnection c2 = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c2 = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
         c2.setReadTimeout(5000);
         is = c2.getInputStream();
         buffer = new byte[httpServer.response.length()];
         bytes2Read = httpServer.response.length();
-        while((bytes2Read -= is.read(buffer)) > 0) { }
+        while ((bytes2Read -= is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
     }
 
     /**
-     * Test that a connection is not closed if it firstly does GET, 
-     * and then does POST requests.
+     * Test that a connection is not closed if it firstly does GET, and then
+     * does POST requests.
      */
     public void testConnectionPersistence4() throws Exception {
-        MockHTTPServer httpServer =
-            new MockHTTPServer("HTTP Server for persistence checking", 2);
+        MockHTTPServer httpServer = new MockHTTPServer(
+                "HTTP Server for persistence checking", 2);
         httpServer.start();
-        synchronized(bound) {
+        synchronized (bound) {
             if (!httpServer.started) {
                 bound.wait(5000);
             }
         }
 
-        HttpURLConnection c = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         if (DEBUG) {
-            System.out.println("Actual connection class: "+c.getClass());
+            System.out.println("Actual connection class: " + c.getClass());
         }
 
         c.setDoInput(true);
         c.setConnectTimeout(5000);
         c.setReadTimeout(5000);
 
-        InputStream is = c.getInputStream(); 
+        InputStream is = c.getInputStream();
         int bytes2Read = httpServer.response.length();
         byte[] buffer = new byte[httpServer.response.length()];
-        while((bytes2Read = is.read(buffer)) > 0) { }
+        while ((bytes2Read = is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
-        
-        HttpURLConnection c2 = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+
+        HttpURLConnection c2 = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         c2.setDoOutput(true);
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
@@ -625,10 +637,11 @@
         is = c2.getInputStream();
         buffer = new byte[httpServer.response.length()];
         bytes2Read = httpServer.response.length();
-        while((bytes2Read = is.read(buffer)) > 0) { }
+        while ((bytes2Read = is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
     }
 
@@ -636,36 +649,37 @@
      * Test that a connection is not closed if it does POST for 2 times.
      */
     public void testConnectionPersistence5() throws Exception {
-        MockHTTPServer httpServer =
-            new MockHTTPServer("HTTP Server for persistence checking", 2);
+        MockHTTPServer httpServer = new MockHTTPServer(
+                "HTTP Server for persistence checking", 2);
         httpServer.start();
-        synchronized(bound) {
+        synchronized (bound) {
             if (!httpServer.started) {
                 bound.wait(5000);
             }
         }
 
-        HttpURLConnection c = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         if (DEBUG) {
-            System.out.println("Actual connection class: "+c.getClass());
+            System.out.println("Actual connection class: " + c.getClass());
         }
         c.setDoOutput(true);
         c.setDoInput(true);
         c.setConnectTimeout(5000);
         c.setReadTimeout(5000);
         c.getOutputStream().write(httpServer.clientPost.getBytes());
-        InputStream is = c.getInputStream(); 
+        InputStream is = c.getInputStream();
         int bytes2Read = httpServer.response.length();
         byte[] buffer = new byte[httpServer.response.length()];
-        while((bytes2Read = is.read(buffer)) > 0) { }
+        while ((bytes2Read = is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
 
-        HttpURLConnection c2 = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+        HttpURLConnection c2 = (HttpURLConnection) new URL("http://localhost:"
+                + httpServer.port()).openConnection();
         c2.setDoOutput(true);
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
@@ -674,72 +688,75 @@
         is = c2.getInputStream();
         buffer = new byte[httpServer.response.length()];
         bytes2Read = httpServer.response.length();
-        while((bytes2Read = is.read(buffer)) > 0) { }
+        while ((bytes2Read = is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
     }
 
     /**
-     * Test that a connection made through proxy will be reused
-     * for connection establishing without proxy.
+     * Test that a connection made through proxy will be reused for connection
+     * establishing without proxy.
      */
     public void testProxiedConnectionPersistence() throws Exception {
-        MockHTTPServer httpServer =
-            new MockHTTPServer("HTTP Server for persistence checking", 2);
+        MockHTTPServer httpServer = new MockHTTPServer(
+                "HTTP Server for persistence checking", 2);
         httpServer.start();
-        synchronized(bound) {
+        synchronized (bound) {
             if (!httpServer.started) {
                 bound.wait(5000);
             }
         }
 
-        HttpURLConnection c = (HttpURLConnection)
-            new URL("http://some.host:1234")
-                    .openConnection(new Proxy(Proxy.Type.HTTP,
-                            new InetSocketAddress("localhost",
-                                httpServer.port())));
+        HttpURLConnection c = (HttpURLConnection) new URL(
+                "http://some.host:1234").openConnection(new Proxy(
+                Proxy.Type.HTTP, new InetSocketAddress("localhost", httpServer
+                        .port())));
         if (DEBUG) {
-            System.out.println("Actual connection class: "+c.getClass());
+            System.out.println("Actual connection class: " + c.getClass());
         }
         c.setDoOutput(true);
         c.setDoInput(true);
         c.setConnectTimeout(5000);
         c.setReadTimeout(5000);
         c.getOutputStream().write(httpServer.clientPost.getBytes());
-        InputStream is = c.getInputStream(); 
+        InputStream is = c.getInputStream();
         int bytes2Read = httpServer.response.length();
         byte[] buffer = new byte[httpServer.response.length()];
-        while((bytes2Read = is.read(buffer)) > 0) { }
+        while ((bytes2Read = is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
 
-        HttpURLConnection c2 = (HttpURLConnection)
-            new URL("http://some.host:1234").openConnection();
+        HttpURLConnection c2 = (HttpURLConnection) new URL(
+                "http://some.host:1234").openConnection();
         c2.setDoOutput(true);
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
         c2.setReadTimeout(5000);
         c2.getOutputStream().write(httpServer.clientPost.getBytes());
-        is = c2.getInputStream(); 
+        is = c2.getInputStream();
         buffer = new byte[httpServer.response.length()];
         bytes2Read = httpServer.response.length();
-        while((bytes2Read = is.read(buffer)) > 0) { }
+        while ((bytes2Read = is.read(buffer)) > 0) {
+        }
         if (DEBUG) {
-            System.out.println("Client got response: '"
-                    + new String(buffer) + "'");
+            System.out.println("Client got response: '" + new String(buffer)
+                    + "'");
         }
     }
 
-    public void testSecurityManager() throws MalformedURLException, IOException, InterruptedException {
+    public void testSecurityManager() throws MalformedURLException,
+            IOException, InterruptedException {
         try {
-            MockHTTPServer httpServer =
-                new MockHTTPServer("HTTP Server for persistence checking", 2);
+            MockHTTPServer httpServer = new MockHTTPServer(
+                    "HTTP Server for persistence checking", 2);
             httpServer.start();
-            synchronized(bound) {
+            synchronized (bound) {
                 if (!httpServer.started) {
                     bound.wait(5000);
                 }
@@ -749,10 +766,12 @@
 
             // Check that a first connection calls checkConnect
             try {
-                HttpURLConnection c = (HttpURLConnection)
-                    new URL("http://localhost:"+httpServer.port()).openConnection();
+                HttpURLConnection c = (HttpURLConnection) new URL(
+                        "http://localhost:" + httpServer.port())
+                        .openConnection();
                 if (DEBUG) {
-                    System.out.println("Actual connection class: "+c.getClass());
+                    System.out.println("Actual connection class: "
+                            + c.getClass());
                 }
                 c.connect();
                 fail("Should have thrown a SecurityException upon connection");
@@ -762,8 +781,8 @@
 
             // Now create a connection properly
             System.setSecurityManager(null);
-            HttpURLConnection c = (HttpURLConnection)
-            new URL("http://localhost:"+httpServer.port()).openConnection();
+            HttpURLConnection c = (HttpURLConnection) new URL(
+                    "http://localhost:" + httpServer.port()).openConnection();
             c.setDoInput(true);
             c.setConnectTimeout(5000);
             c.setReadTimeout(5000);
@@ -771,7 +790,7 @@
             byte[] buffer = new byte[128];
             int totalBytes = 0;
             int bytesRead = 0;
-            while((bytesRead = is.read(buffer)) > 0){
+            while ((bytesRead = is.read(buffer)) > 0) {
                 if (DEBUG) {
                     System.out.println("Client got response: '"
                             + new String(buffer, 0, bytesRead) + "'");
@@ -782,8 +801,9 @@
             // Now check that a second connection also calls checkConnect
             System.setSecurityManager(sm);
             try {
-                HttpURLConnection c2 = (HttpURLConnection)
-                    new URL("http://localhost:"+httpServer.port()).openConnection();
+                HttpURLConnection c2 = (HttpURLConnection) new URL(
+                        "http://localhost:" + httpServer.port())
+                        .openConnection();
                 c2.setDoInput(true);
                 c2.setConnectTimeout(5000);
                 c2.setReadTimeout(5000);
@@ -791,7 +811,7 @@
                 buffer = new byte[128];
                 totalBytes = 0;
                 bytesRead = 0;
-                while((bytesRead = is.read(buffer)) > 0){
+                while ((bytesRead = is.read(buffer)) > 0) {
                     if (DEBUG) {
                         System.out.println("Client got response: '"
                                 + new String(buffer, 0, bytesRead) + "'");
@@ -810,14 +830,14 @@
 
         @Override
         public void checkConnect(String host, int port) {
-           throw new SecurityException();
+            throw new SecurityException();
         }
-        
+
         @Override
         public void checkConnect(String host, int port, Object context) {
             throw new SecurityException();
         }
-        
+
         @Override
         public void checkPermission(Permission permission) {
             // allows a new security manager to be set

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java?rev=612569&r1=612568&r2=612569&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java Wed Jan 16 12:56:03 2008
@@ -36,6 +36,7 @@
 import java.security.KeyStore;
 import java.security.cert.Certificate;
 import java.util.Arrays;
+
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.KeyManagerFactory;
@@ -46,23 +47,19 @@
 import javax.net.ssl.SSLSocketFactory;
 import javax.net.ssl.TrustManagerFactory;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 /**
- * Implementation independent test for HttpsURLConnection.
- * The test needs certstore file placed in system classpath 
- * and named as "key_store." + the type of the
- * default KeyStore installed in the system in lower case.
- * <br>
- * For example: if default KeyStore type in the system is BKS
- * (i.e. java.security file sets up the property keystore.type=BKS),
- * thus classpath should point to the directory with "key_store.bks"
- * file.
- * <br>
- * This certstore file should contain self-signed certificate
- * generated by keytool utility in a usual way.
- * <br>
+ * Implementation independent test for HttpsURLConnection. The test needs
+ * certstore file placed in system classpath and named as "key_store." + the
+ * type of the default KeyStore installed in the system in lower case. <br>
+ * For example: if default KeyStore type in the system is BKS (i.e.
+ * java.security file sets up the property keystore.type=BKS), thus classpath
+ * should point to the directory with "key_store.bks" file. <br>
+ * This certstore file should contain self-signed certificate generated by
+ * keytool utility in a usual way. <br>
  * The password to the certstore should be "password" (without quotes).
  */
 public class HttpsURLConnectionTest extends TestCase {
@@ -121,11 +118,10 @@
     }
 
     /**
-     * Checks if HTTPS connection performs initial SSL handshake with the
-     * server working over SSL, sends encrypted HTTP request,
-     * and receives expected HTTP response. After HTTPS session if finished
-     * test checks connection state parameters established by
-     * HttpsURLConnection.
+     * Checks if HTTPS connection performs initial SSL handshake with the server
+     * working over SSL, sends encrypted HTTP request, and receives expected
+     * HTTP response. After HTTPS session if finished test checks connection
+     * state parameters established by HttpsURLConnection.
      */
     public void testHttpsConnection() throws Throwable {
         // set up the properties defining the default values needed by SSL stuff
@@ -161,13 +157,11 @@
     }
 
     /**
-     * Checks if HTTPS connection performs initial SSL handshake with the
-     * server working over SSL, sends encrypted HTTP request,
-     * and receives expected HTTP response. After that it checks that the
-     * established connection is persistent.
-     * After HTTPS session if finished
-     * test checks connection state parameters established by
-     * HttpsURLConnection.
+     * Checks if HTTPS connection performs initial SSL handshake with the server
+     * working over SSL, sends encrypted HTTP request, and receives expected
+     * HTTP response. After that it checks that the established connection is
+     * persistent. After HTTPS session if finished test checks connection state
+     * parameters established by HttpsURLConnection.
      */
     public void testHttpsPersistentConnection() throws Throwable {
         // set up the properties defining the default values needed by SSL stuff
@@ -189,7 +183,8 @@
                     .openConnection();
 
             // perform the interaction between the peers
-            SSLSocket peerSocket = (SSLSocket) doPersistentInteraction(connection, ss);
+            SSLSocket peerSocket = (SSLSocket) doPersistentInteraction(
+                    connection, ss);
 
             // check the connection state
             checkConnectionStateParameters(connection, peerSocket);
@@ -203,8 +198,8 @@
     }
 
     /**
-     * Tests the behaviour of HTTPS connection in case of unavailability
-     * of requested resource.
+     * Tests the behaviour of HTTPS connection in case of unavailability of
+     * requested resource.
      */
     public void testHttpsConnection_Not_Found_Response() throws Throwable {
         // set up the properties defining the default values needed by SSL stuff
@@ -244,8 +239,8 @@
     }
 
     /**
-     * Tests possibility to set up the default SSLSocketFactory
-     * to be used by HttpsURLConnection.
+     * Tests possibility to set up the default SSLSocketFactory to be used by
+     * HttpsURLConnection.
      */
     public void testSetDefaultSSLSocketFactory() throws Throwable {
         // create the SSLServerSocket which will be used by server side
@@ -293,8 +288,8 @@
     }
 
     /**
-     * Tests possibility to set up the SSLSocketFactory
-     * to be used by HttpsURLConnection.
+     * Tests possibility to set up the SSLSocketFactory to be used by
+     * HttpsURLConnection.
      */
     public void testSetSSLSocketFactory() throws Throwable {
         // create the SSLServerSocket which will be used by server side
@@ -340,8 +335,8 @@
     }
 
     /**
-     * Tests the behaviour of HttpsURLConnection in case of retrieving
-     * of the connection state parameters before connection has been made.
+     * Tests the behaviour of HttpsURLConnection in case of retrieving of the
+     * connection state parameters before connection has been made.
      */
     public void testUnconnectedStateParameters() throws Throwable {
         // create HttpsURLConnection to be tested
@@ -352,24 +347,29 @@
         try {
             connection.getCipherSuite();
             fail("Expected IllegalStateException was not thrown");
-        } catch (IllegalStateException e) {}
+        } catch (IllegalStateException e) {
+        }
         try {
             connection.getPeerPrincipal();
             fail("Expected IllegalStateException was not thrown");
-        } catch (IllegalStateException e) {}
+        } catch (IllegalStateException e) {
+        }
         try {
             connection.getLocalPrincipal();
             fail("Expected IllegalStateException was not thrown");
-        } catch (IllegalStateException e) {}
+        } catch (IllegalStateException e) {
+        }
 
         try {
             connection.getServerCertificates();
             fail("Expected IllegalStateException was not thrown");
-        } catch (IllegalStateException e) {}
+        } catch (IllegalStateException e) {
+        }
         try {
             connection.getLocalCertificates();
             fail("Expected IllegalStateException was not thrown");
-        } catch (IllegalStateException e) {}
+        } catch (IllegalStateException e) {
+        }
     }
 
     /**
@@ -450,8 +450,8 @@
     }
 
     /**
-     * Tests the behaviour in case of sending the data to the server 
-     * over persistent connection.
+     * Tests the behaviour in case of sending the data to the server over
+     * persistent connection.
      */
     public void testPersistence_doOutput() throws Throwable {
         // setting up the properties pointing to the key/trust stores
@@ -474,8 +474,8 @@
             connection.setDoOutput(true);
 
             // perform the interaction between the peers and check the results
-            SSLSocket peerSocket = (SSLSocket) 
-                doPersistentInteraction(connection, ss);
+            SSLSocket peerSocket = (SSLSocket) doPersistentInteraction(
+                    connection, ss);
             checkConnectionStateParameters(connection, peerSocket);
 
             // should silently exit
@@ -522,9 +522,9 @@
     }
 
     /**
-     * Tests HTTPS connection process made through the proxy server.
-     * Checks that persistent connection to the host exists and can
-     * be used no in spite of explicit Proxy specifying.
+     * Tests HTTPS connection process made through the proxy server. Checks that
+     * persistent connection to the host exists and can be used no in spite of
+     * explicit Proxy specifying.
      */
     public void testPersistentProxyConnection() throws Throwable {
         // setting up the properties pointing to the key/trust stores
@@ -547,7 +547,8 @@
                                     .getLocalPort())));
 
             // perform the interaction between the peers and check the results
-            SSLSocket peerSocket = (SSLSocket) doPersistentInteraction(connection, ss);
+            SSLSocket peerSocket = (SSLSocket) doPersistentInteraction(
+                    connection, ss);
             checkConnectionStateParameters(connection, peerSocket);
 
             // should silently exit
@@ -559,8 +560,8 @@
     }
 
     /**
-     * Tests HTTPS connection process made through the proxy server.
-     * Proxy server needs authentication.
+     * Tests HTTPS connection process made through the proxy server. Proxy
+     * server needs authentication.
      */
     public void testProxyAuthConnection() throws Throwable {
         // setting up the properties pointing to the key/trust stores
@@ -603,10 +604,9 @@
     }
 
     /**
-     * Tests HTTPS connection process made through the proxy server.
-     * 2 HTTPS connections are opened for one URL. For the first time
-     * the connection is opened through one proxy,
-     * for the second time through another.
+     * Tests HTTPS connection process made through the proxy server. 2 HTTPS
+     * connections are opened for one URL. For the first time the connection is
+     * opened through one proxy, for the second time through another.
      */
     public void testConsequentProxyConnection() throws Throwable {
         // setting up the properties pointing to the key/trust stores
@@ -649,9 +649,8 @@
     }
 
     /**
-     * Tests HTTPS connection process made through the proxy server.
-     * Proxy server needs authentication.
-     * Client sends data to the server.
+     * Tests HTTPS connection process made through the proxy server. Proxy
+     * server needs authentication. Client sends data to the server.
      */
     public void testProxyAuthConnection_doOutput() throws Throwable {
         // setting up the properties pointing to the key/trust stores
@@ -693,8 +692,8 @@
     }
 
     /**
-     * Tests HTTPS connection process made through the proxy server.
-     * Proxy server needs authentication but client fails to authenticate
+     * Tests HTTPS connection process made through the proxy server. Proxy
+     * server needs authentication but client fails to authenticate
      * (Authenticator was not set up in the system).
      */
     public void testProxyAuthConnectionFailed() throws Throwable {
@@ -734,8 +733,8 @@
     }
 
     /**
-     * Tests the behaviour of HTTPS connection in case of unavailability
-     * of requested resource.
+     * Tests the behaviour of HTTPS connection in case of unavailability of
+     * requested resource.
      */
     public void testProxyConnection_Not_Found_Response() throws Throwable {
         // setting up the properties pointing to the key/trust stores
@@ -789,8 +788,8 @@
     }
 
     /**
-     * Checks the HttpsURLConnection getter's values and compares
-     * them with actual corresponding values of remote peer.
+     * Checks the HttpsURLConnection getter's values and compares them with
+     * actual corresponding values of remote peer.
      */
     public static void checkConnectionStateParameters(
             HttpsURLConnection clientConnection, SSLSocket serverPeer)
@@ -819,11 +818,12 @@
     }
 
     /**
-     * Returns the file name of the key/trust store. The key store file
-     * (named as "key_store." + extension equals to the default KeyStore
-     * type installed in the system in lower case) is searched in classpath.
-     * @throws AssertionFailedError if property was not set
-     * or file does not exist.
+     * Returns the file name of the key/trust store. The key store file (named
+     * as "key_store." + extension equals to the default KeyStore type installed
+     * in the system in lower case) is searched in classpath.
+     * 
+     * @throws AssertionFailedError
+     *             if property was not set or file does not exist.
      */
     private static String getKeyStoreFileName() throws Exception {
         String ksFileName = "org/apache/harmony/luni/tests/key_store."
@@ -865,9 +865,9 @@
     }
 
     /**
-     * Sets up the properties pointing to the key store and trust store
-     * and used as default values by JSSE staff. This is needed to test
-     * HTTPS behaviour in the case of default SSL Socket Factories.
+     * Sets up the properties pointing to the key store and trust store and used
+     * as default values by JSSE staff. This is needed to test HTTPS behaviour
+     * in the case of default SSL Socket Factories.
      */
     private static void setUpStoreProperties() throws Exception {
         String type = KeyStore.getDefaultType();
@@ -935,19 +935,19 @@
     }
 
     /**
-     * Performs interaction between client's HttpURLConnection and
-     * servers side (ServerSocket).
+     * Performs interaction between client's HttpURLConnection and servers side
+     * (ServerSocket).
      */
     public static Socket doInteraction(
             final HttpURLConnection clientConnection,
             final ServerSocket serverSocket) throws Throwable {
-        return doInteraction(clientConnection, serverSocket, OK_CODE, false, false);
+        return doInteraction(clientConnection, serverSocket, OK_CODE, false,
+                false);
     }
 
     /**
-     * Performs interaction between client's HttpURLConnection and
-     * servers side (ServerSocket). Server will response with specified
-     * response code.
+     * Performs interaction between client's HttpURLConnection and servers side
+     * (ServerSocket). Server will response with specified response code.
      */
     public static Socket doInteraction(
             final HttpURLConnection clientConnection,
@@ -958,20 +958,20 @@
     }
 
     /**
-     * Performs interaction between client's HttpURLConnection and
-     * servers side (ServerSocket) over persistent connection.
+     * Performs interaction between client's HttpURLConnection and servers side
+     * (ServerSocket) over persistent connection.
      */
     public static Socket doPersistentInteraction(
             final HttpURLConnection clientConnection,
             final ServerSocket serverSocket) throws Throwable {
-        return doInteraction(clientConnection, serverSocket, OK_CODE,
-                false, true);
+        return doInteraction(clientConnection, serverSocket, OK_CODE, false,
+                true);
     }
 
     /**
-     * Performs interaction between client's HttpURLConnection and
-     * servers side (ServerSocket) over persistent connection.
-     * Server will response with specified response code.
+     * Performs interaction between client's HttpURLConnection and servers side
+     * (ServerSocket) over persistent connection. Server will response with
+     * specified response code.
      */
     public static Socket doPersistentInteraction(
             final HttpURLConnection clientConnection,
@@ -982,17 +982,17 @@
     }
 
     /**
-     * Performs interaction between client's HttpURLConnection and
-     * servers side (ServerSocket). Server will response with specified
-     * response code.
-     * @param doAuthentication specifies 
-     * if the server needs client authentication.
+     * Performs interaction between client's HttpURLConnection and servers side
+     * (ServerSocket). Server will response with specified response code.
+     * 
+     * @param doAuthentication
+     *            specifies if the server needs client authentication.
      */
     public static Socket doInteraction(
             final HttpURLConnection clientConnection,
             final ServerSocket serverSocket, final int responseCode,
-            final boolean doAuthentication, 
-            final boolean checkPersistence) throws Throwable {
+            final boolean doAuthentication, final boolean checkPersistence)
+            throws Throwable {
 
         // set up the connection
         clientConnection.setDoInput(true);
@@ -1023,9 +1023,9 @@
         }
 
         if (checkPersistence) {
-            ClientConnectionWork client2 =
-                new ClientConnectionWork((HttpURLConnection)
-                        clientConnection.getURL().openConnection());
+            ClientConnectionWork client2 = new ClientConnectionWork(
+                    (HttpURLConnection) clientConnection.getURL()
+                            .openConnection());
             client2.start();
             client2.join();
             if (client2.thrown != null) {
@@ -1128,8 +1128,8 @@
         protected Throwable thrown;
 
         /**
-         * The print stream used for debug log.
-         * If it is null debug info will not be printed.
+         * The print stream used for debug log. If it is null debug info will
+         * not be printed.
          */
         private PrintStream out = new PrintStream(System.out);
 
@@ -1177,10 +1177,13 @@
 
         /**
          * Creates the thread acting as a server side.
-         * @param serverSocket the server socket to be used during connection
-         * @param responseCode the response code to be sent to the client
+         * 
+         * @param serverSocket
+         *            the server socket to be used during connection
+         * @param responseCode
+         *            the response code to be sent to the client
          * @param needProxyAuthentication
-         * indicates if the server needs proxy authentication
+         *            indicates if the server needs proxy authentication
          */
         public ServerWork(ServerSocket serverSocket, int responseCode,
                 boolean needProxyAuthentication, boolean checkPersistence) {
@@ -1208,19 +1211,21 @@
         public void closeSocket(Socket socket) {
             try {
                 socket.getInputStream().close();
-            } catch (IOException e) {}
+            } catch (IOException e) {
+            }
             try {
                 socket.getOutputStream().close();
-            } catch (IOException e) {}
+            } catch (IOException e) {
+            }
             try {
                 socket.close();
-            } catch (IOException e) {}
+            } catch (IOException e) {
+            }
         }
 
         /**
-         * Performs the actual server work.
-         * If some exception occurs during the work it will be
-         * stored in the <code>thrown</code> field.
+         * Performs the actual server work. If some exception occurs during the
+         * work it will be stored in the <code>thrown</code> field.
          */
         public void run() {
             // the buffer used for reading the messages
@@ -1241,10 +1246,11 @@
 
                 // how many times established connection will be used
                 int number_of_uses = checkPersistence ? 2 : 1;
-                for (int it=0; it<number_of_uses; it++) {
+                for (int it = 0; it < number_of_uses; it++) {
                     if (checkPersistence) {
                         log("==========================================");
-                        log("Use established connection for "+(it+1)+" time");
+                        log("Use established connection for " + (it + 1)
+                                + " time");
                     }
 
                     num = is.read(buff);
@@ -1264,8 +1270,9 @@
                             assertEquals(clientsData, message);
                         }
                         // just send the response
-                        os.write(("HTTP/1.1 " + responseCode + "\n" 
-                                    + httpsResponseTail).getBytes());
+                        os
+                                .write(("HTTP/1.1 " + responseCode + "\n" + httpsResponseTail)
+                                        .getBytes());
                         log("Simple NON-Proxy work is DONE");
                         continue;
                     }
@@ -1278,7 +1285,7 @@
                         // read response
                         num = is.read(buff);
                         if (num == -1) {
-                            // this connection was closed, 
+                            // this connection was closed,
                             // do clean up and create new one:
                             closeSocket(peerSocket);
                             peerSocket = serverSocket.accept();
@@ -1293,20 +1300,22 @@
                         log("------------------");
                         // check provided authorization credentials
                         assertTrue("Received message does not contain "
-                                + "authorization credentials", message
-                                .toLowerCase().indexOf("proxy-authorization:") > 0);
+                                + "authorization credentials",
+                                message.toLowerCase().indexOf(
+                                        "proxy-authorization:") > 0);
                     }
 
                     if (peerSocket instanceof SSLSocket) {
-                        // it will be so if we are have second iteration 
+                        // it will be so if we are have second iteration
                         // over persistent connection
-                        os.write(("HTTP/1.1 " + OK_CODE
-                                    + "\n" + httpsResponseTail).getBytes());
+                        os
+                                .write(("HTTP/1.1 " + OK_CODE + "\n" + httpsResponseTail)
+                                        .getBytes());
                         log("Sent OK RESPONSE over SSL");
                     } else {
                         // The content of this response will reach proxied
                         // HTTPUC but will not reach proxied HTTPSUC
-                        // In case of HTTP connection it will be the final 
+                        // In case of HTTP connection it will be the final
                         // message, in case of HTTPS connection this message
                         // will just indicate that connection with remote
                         // host has been done
@@ -1315,12 +1324,15 @@
                         log("Sent OK RESPONSE");
                     }
 
-                    if (message.startsWith("CONNECT")) { // request for SSL tunnel
+                    if (message.startsWith("CONNECT")) { // request for SSL
+                                                            // tunnel
                         log("Perform SSL Handshake...");
                         // create sslSocket acting as a remote server peer
                         SSLSocket sslSocket = (SSLSocket) getContext()
-                                .getSocketFactory().createSocket(peerSocket,
-                                        "localhost", peerSocket.getPort(), true); // do autoclose
+                                .getSocketFactory()
+                                .createSocket(peerSocket, "localhost",
+                                        peerSocket.getPort(), true); // do
+                                                                        // autoclose
                         sslSocket.setUseClientMode(false);
                         // demand client authentication
                         sslSocket.setNeedClientAuth(true);
@@ -1333,7 +1345,8 @@
                         // (HTTPS request)
                         num = is.read(buff);
                         message = new String(buff, 0, num);
-                        log("[Remote Server] Request from SSL tunnel:\n" + message);
+                        log("[Remote Server] Request from SSL tunnel:\n"
+                                + message);
                         log("------------------");
 
                         if (message.startsWith("POST")) {
@@ -1341,18 +1354,21 @@
                             log("[Remote Server] try to read client data");
                             num = is.read(buff);
                             message = new String(buff, 0, num);
-                            log("[Remote Server] client's data: '" + message + "'");
+                            log("[Remote Server] client's data: '" + message
+                                    + "'");
                             // check the received data
                             assertEquals(clientsData, message);
                         }
 
                         log("[Remote Server] Sending the response by SSL tunnel..");
                         // send the response with specified response code
-                        os.write(("HTTP/1.1 " + responseCode 
-                                    + "\n" + httpsResponseTail).getBytes());
+                        os
+                                .write(("HTTP/1.1 " + responseCode + "\n" + httpsResponseTail)
+                                        .getBytes());
                     }
                     log("Work is DONE");
-                };
+                }
+                ;
             } catch (Throwable e) {
                 if (DO_LOG) {
                     e.printStackTrace();
@@ -1362,14 +1378,15 @@
                 closeSocket(peerSocket);
                 try {
                     serverSocket.close();
-                } catch (IOException e) {}
+                } catch (IOException e) {
+                }
             }
         }
     }
 
     /**
-     * The class used for client side works. It could be used to test
-     * both HttpURLConnection and HttpsURLConnection.
+     * The class used for client side works. It could be used to test both
+     * HttpURLConnection and HttpsURLConnection.
      */
     static class ClientConnectionWork extends Work {
 
@@ -1378,7 +1395,9 @@
 
         /**
          * Creates the thread acting as a client side.
-         * @param connection connection to be used to contact the server side
+         * 
+         * @param connection
+         *            connection to be used to contact the server side
          */
         public ClientConnectionWork(HttpURLConnection connection) {
             this.connection = connection;
@@ -1387,9 +1406,8 @@
         }
 
         /**
-         * Performs the actual client work.
-         * If some exception occurs during the work it will be
-         * stored in the <code>thrown<code> field.
+         * Performs the actual client work. If some exception occurs during the
+         * work it will be stored in the <code>thrown<code> field.
          */
         public void run() {
             try {
@@ -1403,7 +1421,7 @@
                 }
                 // read the content of HTTP(s) response
                 InputStream is = connection.getInputStream();
-                log("Input Stream obtained: "+is.getClass());
+                log("Input Stream obtained: " + is.getClass());
                 byte[] buff = new byte[2048];
                 int num = 0;
                 int byt = 0;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayInputStreamTest.java?rev=612569&r1=612568&r2=612569&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayInputStreamTest.java Wed Jan 16 12:56:03 2008
@@ -19,190 +19,160 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 
 public class ByteArrayInputStreamTest extends junit.framework.TestCase {
 
-	private java.io.InputStream is;
+    private InputStream is;
 
-	public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
+    public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
 
-	/**
-	 * @tests java.io.ByteArrayInputStream#ByteArrayInputStream(byte[])
-	 */
-	public void test_Constructor$B() throws Exception {
-		// Test for method java.io.ByteArrayInputStream(byte [])
-		java.io.InputStream bis = new java.io.ByteArrayInputStream(fileString
-				.getBytes());
-
-		assertTrue("Unable to create ByteArrayInputStream",
-				bis.available() == fileString.length());
-	}
-
-	/**
-	 * @throws IOException 
-	 * @tests java.io.ByteArrayInputStream#ByteArrayInputStream(byte[], int,
-	 *        int)
-	 */
-	public void test_Constructor$BII() throws IOException {
-		// Test for method java.io.ByteArrayInputStream(byte [], int, int)
-
-		byte[] zz = fileString.getBytes();
-		java.io.InputStream bis = new java.io.ByteArrayInputStream(zz, 0, 100);
-
-		assertEquals("Unable to create ByteArrayInputStream",
-				100, bis.available());
-		
-		// Regression test for Harmony-2405
-		new SubByteArrayInputStream(new byte[] { 1, 2 }, 444, 13);
-		assertEquals(444, SubByteArrayInputStream.pos);
-		assertEquals(444, SubByteArrayInputStream.mark);
-		assertEquals(2, SubByteArrayInputStream.count);
-	}
-	
-	static class SubByteArrayInputStream extends ByteArrayInputStream {
-		public static byte[] buf;
-
-		public static int mark, pos, count;
-
-		SubByteArrayInputStream(byte[] buf, int offset, int length)
-				throws IOException {
-			super(buf, offset, length);
-			buf = super.buf;
-			mark = super.mark;
-			pos = super.pos;
-			count = super.count;
-		}
-	}
-
-	/**
-	 * @tests java.io.ByteArrayInputStream#available()
-	 */
-	public void test_available() throws Exception {
-		// Test for method int java.io.ByteArrayInputStream.available()
-                assertTrue("Returned incorrect number of available bytes", is
-                           .available() == fileString.length());
-	}
-
-	/**
-	 * @tests java.io.ByteArrayInputStream#close()
-	 */
-	public void test_close() {
-		// Test for method void java.io.ByteArrayInputStream.close()
-		try {
-			is.read();
-		} catch (java.io.IOException e) {
-			fail("Failed reading from input stream");
-		}
-		try {
-			is.close();
-		} catch (java.io.IOException e) {
-			fail("Failed closing input stream");
-		}
-		try {
-			is.read();
-		} catch (Exception e) {
-			fail("Should be able to read from closed stream");
-		}
-	}
-
-	/**
-	 * @tests java.io.ByteArrayInputStream#mark(int)
-	 */
-	public void test_markI() throws Exception {
-		// Test for method void java.io.ByteArrayInputStream.mark(int)
-		byte[] buf1 = new byte[100];
-		byte[] buf2 = new byte[100];
-                is.skip(3000);
-                is.mark(1000);
-                is.read(buf1, 0, buf1.length);
-                is.reset();
-                is.read(buf2, 0, buf2.length);
-                is.reset();
-                assertTrue("Failed to mark correct position", new String(buf1, 0,
-                                buf1.length).equals(new String(buf2, 0, buf2.length)));
-	}
-
-	/**
-	 * @tests java.io.ByteArrayInputStream#markSupported()
-	 */
-	public void test_markSupported() {
-		// Test for method boolean java.io.ByteArrayInputStream.markSupported()
-		assertTrue("markSupported returned incorrect value", is.markSupported());
-	}
-
-	/**
-	 * @tests java.io.ByteArrayInputStream#read()
-	 */
-	public void test_read() throws Exception {
-		// Test for method int java.io.ByteArrayInputStream.read()
-                int c = is.read();
-                is.reset();
-                assertTrue("read returned incorrect char", c == fileString
-                                .charAt(0));
-	}
-
-	/**
-	 * @tests java.io.ByteArrayInputStream#read(byte[], int, int)
-	 */
-	public void test_read$BII() throws Exception {
-		// Test for method int java.io.ByteArrayInputStream.read(byte [], int,
-		// int)
-		byte[] buf1 = new byte[20];
-                is.skip(50);
-                is.mark(100);
-                is.read(buf1, 0, buf1.length);
-                assertTrue("Failed to read correct data", new String(buf1, 0,
-                                buf1.length).equals(fileString.substring(50, 70)));
-	}
-
-	/**
-	 * @tests java.io.ByteArrayInputStream#reset()
-	 */
-	public void test_reset() throws Exception {
-		// Test for method void java.io.ByteArrayInputStream.reset()
-		byte[] buf1 = new byte[10];
-		byte[] buf2 = new byte[10];
-                is.mark(200);
-                is.read(buf1, 0, 10);
-                is.reset();
-                is.read(buf2, 0, 10);
-                is.reset();
-                assertTrue("Reset failed", new String(buf1, 0, buf1.length)
-                                .equals(new String(buf2, 0, buf2.length)));
-	}
-
-	/**
-	 * @tests java.io.ByteArrayInputStream#skip(long)
-	 */
-	public void test_skipJ() throws Exception {
-		// Test for method long java.io.ByteArrayInputStream.skip(long)
-		byte[] buf1 = new byte[10];
-                is.skip(100);
-                is.read(buf1, 0, buf1.length);
-                assertTrue("Failed to skip to correct position", new String(buf1,
-                                0, buf1.length).equals(fileString.substring(100, 110)));
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-
-		is = new java.io.ByteArrayInputStream(fileString.getBytes());
-
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-
-		try {
-			is.close();
-
-		} catch (Exception e) {
-		}
-	}
+    /**
+     * @tests ByteArrayInputStream#ByteArrayInputStream(byte[])
+     */
+    public void test_Constructor$B() throws IOException {
+        InputStream bis = new ByteArrayInputStream(fileString.getBytes());
+
+        assertTrue("Unable to create ByteArrayInputStream",
+                bis.available() == fileString.length());
+    }
+
+    /**
+     * @tests ByteArrayInputStream#ByteArrayInputStream(byte[], int, int)
+     */
+    public void test_Constructor$BII() throws IOException {
+        byte[] zz = fileString.getBytes();
+        InputStream bis = new ByteArrayInputStream(zz, 0, 100);
+
+        assertEquals("Unable to create ByteArrayInputStream", 100, bis
+                .available());
+
+        // Regression test for Harmony-2405
+        new SubByteArrayInputStream(new byte[] { 1, 2 }, 444, 13);
+        assertEquals(444, SubByteArrayInputStream.pos);
+        assertEquals(444, SubByteArrayInputStream.mark);
+        assertEquals(2, SubByteArrayInputStream.count);
+    }
+
+    static class SubByteArrayInputStream extends ByteArrayInputStream {
+        public static byte[] buf;
+
+        public static int mark, pos, count;
+
+        SubByteArrayInputStream(byte[] buf, int offset, int length)
+                throws IOException {
+            super(buf, offset, length);
+            buf = super.buf;
+            mark = super.mark;
+            pos = super.pos;
+            count = super.count;
+        }
+    }
+
+    /**
+     * @tests ByteArrayInputStream#available()
+     */
+    public void test_available() throws IOException {
+        assertTrue("Returned incorrect number of available bytes", is
+                .available() == fileString.length());
+    }
+
+    /**
+     * @tests ByteArrayInputStream#close()
+     */
+    public void test_close() throws IOException {
+        is.read();
+        is.close();
+        is.read(); // Should be able to read from a closed stream
+    }
+
+    /**
+     * @tests ByteArrayInputStream#mark(int)
+     */
+    public void test_markI() throws IOException {
+        byte[] buf1 = new byte[100];
+        byte[] buf2 = new byte[100];
+        is.skip(3000);
+        is.mark(1000);
+        is.read(buf1, 0, buf1.length);
+        is.reset();
+        is.read(buf2, 0, buf2.length);
+        is.reset();
+        assertTrue("Failed to mark correct position", new String(buf1, 0,
+                buf1.length).equals(new String(buf2, 0, buf2.length)));
+    }
+
+    /**
+     * @tests ByteArrayInputStream#markSupported()
+     */
+    public void test_markSupported() {
+        assertTrue("markSupported returned incorrect value", is.markSupported());
+    }
+
+    /**
+     * @tests ByteArrayInputStream#read()
+     */
+    public void test_read() throws IOException {
+        int c = is.read();
+        is.reset();
+        assertTrue("read returned incorrect char", c == fileString.charAt(0));
+    }
+
+    /**
+     * @tests ByteArrayInputStream#read(byte[], int, int)
+     */
+    public void test_read$BII() throws IOException {
+        byte[] buf1 = new byte[20];
+        is.skip(50);
+        is.mark(100);
+        is.read(buf1, 0, buf1.length);
+        assertTrue("Failed to read correct data", new String(buf1, 0,
+                buf1.length).equals(fileString.substring(50, 70)));
+    }
+
+    /**
+     * @tests ByteArrayInputStream#reset()
+     */
+    public void test_reset() throws IOException {
+        byte[] buf1 = new byte[10];
+        byte[] buf2 = new byte[10];
+        is.mark(200);
+        is.read(buf1, 0, 10);
+        is.reset();
+        is.read(buf2, 0, 10);
+        is.reset();
+        assertTrue("Reset failed", new String(buf1, 0, buf1.length)
+                .equals(new String(buf2, 0, buf2.length)));
+    }
+
+    /**
+     * @tests ByteArrayInputStream#skip(long)
+     */
+    public void test_skipJ() throws IOException {
+        byte[] buf1 = new byte[10];
+        is.skip(100);
+        is.read(buf1, 0, buf1.length);
+        assertTrue("Failed to skip to correct position", new String(buf1, 0,
+                buf1.length).equals(fileString.substring(100, 110)));
+    }
+
+    /**
+     * Sets up the fixture, for example, open a network connection. This method
+     * is called before a test is executed.
+     */
+    protected void setUp() {
+        is = new ByteArrayInputStream(fileString.getBytes());
+
+    }
+
+    /**
+     * Tears down the fixture, for example, close a network connection. This
+     * method is called after a test is executed.
+     */
+    protected void tearDown() {
+        try {
+            is.close();
+        } catch (Exception e) {
+        }
+    }
 }