harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject svn commit: r620812 - in /harmony/enhanced/classlib/trunk/modules/beans/src/test: java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java resources/binary/java/beans/mock/TestClassEditor.bin
Date Tue, 12 Feb 2008 14:11:11 GMT
Author: vmz
Date: Tue Feb 12 06:11:08 2008
New Revision: 620812

URL: http://svn.apache.org/viewvc?rev=620812&view=rev
Log:
HARMONY-5477 [classlib][beans][geronimo] PropertyEditorManager.findEditor() uses wrong classloader
Regression test added
Also added TestClassEditor.bin file which is needed for test and is a class file for:

package testPackage;
public class TestClassEditor extends java.beans.PropertyEditorSupport {
}

Added:
    harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/binary/java/beans/mock/TestClassEditor.bin
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java?rev=620812&r1=620811&r2=620812&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
Tue Feb 12 06:11:08 2008
@@ -20,6 +20,8 @@
 import java.awt.Color;
 import java.beans.PropertyEditor;
 import java.beans.PropertyEditorManager;
+import java.io.InputStream;
+import java.io.IOException;
 
 import junit.framework.TestCase;
 
@@ -30,6 +32,11 @@
 
     static String origPath[] = PropertyEditorManager.getEditorSearchPath();
 
+    private final String MOCK_TEST_CLASS_EDITOR = "testPackage.TestClassEditor";
+
+    private final String MOCK_TEST_CLASS_EDITOR_FILE
+            = "binary/java/beans/mock/TestClassEditor.bin";
+
     public void testFindEditorAccordingPath_1() throws Exception {
         // Regression Harmony-1205
         String newPath[] = new String[origPath.length + 1];
@@ -64,6 +71,42 @@
                 editor.getClass());
     }
 
+    public void testFindEditorAccordingPath_3() throws Exception {
+        // Regression Harmony-5477
+        class TestClassLoader extends ClassLoader {
+            protected Class<?> findClass(String name) throws ClassNotFoundException
{
+                if (!MOCK_TEST_CLASS_EDITOR.equals(name)) {
+                    throw new ClassNotFoundException(name);
+                }
+
+                try {
+                    byte[] buf = new byte[1024];
+                    InputStream in = getResourceAsStream(MOCK_TEST_CLASS_EDITOR_FILE);
+                    int sz = 0;
+                    int read;
+
+                    while ((read = in.read(buf, sz, buf.length - sz)) >= 0) {
+                        sz += read;
+                    }
+                    return defineClass(MOCK_TEST_CLASS_EDITOR, buf, 0, sz);
+                } catch (IOException e) {
+                    throw (ClassNotFoundException) new ClassNotFoundException(
+                            e.getMessage()).initCause(e);
+                }
+            }
+        }
+        PropertyEditorManager.setEditorSearchPath(new String[] { "testPackage" });
+        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+
+        try {
+            Thread.currentThread().setContextClassLoader(new TestClassLoader());
+            PropertyEditor editor = PropertyEditorManager.findEditor(TestClass.class);
+            assertEquals(MOCK_TEST_CLASS_EDITOR, editor.getClass().getName());
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldLoader);
+        }
+    }
+
     public void testStringEditor() throws Exception {
         // Regression Harmony-1199
         PropertyEditorManager.setEditorSearchPath(origPath);
@@ -75,7 +118,7 @@
         assertEquals(text, editor.getAsText());
     }
     
-    // Regression for HARMONY-4062
+    // Regression Harmony-4062
     public void testColorEditor() {
         PropertyEditor propertyEditor = PropertyEditorManager
                 .findEditor(Color.class);
@@ -105,6 +148,7 @@
             //expected.
         }
     }
+
     String[] defaultSearchPath;
     
     public void setUp(){
@@ -115,3 +159,5 @@
         PropertyEditorManager.setEditorSearchPath(defaultSearchPath);
     }
 }
+
+class TestClass {}

Added: harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/binary/java/beans/mock/TestClassEditor.bin
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/binary/java/beans/mock/TestClassEditor.bin?rev=620812&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/binary/java/beans/mock/TestClassEditor.bin
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message