[jboss-cvs] JBossCache/tests/compat/org/jboss/cache/compat ...

Pavel Tsekov ptsekov at jboss.org
Sat Dec 23 10:36:00 EST 2006


  User: ptsekov 
  Date: 06/12/23 10:36:00

  Modified:    tests/compat/org/jboss/cache/compat  Tag:
                        Branch_JBossCache_1_4_0
                        SerialVersionUIDUnitTestCase.java
  Log:
  * SerialVersionUIDUnitTestCase.java: Add tests for compatibility with JBossCache 1.3.0.GA and 1.4.0.GA.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +109 -0    JBossCache/tests/compat/org/jboss/cache/compat/Attic/SerialVersionUIDUnitTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SerialVersionUIDUnitTestCase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/compat/org/jboss/cache/compat/Attic/SerialVersionUIDUnitTestCase.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -b -r1.1.2.1 -r1.1.2.2
  --- SerialVersionUIDUnitTestCase.java	16 Dec 2006 13:13:03 -0000	1.1.2.1
  +++ SerialVersionUIDUnitTestCase.java	23 Dec 2006 15:36:00 -0000	1.1.2.2
  @@ -6,6 +6,7 @@
    */
   package org.jboss.cache.compat;
   
  +import java.beans.XMLDecoder;
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileWriter;
  @@ -13,6 +14,7 @@
   import java.io.ObjectInputStream;
   import java.util.Iterator;
   import java.util.Map;
  +import java.util.TreeMap;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
  @@ -30,11 +32,116 @@
    */
   public class SerialVersionUIDUnitTestCase extends TestCase
   {
  +   private static final String DB_DIR = "etc/svuid-db";
  +   private static final String DB_FILE_PREFIX = "svuid-";
  +   private static final String VERSION_STRING_1_3_0_GA = "1.3.0.GA";
  +   private static final String VERSION_STRING_1_4_0_GA = "1.4.0.GA";
  +   private static final String JAVA_VERSION_PREFIX_14 = "14";
  +   private static final String JAVA_VERSION_PREFIX_50 = "50";
  +
  +   int mismatchCount = 0;
  +
  +   StringBuffer messages = null;
  +
      public SerialVersionUIDUnitTestCase(String name)
      {
         super(name);
      }
   
  +   protected void setUp()
  +   {
  +      mismatchCount = 0;
  +
  +      if (messages == null)
  +      {
  +         messages = new StringBuffer();
  +      }
  +   }
  +
  +   protected void tearDown()
  +   {
  +      messages.setLength(0);
  +   }
  +
  +   public void testCompat_1_3_0_GA() throws Exception
  +   {
  +      String prefix = getFilePrefix() + VERSION_STRING_1_3_0_GA;
  +      Map db = readDatabase(prefix);
  +      mismatchCount = compare(db, calcClassInfoMap(), prefix,
  +			      new String[0], messages);
  +
  +      System.out.println("serialVersionUID mismatches = " + mismatchCount);
  +      if (mismatchCount != 0)
  +      {
  +         fail("Failures for :" + messages.toString());
  +      }
  +   }
  +
  +   public void testCompat_1_4_0_GA() throws Exception
  +   {
  +      String prefix = getFilePrefix() + VERSION_STRING_1_4_0_GA;
  +      Map db = readDatabase(prefix);
  +      mismatchCount = compare(db, calcClassInfoMap(), prefix,
  +			      new String[0], messages);
  +
  +      System.out.println("serialVersionUID mismatches = " + mismatchCount);
  +      if (mismatchCount != 0)
  +      {
  +         fail("Failures for :" + messages.toString());
  +      }
  +   }
  +
  +   private String getFilePrefix()
  +   {
  +      String javaVersion = System.getProperty("java.version").trim();
  +      if (javaVersion.startsWith("1.5."))
  +      {
  +         return DB_FILE_PREFIX + JAVA_VERSION_PREFIX_50 + ".";
  +      }
  +      else if (javaVersion.startsWith("1.4."))
  +      {
  +         return DB_FILE_PREFIX + JAVA_VERSION_PREFIX_14 + ".";
  +      }
  +      else
  +      {
  +         return "";
  +      }
  +   }
  +
  +   private Map readDatabase(String dbFilePrefix)
  +      throws Exception
  +   {
  +      File dbFile = new File(DB_DIR, dbFilePrefix + ".xml");
  +      FileInputStream inputStream = new FileInputStream(dbFile);
  +      XMLDecoder xmlObjects = new XMLDecoder(inputStream);
  +      ClassVersionInfo svuidInfo;
  +      TreeMap db = new TreeMap();
  +      boolean doQuit = false;
  +
  +      do
  +      {
  +         try
  +         {
  +            svuidInfo = (ClassVersionInfo) xmlObjects.readObject();
  +            db.put(svuidInfo.getName(), svuidInfo);
  +         }
  +         /*
  +          * TODO: Keep working ?
  +         catch (ClassCastException e)
  +         {
  +            ;
  +         }
  +         */
  +         catch (ArrayIndexOutOfBoundsException e)
  +         {
  +            // No more data
  +            doQuit = true;
  +         }
  +      } while (doQuit == false);
  +
  +      return db;
  +   }
  +
      /**
       Compare two sets of classes for serialVersionUID compatibility.
   
  @@ -109,6 +216,8 @@
      public static Test suite() throws Exception
      {
         TestSuite suite = new TestSuite();
  +      suite.addTest(new SerialVersionUIDUnitTestCase("testCompat_1_4_0_GA"));
  +      suite.addTest(new SerialVersionUIDUnitTestCase("testCompat_1_3_0_GA"));
   
         return suite;
      }
  
  
  



More information about the jboss-cvs-commits mailing list