1 package org.jbpm; 2 3 import java.io.File ; 4 import java.io.Serializable ; 5 import java.lang.reflect.Modifier ; 6 import java.util.Arrays ; 7 import java.util.HashSet ; 8 import java.util.Set ; 9 10 import junit.framework.TestCase; 11 12 import org.jbpm.file.def.FileDefinitionFileSystemConfigTest; 13 import org.jbpm.instantiation.ClassLoaderUtil; 14 15 public class SerializabilityTest extends TestCase { 16 17 String testRootDir = FileDefinitionFileSystemConfigTest.class.getProtectionDomain().getCodeSource().getLocation().getFile().toString(); 18 19 static Set excusedClasses = new HashSet (Arrays.asList(new String [] { 20 "org.jbpm.ant.DeployParTask", 21 "org.jbpm.ant.JbpmSchemaTask", 22 "org.jbpm.ant.Launcher", 23 "org.jbpm.ant.StartHsqldbTask", 24 "org.jbpm.ant.StartJBossTask", 25 "org.jbpm.context.exe.JbpmType", 26 "org.jbpm.db.hibernate.ConverterEnumType", 27 "org.jbpm.db.hibernate.Converters", 28 "org.jbpm.db.hibernate.JbpmNamingStrategy", 29 "org.jbpm.db.jmx.JbpmService", 30 "org.jbpm.db.ContextSession", 31 "org.jbpm.db.FileSession", 32 "org.jbpm.db.GraphSession", 33 "org.jbpm.db.JbpmSession", 34 "org.jbpm.db.LoggingSession", 35 "org.jbpm.db.SchedulerSession", 36 "org.jbpm.db.TaskMgmtSession", 37 "org.jbpm.graph.exe.ExecutionContext", 38 "org.jbpm.instantiation.BeanInstantiator", 39 "org.jbpm.instantiation.ClassLoaderUtil", 40 "org.jbpm.instantiation.ConfigurationPropertyInstantiator", 41 "org.jbpm.instantiation.ConstructorInstantiator", 42 "org.jbpm.instantiation.DefaultInstantiator", 43 "org.jbpm.instantiation.FieldInstantiator", 44 "org.jbpm.instantiation.ProcessClassLoader", 45 "org.jbpm.instantiation.XmlInstantiator", 46 "org.jbpm.JbpmConfiguration", 47 "org.jbpm.jmx.JbpmService", 48 "org.jbpm.jpdl.convert.Converter", 49 "org.jbpm.jpdl.convert.Converter$1", 50 "org.jbpm.graph.action.ActionTypes", 51 "org.jbpm.graph.node.Fork$ForkedToken", 52 "org.jbpm.graph.node.InterleaveStart$DefaultInterleaver", 53 "org.jbpm.graph.node.NodeTypes", 54 "org.jbpm.graph.node.ProcessFactory", 55 "org.jbpm.jpdl.par.FileArchiveParser", 56 "org.jbpm.jpdl.par.JpdlArchiveParser", 57 "org.jbpm.jpdl.par.ProcessArchive", 58 "org.jbpm.jpdl.par.ProcessArchiveDeployer", 59 "org.jbpm.jpdl.par.ProcessArchiveDeployerTask", 60 "org.jbpm.jpdl.xml.JpdlXmlReader", 61 "org.jbpm.jpdl.xml.JpdlXmlWriter", 62 "org.jbpm.jpdl.xml.SchemaValidationHelper$Handler", 63 "org.jbpm.jpdl.xml.SchemaValidationHelper$Resolver", 64 "org.jbpm.jpdl.xml.SchemaValidationHelper", 65 "org.jbpm.scheduler.exe.SchedulerInstance$CancelledTimer", 66 "org.jbpm.scheduler.impl.Scheduler", 67 "org.jbpm.scheduler.impl.Scheduler$HistoryListener", 68 "org.jbpm.scheduler.impl.SchedulerMain$1", 69 "org.jbpm.scheduler.impl.SchedulerMain$LogListener", 70 "org.jbpm.scheduler.impl.SchedulerMain", 71 "org.jbpm.scheduler.impl.SchedulerThread", 72 "org.jbpm.security.authenticator.JBossAuthenticator", 73 "org.jbpm.security.authenticator.JbpmDefaultAuthenticator", 74 "org.jbpm.security.authenticator.SubjectAuthenticator", 75 "org.jbpm.security.Authorization", 76 "org.jbpm.security.authorizer.AccessControllerAuthorizer", 77 "org.jbpm.security.authorizer.JbpmIdentityAuthorizer", 78 "org.jbpm.security.authorizer.RolesAuthorizer", 79 "org.jbpm.security.filter.JbpmAuthenticationFilter" 80 })); 81 82 public void testForNonSerializableClasses() { 83 File jbpmRoot = new File (testRootDir+"../classes.jbpm/"); 84 scanForClasses(jbpmRoot, ""); 85 } 86 87 private void scanForClasses(File rootClassDir, String packageDir) { 88 File packageDirFile = new File (rootClassDir.getPath()+"/"+packageDir); 89 File [] files = packageDirFile.listFiles(); 90 for (int i=0; i<files.length; i++) { 91 if (files[i].isDirectory()) { 92 String newPackageDir = ( "".equals(packageDir) ? files[i].getName() : packageDir+"/"+files[i].getName() ); 93 scanForClasses(rootClassDir, newPackageDir); 95 96 } else if ( (files[i].isFile()) 97 && (files[i].getName().endsWith(".class")) 98 ) { 99 String classFilePath = packageDir+"/"+files[i].getName(); 101 String className = classFilePath.replace('/', '.'); 102 className = className.substring(0, className.length()-6); 103 assertSerializabilityOfClass(className); 104 } 105 } 106 } 107 108 private void assertSerializabilityOfClass(String className) { 109 Class clazz = ClassLoaderUtil.loadClass(className); 110 111 if ( ! ( (Serializable .class.isAssignableFrom(clazz)) 112 || (Modifier.isAbstract(clazz.getModifiers())) 113 || (excusedClasses.contains(clazz.getName())) 114 ) 115 ) { 116 fail(className+" is NOT Serializable"); 117 } 118 } 119 120 } 122 | Popular Tags |