1 22 package org.jboss.test.compatibility.test; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.IOException ; 27 import java.io.ObjectInputStream ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import junit.framework.Test; 32 import junit.framework.TestCase; 33 import junit.framework.TestSuite; 34 35 import org.jboss.tools.ClassVersionInfo; 36 import org.jboss.tools.SerialVersionUID; 37 38 39 45 public class SerialVersionUIDUnitTestCase extends TestCase 46 { 47 static Map currentClassInfoMap; 48 49 public SerialVersionUIDUnitTestCase(String name) 50 { 51 super(name); 52 } 53 54 57 public void test401Compatibility() 58 throws Exception 59 { 60 String [] badPackages = { 62 "org.apache", 64 "org.jacorb", 66 "org.omg", 67 70 "org.jboss.aop", 71 74 "org.jboss.webservice", 75 78 "org.hsqldb", 79 81 "org.jboss.ejb.plugins.cmp.ejbql.TokenMgrError", 82 "org.jboss.mq.selectors.TokenMgrError", 83 "org.jboss.security.auth.login.TokenMgrError" 84 }; 85 86 System.out.println("+++ test401Compatibility"); 87 String etc = System.getProperty("jbosstest.src.etc", "../src/etc"); 89 File serFile = new File (etc, "serialVersionUID/401.ser"); 90 FileInputStream fis = new FileInputStream (serFile); 91 ObjectInputStream ois = new ObjectInputStream (fis); 92 Map classInfoMap = (Map ) ois.readObject(); 93 System.out.println("4.0.1 serial classes count: "+classInfoMap.size()); 94 95 System.setProperty("org.jboss.j2ee.LegacySerialization", "true"); 96 Map currentClassInfoMap = calcClassInfoMap(); 97 int mismatchCount = compare(classInfoMap, currentClassInfoMap, "401", badPackages); 98 currentClassInfoMap.clear(); 99 System.out.println("serialVersionUID mismatches = "+mismatchCount); 100 assertTrue("There are no serialVersionUID mismatches("+mismatchCount+")", 101 mismatchCount == 0); 102 } 103 104 107 public void testJ2EERI141Compatibility() 108 throws Exception 109 { 110 String [] badPackages = { 112 "javax.mail" 114 }; 115 System.out.println("+++ testJ2EERI141Compatibility"); 116 System.getProperties().remove("org.jboss.j2ee.LegacySerialization"); 117 String etc = System.getProperty("jbosstest.src.etc", "../src/etc"); 118 File serFile = new File (etc, "serialVersionUID/j2ee141.ser"); 119 FileInputStream fis = new FileInputStream (serFile); 120 ObjectInputStream ois = new ObjectInputStream (fis); 121 Map classInfoMap = (Map ) ois.readObject(); 122 System.out.println("J2EE RI serial classes count: "+classInfoMap.size()); 123 124 Map currentClassInfoMap = calcClassInfoMap(); 125 int mismatchCount = compare(classInfoMap, currentClassInfoMap, "J2EE1.4", badPackages); 126 currentClassInfoMap.clear(); 127 System.out.println("serialVersionUID mismatches = "+mismatchCount); 128 assertTrue("There are no serialVersionUID mismatches("+mismatchCount+")", 129 mismatchCount == 0); 130 } 131 132 private int compare(Map classInfoMap, Map currentClassInfoMap, 133 String versionName, String [] badPackages) 134 { 135 int mismatchCount = 0; 136 Iterator iter = currentClassInfoMap.values().iterator(); 137 while( iter.hasNext() ) 138 { 139 ClassVersionInfo cvi = (ClassVersionInfo) iter.next(); 140 String name = cvi.getName(); 141 ClassVersionInfo cvi401 = (ClassVersionInfo) classInfoMap.get(name); 142 if( cvi401 != null && cvi.getSerialVersion() != cvi401.getSerialVersion() ) 143 { 144 String msg = "serialVersionUID error for "+name 145 +", " + versionName + " " + cvi401.getSerialVersion() 146 +", current: "+cvi.getSerialVersion(); 147 boolean isInBadPkg = false; 149 for(int n = 0; n < badPackages.length; n ++) 150 { 151 String pkg = badPackages[n]; 152 if( name.startsWith(pkg) ) 153 { 154 isInBadPkg = true; 155 break; 156 } 157 } 158 if( isInBadPkg == false ) 159 { 160 mismatchCount ++; 161 System.err.println(msg); 162 } 163 else 164 { 165 System.out.println(msg); 166 } 167 } 168 } 169 return mismatchCount; 170 } 171 172 static Map calcClassInfoMap() 173 throws IOException 174 { 175 String jbossDist = System.getProperty("jbosstest.dist"); 176 File jbossHome = new File (jbossDist); 177 jbossHome = jbossHome.getCanonicalFile(); 178 System.out.println("Calculating serialVersionUIDs for jbossHome: "+jbossHome); 179 Map classInfoMap = SerialVersionUID.generateJBossSerialVersionUIDReport( 180 jbossHome); 181 return classInfoMap; 182 } 183 184 public static Test suite() throws Exception 185 { 186 TestSuite suite = new TestSuite(); 189 suite.addTest(new SerialVersionUIDUnitTestCase("test401Compatibility")); 190 suite.addTest(new SerialVersionUIDUnitTestCase("testJ2EERI141Compatibility")); 191 192 return suite; 193 } 194 195 public static void main(String [] args) 196 { 197 junit.textui.TestRunner.run(SerialVersionUIDUnitTestCase.class); 198 } 199 } 200 | Popular Tags |