You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/11/19 01:30:03 UTC

svn commit: r476666 - in /beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit: beaninfo/BeanInfoTest.java inherit/InheritTest.java utils/ControlIntrospector.java utils/ControlTestUtils.java

Author: ekoneil
Date: Sat Nov 18 16:30:02 2006
New Revision: 476666

URL: http://svn.apache.org/viewvc?view=rev&rev=476666
Log:
Fix the control tests which are failing on win32 with "native" line endings on the beaninfo files.  The ControlIntrospector wrote "\n" line endings independent of platform which caused problems for Windows.

This change also consolidates the beaninfo diff routines into a single utility method in ControlTestUtils.

This fix needs to be integ'ed into branches/v1.0.2.

Test: Controls pass


Modified:
    beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/beaninfo/BeanInfoTest.java
    beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/inherit/InheritTest.java
    beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlIntrospector.java
    beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlTestUtils.java

Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/beaninfo/BeanInfoTest.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/beaninfo/BeanInfoTest.java?view=diff&rev=476666&r1=476665&r2=476666
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/beaninfo/BeanInfoTest.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/beaninfo/BeanInfoTest.java Sat Nov 18 16:30:02 2006
@@ -19,15 +19,16 @@
 
 package org.apache.beehive.controls.test.junit.beaninfo;
 
-import junit.framework.TestCase;
-import org.apache.beehive.controls.test.controls.beaninfo.InfoTestBean;
-import org.apache.beehive.controls.test.junit.utils.ControlIntrospector;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 
+import junit.framework.TestCase;
+import org.apache.beehive.controls.test.controls.beaninfo.InfoTestBean;
+import org.apache.beehive.controls.test.junit.utils.ControlTestUtils;
+
+
 /**
  * A TestCase that tests generated BeanInfo
  * <p/>
@@ -40,42 +41,11 @@
 
     public void testBeanInfo() throws Exception {
 
-        File tempFile = null;
-        FileOutputStream fos = null;
-        try {
-            tempFile = File.createTempFile("InfoTestBean", ".beaninfo");
-            fos = new FileOutputStream(tempFile);
-            ControlIntrospector ci = new ControlIntrospector(InfoTestBean.class, fos);
-            ci.introspect();
-        }
-        finally {
-            if (fos != null)
-                fos.close();
-        }
-
-        InputStream valid = null;
-        InputStream current = null;
-        try {
-            valid = this.getClass().getClassLoader().getResourceAsStream(BEANINFO);
-            assertNotNull(valid);
-
-            current = new FileInputStream(tempFile);
-            int validVal;
-            int currentVal;
-            do {
-                validVal = valid.read();
-                currentVal = current.read();
-                assertEquals(validVal, currentVal);
-            } while (validVal != -1);
-        }
-        finally {
-            if (current != null)
-                current.close();
-            if (valid != null)
-                valid.close();
-        }
-
-        // Pass, so remove the temporary output file
-        tempFile.delete();
+	File tempFile = File.createTempFile(getClass().getSimpleName(), ".beaninfo");
+	boolean same = ControlTestUtils.compareBeanInfo(BEANINFO, tempFile, InfoTestBean.class);
+	
+	if(!same) 
+	    fail("Generated beaninfo file " + tempFile + " differs from expected beaninfo " + BEANINFO + " in classloader");
+	else tempFile.delete();
     }
 }

Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/inherit/InheritTest.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/inherit/InheritTest.java?view=diff&rev=476666&r1=476665&r2=476666
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/inherit/InheritTest.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/inherit/InheritTest.java Sat Nov 18 16:30:02 2006
@@ -19,20 +19,19 @@
 
 package org.apache.beehive.controls.test.junit.inherit;
 
-import junit.framework.TestCase;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.FileInputStream;
 
-import org.apache.beehive.controls.test.junit.utils.ControlIntrospector;
+import junit.framework.TestCase;
+import org.apache.beehive.controls.test.junit.utils.ControlTestUtils;
 
 /**
  * A TestCase that tests control interface, extension, and implementation inheritance
  */
-public class InheritTest extends TestCase
-{
+public class InheritTest extends TestCase {
+
     /**
      * Verifies the generated BeanInfo for Intf1
      */
@@ -61,10 +60,20 @@
         validateBeanInfo("Ext2Bean");
     }
 
-    private void validateBeanInfo(String shortName) throws Exception {
+    private void validateBeanInfo(String simpleName) 
+	throws Exception {
 
-        String beanClassName = "org.apache.beehive.controls.test.controls.inherit." + shortName;
-        String beanInfo = "org/apache/beehive/controls/test/junit/inherit/" + shortName + ".beaninfo";
+        String beanClassName = "org.apache.beehive.controls.test.controls.inherit." + simpleName;
+        String beanInfo = "org/apache/beehive/controls/test/junit/inherit/" + simpleName + ".beaninfo";
+	
+	File tempFile = File.createTempFile(simpleName, ".beaninfo");
+	boolean same = ControlTestUtils.compareBeanInfo(beanInfo, tempFile, Class.forName(beanClassName));
+	
+	if(!same) 
+	    fail("Generated beaninfo file " + tempFile + " differs from expected beaninfo " + beanInfo + " in classloader");
+	else tempFile.delete();
+    }	
+    /*
 
         File tempFile = null;
         FileOutputStream fos = null;
@@ -81,33 +90,30 @@
                 fos.close();
         }
 
-        InputStream valid = null;
-        InputStream current = null;
+        InputStream expected = null;
+        InputStream actual = null;
         try {
-            valid = this.getClass().getClassLoader().getResourceAsStream(beanInfo);
+            expected = getClass().getClassLoader().getResourceAsStream(beanInfo);
 
-            if (valid == null)
-                fail("Could not locate valid beaninfo file \"" + beanInfo + "\"");
+            if (expected == null)
+                fail("Could not locate expected beaninfo file \"" + beanInfo + "\"");
 
-            current = new FileInputStream(tempFile);
-            int validVal, currentVal;
-            do {
-                validVal = valid.read();
-                currentVal = current.read();
-
-                if (validVal != currentVal)
-                    fail("BeanInfo data in " + tempFile.getName() + " differs from valid file");
-            }
-            while (validVal != -1);
+            actual = new FileInputStream(tempFile);
+	    
+	    boolean same = ControlTestUtils.compareFiles(expected, actual);
+	    
+	    if(!same) 
+		fail("File " + tempFile.getName() " differs from expected file " + beanInfo + " in classloader");
         }
         finally {
-            if(valid != null)
-                valid.close();
-            if(current != null)
-                current.close();
+            if(expected != null)
+                expected.close();
+            if(actual != null)
+                actual.close();
         }
 
         // Pass, so remove the temporary output file
         tempFile.delete();
     }
+    */
 }

Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlIntrospector.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlIntrospector.java?view=diff&rev=476666&r1=476665&r2=476666
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlIntrospector.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlIntrospector.java Sat Nov 18 16:30:02 2006
@@ -42,7 +42,9 @@
 /**
  * A utility class for introspecting Control beans
  */
-public final class ControlIntrospector {
+final class ControlIntrospector {
+
+    private static String LINE_SEPARATOR = System.getProperty("line.separator");
 
     private Class _beanClass;
     private int _indentLevel = 0;
@@ -65,7 +67,7 @@
         for (int i = 0; i < _indentLevel; i++)
             _pw.append("    ");
         _pw.printf(format, args);
-        _pw.printf("\n");
+        _pw.printf(LINE_SEPARATOR);
     }
 
     private void printElement(String name, String value) {

Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlTestUtils.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlTestUtils.java?view=diff&rev=476666&r1=476665&r2=476666
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlTestUtils.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/utils/ControlTestUtils.java Sat Nov 18 16:30:02 2006
@@ -18,13 +18,15 @@
  */
 package org.apache.beehive.controls.test.junit.utils;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.ObjectOutputStream;
+import java.io.InputStream;
 import java.io.IOException;
-import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.ObjectInputStream;
-
-import org.apache.beehive.controls.test.controls.composition.OuterControlBean;
+import java.io.ObjectOutputStream;
 
 public final class ControlTestUtils {
 
@@ -69,5 +71,62 @@
         }
 
         return object;
+    }
+
+    /**
+       Compare two bean info files.  Two InputStream instances are created given the parameters
+       and compared byte-by-byte.  Any difference between these comparisons will result in a 
+       return value of <code>false</code>.
+       
+       @param expectedBeanInfo the String path to an expected beaninfo file that must be available in classloader
+       @param tempFile the location of a temporary file into which the actual beaninfo will be generated
+       @param controlBeanClass the type of control bean to introspect
+       @return <code>false</code> if the files differ by any byte; <code>true</code> otherwise
+    */
+    public static boolean compareBeanInfo(String expectedBeanInfo, File tempFile, Class controlBeanClass) 
+	throws Exception {
+
+	assert controlBeanClass != null;
+	assert tempFile != null;
+
+        FileOutputStream fos = null;
+        try {
+            fos = new FileOutputStream(tempFile);
+            ControlIntrospector ci = new ControlIntrospector(controlBeanClass, fos);
+            ci.introspect();
+        }
+        finally {
+            if (fos != null)
+                fos.close();
+        }
+
+	boolean fail = false;
+        InputStream valid = null;
+        InputStream current = null;
+        try {
+            valid = controlBeanClass.getClassLoader().getResourceAsStream(expectedBeanInfo);
+            current = new FileInputStream(tempFile);
+
+            assert valid != null;
+	    assert current != null;
+
+            int validVal;
+            int currentVal;
+            do {
+                validVal = valid.read();
+                currentVal = current.read();
+
+		if(validVal != currentVal) 
+		    return false;
+            } while (validVal != -1);
+        }
+        finally {
+            if (current != null)
+                current.close();
+            if (valid != null)
+                valid.close();
+        }
+	
+	return true;
     }
 }