harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r409403 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test: java/tests/api/java/net/ resources/serialization/java/net/
Date Thu, 25 May 2006 14:42:15 GMT
Author: mloenko
Date: Thu May 25 07:42:15 2006
New Revision: 409403

URL: http://svn.apache.org/viewvc?rev=409403&view=rev
Log:
serialization tests from HARMONY-495
Java 5 Enhancement: serialization tests for java.net.InetAddress, java.net.Inet4Address, java.net.HttpRetryException

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpRetryExceptionTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/HttpRetryExceptionTest.golden.ser
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/Inet4AddressTest.golden.ser
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/InetAddressTest.golden.ser
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet4AddressTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java?rev=409403&r1=409402&r2=409403&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
Thu May 25 07:42:15 2006
@@ -66,6 +66,9 @@
 		suite.addTestSuite(URLConnectionTest.class);
 		suite.addTestSuite(URLDecoderTest.class);
 		suite.addTestSuite(URLEncoderTest.class);
+        suite.addTestSuite(HttpRetryExceptionTest.class);
+        suite.addTestSuite(Inet4AddressTest.class);
+        suite.addTestSuite(InetAddressTest.class);
 		// $JUnit-END$
 		return suite;
 	}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpRetryExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpRetryExceptionTest.java?rev=409403&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpRetryExceptionTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpRetryExceptionTest.java
Thu May 25 07:42:15 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package tests.api.java.net;
+
+import java.net.HttpRetryException;
+import tests.util.SerializationTester;
+import junit.framework.TestCase;
+
+public class HttpRetryExceptionTest extends TestCase {
+
+    private static final String SERIALIZATION_FILE_NAME = "serialization/java/net/HttpRetryExceptionTest.golden.ser";
//$NON-NLS-1$
+
+    private static final String LOCATION = "Http test"; //$NON-NLS-1$
+
+    private static final String DETAIL = "detail"; //$NON-NLS-1$
+
+    /**
+     * @tests serialization/deserilazation.
+     */
+    public void testSerialization() throws Exception {
+        HttpRetryException ia = new HttpRetryException(DETAIL, 100, LOCATION);
+
+        HttpRetryException deIA = (HttpRetryException) SerializationTester
+                .getDeserilizedObject(ia);
+
+        assertEquals(LOCATION, deIA.getLocation());
+        assertEquals(100, deIA.responseCode());
+        assertEquals(DETAIL, deIA.getReason());
+        assertEquals(DETAIL, deIA.getMessage());
+    }
+
+    /**
+     * @tests serialization/deserilazation compatibility with RI.
+     */
+    public void testSerializationCompatibility() throws Exception {
+        HttpRetryException ia = new HttpRetryException(DETAIL, 100, LOCATION);
+        HttpRetryException deIA = (HttpRetryException) SerializationTester
+                .readObject(ia, SERIALIZATION_FILE_NAME);
+        assertEquals(LOCATION, deIA.getLocation());
+        assertEquals(100, deIA.responseCode());
+        assertEquals(DETAIL, deIA.getReason());
+        assertEquals(DETAIL, deIA.getMessage());
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet4AddressTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet4AddressTest.java?rev=409403&r1=409402&r2=409403&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet4AddressTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet4AddressTest.java
Thu May 25 07:42:15 2006
@@ -1,4 +1,4 @@
-/* Copyright 2003, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2003, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,10 +15,15 @@
 
 package tests.api.java.net;
 
+import java.net.Inet4Address;
 import java.net.InetAddress;
 
+import tests.util.SerializationTester;
+
 public class Inet4AddressTest extends junit.framework.TestCase {
 
+    private static final String SERIALIZATION_FILE_NAME = "serialization/java/net/Inet4AddressTest.golden.ser";
+    
 	/**
 	 * @tests java.net.Inet4Address#isMulticastAddress()
 	 */
@@ -355,10 +360,38 @@
 			fail("Unknown address : " + addrName);
 		}
 	}
-
-	protected void setUp() {
-	}
-
-	protected void tearDown() {
-	}
+    
+    
+    /*
+    * Test serialization/deserilazation.
+    */
+   public void testSerialization() throws Exception {
+       InetAddress ia= Inet4Address.getByName("localhost");
+       InetAddress deIA = (Inet4Address) SerializationTester
+               .getDeserilizedObject(ia);
+       byte[] iaAddresss= ia.getAddress();
+       byte[] deIAAddresss= deIA.getAddress();
+       for (int i = 0; i < iaAddresss.length; i++) {
+           assertEquals(iaAddresss[i], deIAAddresss[i]);
+       } 
+       assertEquals(4, iaAddresss.length);
+       assertEquals(ia.getHostName(), deIA.getHostName());
+   }
+
+   /*
+    * Test serialization/deserilazation compatibility with RI.
+    */
+   public void testSerializationCompatibility() throws Exception {
+       InetAddress ia= Inet4Address.getByName("localhost");
+       InetAddress deIA = (Inet4Address) SerializationTester
+               .readObject(ia,
+                       SERIALIZATION_FILE_NAME);
+       byte[] iaAddresss= ia.getAddress();
+       byte[] deIAAddresss= deIA.getAddress();
+       for (int i = 0; i < iaAddresss.length; i++) {
+           assertEquals(iaAddresss[i], deIAAddresss[i]);
+       } 
+       assertEquals(4, iaAddresss.length);
+       assertEquals(ia.getHostName(), deIA.getHostName());
+   }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java?rev=409403&r1=409402&r2=409403&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java
Thu May 25 07:42:15 2006
@@ -18,15 +18,15 @@
 import java.net.DatagramSocket;
 import java.net.Inet4Address;
 import java.net.InetAddress;
-import java.net.NetworkInterface;
 import java.net.UnknownHostException;
 import java.security.Permission;
 
-import junit.framework.AssertionFailedError;
-
 import tests.support.Support_Configuration;
+import tests.util.SerializationTester;
 
 public class InetAddressTest extends junit.framework.TestCase {
+    
+    private static final String SERIALIZATION_FILE_NAME = "serialization/java/net/InetAddressTest.golden.ser";
 
 	private static boolean someoneDone[] = new boolean[2];
 
@@ -173,7 +173,8 @@
 		}
 
 		// check the getByName if there is a security manager.
-		System.setSecurityManager(new SecurityManager());
+        SecurityManager oldman = System.getSecurityManager();
+		System.setSecurityManager(new MockSecurityManager());
 		try {
 			boolean exception = false;
 			try {
@@ -185,7 +186,7 @@
 			}
 			assertTrue("expected SecurityException", exception);
 		} finally {
-			System.setSecurityManager(null);
+			System.setSecurityManager(oldman);
 		}
 	}
 
@@ -246,9 +247,10 @@
 		// Test for any of the host lookups, where the default SecurityManager
 		// is installed.
 
+        SecurityManager oldman = System.getSecurityManager();
 		try {
 			String exp = Support_Configuration.InetTestIP;
-			System.setSecurityManager(new SecurityManager());
+			System.setSecurityManager(new MockSecurityManager());
 			InetAddress ia = InetAddress.getByName(exp);
 			String ans = ia.getHostName();
 			assertTrue("usingSecurityManager failed, ans: " + ans + " exp: "
@@ -258,7 +260,7 @@
 			fail("Exception during usingSecurityManager test : "
 					+ e.getMessage());
 		} finally {
-			System.setSecurityManager(null);
+			System.setSecurityManager(oldman);
 		}
 
 		// Make sure there is no caching
@@ -491,29 +493,47 @@
         ia = Inet4Address.getByName("1.1.1.1");
         assertFalse(ia.isReachable(1000));
         assertFalse(ia.isReachable(null, 0, 1000));
-        // tests www.apache.org
-        try {
-            ia = InetAddress.getByName("www.apache.org");//$NON-NLS-1$
-            assertTrue(ia.isReachable(10000));
-            assertTrue(ia.isReachable(NetworkInterface.getByName("eth0"), 0,
-                    10000));
-        } catch (AssertionFailedError e) {
-            System.err
-                    .println("isReachableLjava_net_NetworkInterfaceII test may fail for network
issue, please check.");
-        } 
     } 
 
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
+    /*
+     * Test serialization/deserilazation.
+     */
+    public void testSerialization() throws Exception {
+        InetAddress ia= InetAddress.getByName("localhost");
+        InetAddress deIA = (InetAddress) SerializationTester
+                .getDeserilizedObject(ia);
+        byte[] iaAddresss= ia.getAddress();
+        byte[] deIAAddresss= deIA.getAddress();
+        for (int i = 0; i < iaAddresss.length; i++) {
+            assertEquals(iaAddresss[i], deIAAddresss[i]);
+        }        
+        assertEquals(ia.getHostName(), deIA.getHostName());
+    }
 
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-	}
+    /*
+     * Test serialization/deserilazation compatibility with RI.
+     */
+    public void testSerializationCompatibility() throws Exception {
+        InetAddress ia= InetAddress.getByName("localhost");
+        // the ser file was serialized by InetAddress.getByName("localhost");
+        InetAddress deIA = (InetAddress) SerializationTester
+                .readObject(ia,
+                        SERIALIZATION_FILE_NAME);
+        byte[] iaAddresss= ia.getAddress();
+        byte[] deIAAddresss= deIA.getAddress();
+        for (int i = 0; i < iaAddresss.length; i++) {
+            assertEquals(iaAddresss[i], deIAAddresss[i]);
+        } 
+        assertEquals(ia.getHostName(), deIA.getHostName());
+    }
+    
+    
+    class MockSecurityManager extends SecurityManager {        
+        public void checkPermission(Permission permission) {
+            if (permission.getName().equals("setSecurityManager")){
+                return;
+            }
+            super.checkPermission(permission);
+        }
+    }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/HttpRetryExceptionTest.golden.ser
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/HttpRetryExceptionTest.golden.ser?rev=409403&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/HttpRetryExceptionTest.golden.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/Inet4AddressTest.golden.ser
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/Inet4AddressTest.golden.ser?rev=409403&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/Inet4AddressTest.golden.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/InetAddressTest.golden.ser
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/InetAddressTest.golden.ser?rev=409403&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/java/net/InetAddressTest.golden.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message